List of usage examples for org.apache.commons.httpclient.util ParameterFormatter format
public String format(NameValuePair paramNameValuePair)
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("?"); }//from ww w . j a v a2 s . 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(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("?"); }// w w w . j a v a 2s .com 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); }