Example usage for org.apache.commons.httpclient.util ParameterFormatter setAlwaysUseQuotes

List of usage examples for org.apache.commons.httpclient.util ParameterFormatter setAlwaysUseQuotes

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util ParameterFormatter setAlwaysUseQuotes.

Prototype

public void setAlwaysUseQuotes(boolean paramBoolean) 

Source Link

Usage

From source file:org.archive.wayback.resourcestore.http.FileLocationDBClient.java

private String doGetMethod(NameValuePair[] data) throws IOException {
    ParameterFormatter formatter = new ParameterFormatter();
    formatter.setAlwaysUseQuotes(false);
    StringBuilder finalUrl = new StringBuilder(serverUrl);
    if (data.length > 0) {
        finalUrl.append("?");
    }//w  w  w.  j  av a2s .c  om
    for (int i = 0; i < data.length; i++) {
        if (i == 0) {
            finalUrl.append("?");
        } else {
            finalUrl.append("&");
        }
        finalUrl.append(formatter.format(data[i]));
    }

    GetMethod method = new GetMethod(finalUrl.toString());

    int statusCode = client.executeMethod(method);
    if (statusCode != HttpStatus.SC_OK) {
        throw new IOException("Method failed: " + method.getStatusLine());
    }
    String responseString = method.getResponseBodyAsString();
    if (!responseString.startsWith(OK_RESPONSE_PREFIX)) {
        if (responseString.startsWith(FileLocationDBServlet.NO_LOCATION_PREFIX)) {
            return null;
        }
        throw new IOException(responseString);
    }
    return responseString.substring(OK_RESPONSE_PREFIX.length() + 1);
}

From source file:org.archive.wayback.resourcestore.locationdb.RemoteResourceFileLocationDB.java

private String doGetMethod(NameValuePair[] data) throws IOException {
    ParameterFormatter formatter = new ParameterFormatter();
    formatter.setAlwaysUseQuotes(false);
    StringBuilder finalUrl = new StringBuilder(serverUrl);
    if (data.length > 0) {
        finalUrl.append("?");
    }/*from w w  w .j a  va2s.c  o m*/
    for (int i = 0; i < data.length; i++) {
        if (i == 0) {
            finalUrl.append("?");
        } else {
            finalUrl.append("&");
        }
        finalUrl.append(formatter.format(data[i]));
    }

    GetMethod method = new GetMethod(finalUrl.toString());

    int statusCode = client.executeMethod(method);
    if (statusCode != HttpStatus.SC_OK) {
        throw new IOException("Method failed: " + method.getStatusLine());
    }
    String responseString = method.getResponseBodyAsString();
    if (!responseString.startsWith(OK_RESPONSE_PREFIX)) {
        if (responseString.startsWith(ResourceFileLocationDBServlet.NO_LOCATION_PREFIX)) {
            return null;
        }
        throw new IOException(responseString);
    }
    return responseString.substring(OK_RESPONSE_PREFIX.length() + 1);
}