List of usage examples for org.apache.http.client.methods HttpRequestBase getParams
@Deprecated
public HttpParams getParams()
From source file:org.apache.marmotta.platform.core.util.http.HttpRequestUtil.java
/** * Configure whether redirects for this request should be handled automatically. * //from w w w . ja va 2 s . c o m * @param request the request to modify * @param followRedirect <code>true</code> if redirects (HTTP response code 3xx) should be * handled automatically. */ public static void setFollowRedirect(HttpRequestBase request, boolean followRedirect) { request.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, followRedirect); }
From source file:org.apache.marmotta.platform.core.util.http.HttpRequestUtil.java
/** * Set the <i>local part</i> of the User-Agent Header String. It will be suffixed with the * global part of the User-Agent, which is handled by the corresponding * {@link HttpClientService} implementation. * /*from w w w . j a v a 2s . co m*/ * @param request the request to modify * @param userAgentString the prefix of the User-Agent string which will be suffixed with a * LMF-global part handled b< the {@link HttpClientService} implementation. */ public static void setUserAgentString(HttpRequestBase request, String userAgentString) { request.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgentString); }
From source file:net.paissad.minus.utils.HttpClientUtils.java
/** * Adds/appends the content of the map to the current parameters of the * specified {@link HttpRequestBase}.//w ww.ja v a 2 s .co m * * @param request - The request for which we want to add new parameters. * @param parametersBody - The parameters to add. */ private static HttpRequestBase appendParametersToRequest(HttpRequestBase request, final Map<String, String> parametersBody) { Iterator<Entry<String, String>> iter = parametersBody.entrySet().iterator(); while (iter.hasNext()) { Entry<String, String> o = iter.next(); request.getParams().setParameter(o.getKey(), o.getValue()); } return request; }
From source file:com.griddynamics.jagger.invoker.http.ApacheHttpInvoker.java
@Override protected HttpParams getHttpClientParams(HttpRequestBase query) { return query.getParams(); }
From source file:com.alu.e3.gateway.loadbalancer.HttpLoadBalancerProducer.java
protected HttpRequestBase createMethod(Exchange exchange) throws URISyntaxException, CamelExchangeException { HttpRequestBase httpRequest = super.createMethod(exchange); HttpParams params = httpRequest.getParams(); Integer connectionTimeout = exchange.getProperty(ExchangeConstantKeys.E3_HTTP_CONNECTION_TIMEOUT.toString(), E3Constant.DEFAULT_HTTP_CONNECTION_TIMETOUT, Integer.class); Integer socketTimeout = exchange.getProperty(ExchangeConstantKeys.E3_HTTP_SOCKET_TIMEOUT.toString(), E3Constant.DEFAULT_HTTP_SOCKET_TIMEOUT, Integer.class); HttpConnectionParamBean httpConnectionParamBean = new HttpConnectionParamBean(params); httpConnectionParamBean.setConnectionTimeout(connectionTimeout); httpConnectionParamBean.setSoTimeout(socketTimeout); exchange.getIn().setHeader(HttpHeaders.HOST, httpRequest.getURI().getHost()); return httpRequest; }
From source file:org.apache.camel.component.http4.HttpPollingConsumer.java
protected Exchange doReceive(int timeout) { Exchange exchange = endpoint.createExchange(); HttpRequestBase method = createMethod(exchange); // set optional timeout in millis if (timeout > 0) { HttpConnectionParams.setSoTimeout(method.getParams(), timeout); }/*from w ww.j a va2 s .c o m*/ HttpEntity responeEntity = null; try { // execute request HttpResponse response = httpClient.execute(method); int responseCode = response.getStatusLine().getStatusCode(); responeEntity = response.getEntity(); Object body = HttpHelper.readResponseBodyFromInputStream(responeEntity.getContent(), exchange); // lets store the result in the output message. Message message = exchange.getOut(); message.setBody(body); // lets set the headers Header[] headers = response.getAllHeaders(); HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy(); for (Header header : headers) { String name = header.getName(); // mapping the content-type if (name.toLowerCase().equals("content-type")) { name = Exchange.CONTENT_TYPE; } String value = header.getValue(); if (strategy != null && !strategy.applyFilterToExternalHeaders(name, value, exchange)) { message.setHeader(name, value); } } message.setHeader(Exchange.HTTP_RESPONSE_CODE, responseCode); return exchange; } catch (IOException e) { throw new RuntimeCamelException(e); } finally { if (responeEntity != null) { try { EntityUtils.consume(responeEntity); } catch (IOException e) { // nothing what we can do } } } }
From source file:com.vmware.vfabric.hyperic.plugin.vfws.BmxQuery.java
private void doQuery() { HttpClient client = new DefaultHttpClient(); HttpRequestBase method; try {/*from ww w .ja va2 s . co m*/ _log.debug("Getting URL " + getURL().toURI().toString()); method = new HttpGet(getURL().toURI()); } catch (URISyntaxException e) { _log.debug(e, e); return; } method.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, true); // follow // redirects try { HttpResponse response = client.execute(method); _result = new BmxResult(response); _log.debug("Got " + response.getStatusLine().getStatusCode() + " from " + getURL().toString()); } catch (IOException e) { _log.debug(e, e); } }
From source file:com.apptentive.android.sdk.comm.ApptentiveClient.java
private static ApptentiveHttpResponse performHttpRequest(String oauthToken, String uri, Method method, String body) {/* w ww. ja va2s. c om*/ Log.d("Performing request to %s", uri); //Log.e("OAUTH Token: %s", oauthToken); ApptentiveHttpResponse ret = new ApptentiveHttpResponse(); HttpClient httpClient = null; try { HttpRequestBase request; httpClient = new DefaultHttpClient(); switch (method) { case GET: request = new HttpGet(uri); break; case PUT: request = new HttpPut(uri); request.setHeader("Content-Type", "application/json"); Log.d("PUT body: " + body); ((HttpPut) request).setEntity(new StringEntity(body, "UTF-8")); break; case POST: request = new HttpPost(uri); request.setHeader("Content-Type", "application/json"); Log.d("POST body: " + body); ((HttpPost) request).setEntity(new StringEntity(body, "UTF-8")); break; default: Log.e("Unrecognized method: " + method.name()); return ret; } HttpParams httpParams = request.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, DEFAULT_HTTP_CONNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_HTTP_SOCKET_TIMEOUT); httpParams.setParameter("http.useragent", getUserAgentString()); request.setHeader("Authorization", "OAuth " + oauthToken); request.setHeader("Accept-Encoding", "gzip"); request.setHeader("Accept", "application/json"); request.setHeader("X-API-Version", API_VERSION); HttpResponse response = httpClient.execute(request); int code = response.getStatusLine().getStatusCode(); ret.setCode(code); ret.setReason(response.getStatusLine().getReasonPhrase()); Log.d("Response Status Line: " + response.getStatusLine().toString()); HeaderIterator headerIterator = response.headerIterator(); if (headerIterator != null) { Map<String, String> headers = new HashMap<String, String>(); while (headerIterator.hasNext()) { Header header = (Header) headerIterator.next(); headers.put(header.getName(), header.getValue()); //Log.v("Header: %s = %s", header.getName(), header.getValue()); } ret.setHeaders(headers); } HttpEntity entity = response.getEntity(); if (entity != null) { InputStream is = entity.getContent(); if (is != null) { String contentEncoding = ret.getHeaders().get("Content-Encoding"); if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) { is = new GZIPInputStream(is); } ret.setContent(Util.readStringFromInputStream(is, "UTF-8")); if (code >= 200 && code < 300) { Log.d("Response: " + ret.getContent()); } else { Log.w("Response: " + ret.getContent()); } } } } catch (IllegalArgumentException e) { Log.w("Error communicating with server.", e); } catch (SocketTimeoutException e) { Log.w("Timeout communicating with server."); } catch (IOException e) { Log.w("Error communicating with server.", e); } finally { if (httpClient != null) { httpClient.getConnectionManager().shutdown(); } } return ret; }
From source file:com.dhenton9000.filedownloader.FileDownloader.java
private HttpResponse getHTTPResponse() throws IOException, NullPointerException { if (fileURI == null) throw new NullPointerException("No file URI specified"); HttpClient client = new DefaultHttpClient(); BasicHttpContext localContext = new BasicHttpContext(); //Clear down the local cookie store every time to make sure we don't have any left over cookies influencing the test localContext.setAttribute(ClientContext.COOKIE_STORE, null); LOG.info("Mimic WebDriver cookie state: " + mimicWebDriverCookieState); if (mimicWebDriverCookieState) { localContext.setAttribute(ClientContext.COOKIE_STORE, mimicCookieState(driver.manage().getCookies())); }//from ww w.j a v a 2 s .co m HttpRequestBase requestMethod = httpRequestMethod.getRequestMethod(); requestMethod.setURI(fileURI); HttpParams httpRequestParameters = requestMethod.getParams(); httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, followRedirects); requestMethod.setParams(httpRequestParameters); //TODO if post send map of variables, also need to add a post map setter LOG.info("Sending " + httpRequestMethod.toString() + " request for: " + fileURI); return client.execute(requestMethod, localContext); }
From source file:com.ibm.watson.developer_cloud.natural_language_classifier.v1.NaturalLanguageClassifier.java
/** * Returns classification information for a classifier on a phrase. * /*from w w w .ja v a2 s . c o m*/ * @param classifierId * The classifier id * @param text * The submitted phrase to classify * @return the classification of a phrase with a given classifier * @throws UnsupportedEncodingException */ public Classification classify(final String classifierId, final String text) throws UnsupportedEncodingException { if (classifierId == null || classifierId.isEmpty()) throw new IllegalArgumentException("classifierId can not be null or empty"); if (text == null || text.isEmpty()) throw new IllegalArgumentException("text can not be null or empty"); JsonObject contentJson = new JsonObject(); contentJson.addProperty("text", text); String path = String.format("/v1/classifiers/%s/classify", classifierId); System.out.println("PATH::::::::::" + path); //Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.100.1.124", 3128)); HttpHost proxy = new HttpHost("10.100.1.124", 3128); HttpRequestBase request = Request.Post(path).withContent(contentJson).build(); ConnRouteParams.setDefaultProxy(request.getParams(), proxy); try { HttpResponse response = execute(request); Classification classification = ResponseUtil.getObject(response, Classification.class); for (ClassifiedClass klass : classification.getClasses()) { if (klass.getName().equals(classification.getTopClass())) { classification.setTopConfidence(klass.getConfidence()); break; } } return classification; } catch (IOException e) { throw new RuntimeException(e); } }