List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString
public void setQueryString(String queryString)
From source file:demo.jaxrs.search.client.Client.java
private static void search(final String url, final HttpClient httpClient, final String expression) throws IOException, HttpException { System.out.println("Sent HTTP GET request to search the books in catalog: " + expression); final GetMethod get = new GetMethod(url + "/search"); get.setQueryString("$filter=" + expression); try {//from ww w . j av a2s.c o m int status = httpClient.executeMethod(get); if (status == 200) { System.out.println(get.getResponseBodyAsString()); } } finally { get.releaseConnection(); } }
From source file:codeOrchestra.lcs.license.plimus.PlimusHelper.java
private static PlimusResponse executePlimusAction(String key, PlimusValidationAction action) throws IOException { GetMethod getMethod = new GetMethod(VALIDATION_URL); getMethod.getParams().setParameter("http.socket.timeout", new Integer(TIMEOUT)); getMethod.setQueryString(new NameValuePair[] { new NameValuePair("action", action.name()), new NameValuePair("productId", PRODUCT_ID), new NameValuePair("key", key) }); httpClient.executeMethod(getMethod); return new PlimusResponse(getMethod.getResponseBodyAsString()); }
From source file:com.zimbra.cs.util.yauth.RawAuth.java
private static Response doGet(String action, NameValuePair... params) throws AuthenticationException, IOException { String uri = LC.yauth_baseuri.value() + '/' + action; GetMethod method = new GetMethod(uri); method.setQueryString(params); int rc = HttpClientUtil.executeMethod(method); Response res = new Response(method); String error = res.getField(ERROR); // Request can sometimes fail even with a 200 status code, so always // check for "Error" attribute in response. if (rc == 200 && error == null) { return res; }/*from w w w . j av a 2 s . com*/ if (rc == 999) { // Yahoo service temporarily unavailable (error code text not included) throw new AuthenticationException(ErrorCode.TEMP_ERROR, "Unable to process request at this time"); } ErrorCode code = error != null ? ErrorCode.get(error) : ErrorCode.GENERIC_ERROR; String description = res.getField(ERROR_DESCRIPTION); if (description == null) { description = code.getDescription(); } AuthenticationException e = new AuthenticationException(code, description); e.setCaptchaUrl(res.getField(CAPTCHA_URL)); e.setCaptchaData(res.getField(CAPTCHA_DATA)); throw e; }
From source file:com.carrotsearch.util.httpclient.HttpUtils.java
/** * Opens a HTTP/1.1 connection to the given URL using the GET method, decompresses * compressed response streams, if supported by the server. * // w ww.jav a2 s . co m * @param url The URL to open. The URL must be properly escaped, this method will * <b>not</b> perform any escaping. * @param params Query string parameters to be attached to the url. * @param headers Any extra HTTP headers to add to the request. * @return The {@link HttpUtils.Response} object. Note that entire payload is read and * buffered so that the HTTP connection can be closed when leaving this * method. */ public static Response doGET(String url, Collection<NameValuePair> params, Collection<Header> headers) throws HttpException, IOException { final HttpClient client = HttpClientFactory.getTimeoutingClient(); client.getParams().setVersion(HttpVersion.HTTP_1_1); final GetMethod request = new GetMethod(); final Response response = new Response(); try { request.setURI(new URI(url, true)); if (params != null) { request.setQueryString(params.toArray(new NameValuePair[params.size()])); } request.setRequestHeader(HttpHeaders.URL_ENCODED); request.setRequestHeader(HttpHeaders.GZIP_ENCODING); if (headers != null) { for (Header header : headers) request.setRequestHeader(header); } Logger.getLogger(HttpUtils.class).debug("GET: " + request.getURI()); final int statusCode = client.executeMethod(request); response.status = statusCode; InputStream stream = request.getResponseBodyAsStream(); final Header encoded = request.getResponseHeader("Content-Encoding"); if (encoded != null && "gzip".equalsIgnoreCase(encoded.getValue())) { stream = new GZIPInputStream(stream); response.compression = COMPRESSION_GZIP; } else { response.compression = COMPRESSION_NONE; } final Header[] respHeaders = request.getResponseHeaders(); response.headers = new String[respHeaders.length][]; for (int i = 0; i < respHeaders.length; i++) { response.headers[i] = new String[] { respHeaders[i].getName(), respHeaders[i].getValue() }; } response.payload = StreamUtils.readFullyAndClose(stream); return response; } finally { request.releaseConnection(); } }
From source file:kevin.gvmsgarch.App.java
static String getInboxPage(String authToken, Worker.ListLocation location, int page) throws IOException { HttpClient client = new HttpClient(); String retval = null;/* ww w. jav a2s. c om*/ GetMethod m = new GetMethod(location.getUri()); if (page > 1) { m.setQueryString(new NameValuePair[] { new NameValuePair("page", "p" + page) }); } m.setRequestHeader("Authorization", "GoogleLogin auth=" + authToken); int rcode; rcode = client.executeMethod(m); if (rcode != 200) { throw new RuntimeException("Received rcode: " + rcode); } retval = makeStringFromStream(m.getResponseBodyAsStream()); return retval; }
From source file:mesquite.tol.lib.BaseHttpRequestMaker.java
public static boolean sendInfoToServer(NameValuePair[] pairs, String URI, StringBuffer response) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(URI); method.setQueryString(pairs); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); return executeMethod(client, method, response); }
From source file:edu.uci.ics.asterix.test.aql.TestsUtils.java
public static InputStream executeQuery(String str, OutputFormat fmt) throws Exception { final String url = "http://localhost:19002/query"; // Create a method instance. GetMethod method = new GetMethod(url); method.setQueryString(new NameValuePair[] { new NameValuePair("query", str) }); method.setRequestHeader("Accept", fmt.mimeType()); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); executeHttpMethod(method);// w w w. j a v a 2 s . com return method.getResponseBodyAsStream(); }
From source file:edu.uci.ics.asterix.test.aql.TestsUtils.java
private static InputStream getHandleResult(String handle, OutputFormat fmt) throws Exception { final String url = "http://localhost:19002/query/result"; // Create a method instance. GetMethod method = new GetMethod(url); method.setQueryString(new NameValuePair[] { new NameValuePair("handle", handle) }); method.setRequestHeader("Accept", fmt.mimeType()); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); executeHttpMethod(method);/*from w w w . j a va 2 s .c o m*/ return method.getResponseBodyAsStream(); }
From source file:com.feilong.tools.net.httpclient3.HttpClientUtil.java
/** * uri and params.// ww w .ja va 2 s . c o m * * @param httpClientConfig * the uri and params * @return the http method * @since 1.0.9 */ private static HttpMethod setUriAndParams(HttpClientConfig httpClientConfig) { String uri = httpClientConfig.getUri(); Map<String, String> params = httpClientConfig.getParams(); NameValuePair[] nameValuePairs = null; if (Validator.isNotNullOrEmpty(params)) { nameValuePairs = NameValuePairUtil.fromMap(params); } HttpMethodType httpMethodType = httpClientConfig.getHttpMethodType(); switch (httpMethodType) { case GET: // get GetMethod getMethod = new GetMethod(uri); //TODO ?? uri?? nameValuePairs if (Validator.isNotNullOrEmpty(nameValuePairs) && uri.indexOf("?") != -1) { throw new NotImplementedException("not implemented!"); } if (Validator.isNotNullOrEmpty(nameValuePairs)) { getMethod.setQueryString(nameValuePairs); } return getMethod; case POST: // post PostMethod postMethod = new PostMethod(uri); if (Validator.isNotNullOrEmpty(nameValuePairs)) { postMethod.setRequestBody(nameValuePairs); } return postMethod; default: throw new UnsupportedOperationException("httpMethod:[" + httpMethodType + "] not support!"); } }
From source file:mesquite.tol.lib.BaseHttpRequestMaker.java
public static boolean contactServer(String s, String URI, StringBuffer response) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(URI); NameValuePair[] pairs = new NameValuePair[1]; pairs[0] = new NameValuePair("build", StringEscapeUtils.escapeHtml("\t" + s + "\tOS =\t" + System.getProperty("os.name") + "\t" + System.getProperty("os.version") + "\tjava =\t" + System.getProperty("java.version") + "\t" + System.getProperty("java.vendor"))); method.setQueryString(pairs); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); return executeMethod(client, method, response); }