List of usage examples for org.apache.http.params HttpParams setParameter
HttpParams setParameter(String str, Object obj);
From source file:de.hackerspacebremen.communication.HackerspaceComm.java
protected final JSONObject doInBackground(final JSONObject... data) { final String userAgent = "HackerSpaceBremen/" + this.appVersionName + "; Android/" + Build.VERSION.RELEASE + "; " + Build.MANUFACTURER + "; " + Build.DEVICE + "; " + Build.MODEL; HttpClient httpclient = new DefaultHttpClient(); HttpParams httpBodyParams = httpclient.getParams(); httpBodyParams.setParameter(CoreProtocolPNames.USER_AGENT, userAgent); String response = null;//from w w w. jav a 2 s . com int responseCode = 0; String httpOrS = HTTPS; if (httpReq) { httpOrS = HTTP; } if (getReq) { try { final HttpURLConnection connection = client .open(new URL(httpOrS + SERVERURL + this.servletUrl + "?" + getParams)); InputStream in = null; try { // Read the response. in = connection.getInputStream(); final byte[] resp = readFully(in); response = new String(resp, Constants.UTF8); responseCode = connection.getResponseCode(); } finally { if (in != null) in.close(); } // HttpGet httpget = new HttpGet(httpOrS + SERVERURL // + this.servletUrl + "?" + getParams); // response = httpclient.execute(httpget); } catch (IOException e) { errorcode = -1; cancel(false); return null; } } else { try { HttpURLConnection connection = client.open(new URL(httpOrS + SERVERURL + this.servletUrl)); OutputStream out = null; InputStream in = null; try { // Write the request. connection.setRequestMethod("POST"); out = connection.getOutputStream(); out.write(createBody().getBytes(Constants.UTF8)); out.close(); responseCode = connection.getResponseCode(); in = connection.getInputStream(); response = readFirstLine(in); } finally { // Clean up. if (out != null) out.close(); if (in != null) in.close(); } // HttpPost httpPost = new HttpPost(httpOrS + SERVERURL // + this.servletUrl); // httpPost.setEntity(new UrlEncodedFormEntity(postParams, // "UTF-8")); // response = httpclient.execute(httpPost); } catch (IOException e) { errorcode = -1; cancel(false); return null; } } httpState = responseCode; JSONObject resData = new JSONObject(); String resString = ""; try { resString = response; resData = new JSONObject(resString); if (httpState != 200) { errorcode = resData.getInt("CODE"); cancel(false); return null; } } catch (JSONException e) { if (httpState != 200) { errorcode = httpState; } else { errorcode = -2; } cancel(false); return null; } return resData; }
From source file:com.senseidb.dataprovider.http.HttpStreamDataProvider.java
public HttpStreamDataProvider(Comparator<String> versionComparator, String baseUrl, String pw, int fetchSize, String startingOffset, boolean disableHttps) { super(versionComparator); _baseUrl = baseUrl;/*from ww w .j ava2s. co m*/ _password = pw; _fetchSize = fetchSize; _offset = startingOffset; _disableHttps = disableHttps; _initialOffset = null; _currentDataIter = null; _stopped = true; _httpGetLatency = 0L; _responseParseLatency = 0L; Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory()); SchemeRegistry sr = new SchemeRegistry(); sr.register(http); HttpParams params = new BasicHttpParams(); params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setParameter(HttpProtocolParams.HTTP_CONTENT_CHARSET, "UTF-8"); params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 5000); // 5s conn timeout params.setIntParameter(HttpConnectionParams.SO_LINGER, 0); // no socket linger params.setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true); // tcp no delay params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 5000); // 5s sock timeout params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 1024 * 1024); // 1mb socket buffer params.setBooleanParameter(HttpConnectionParams.SO_REUSEADDR, true); // 5s sock timeout _httpClientManager = new SingleClientConnManager(sr); _httpclient = new DefaultHttpClient(_httpClientManager, params); if (!_disableHttps) { _httpclient = HttpsClientDecorator.decorate(_httpclient); } _httpclient.addRequestInterceptor(new HttpRequestInterceptor() { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } } }); _httpclient.addResponseInterceptor(new HttpResponseInterceptor() { public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); Header ceheader = entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs = ceheader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } }); _retryTime = DEFAULT_RETRYTIME_MS; // default retry after 5 seconds }
From source file:org.springframework.data.solr.server.support.SolrClientUtilTests.java
/** * @see DATASOLR-189/*from w w w . j a va2 s. c o m*/ */ @Test public void cloningHttpSolrClientShouldCopyHttpParamsCorrectly() { HttpParams params = new BasicHttpParams(); params.setParameter("foo", "bar"); DefaultHttpClient client = new DefaultHttpClient(params); HttpSolrClient solrClient = new HttpSolrClient(BASE_URL, client); HttpSolrClient cloned = SolrClientUtils.clone(solrClient); Assert.assertThat(cloned.getHttpClient().getParams(), IsEqual.equalTo(params)); }
From source file:org.springframework.data.solr.server.support.SolrClientUtilTests.java
/** * @see DATASOLR-189//w w w . j a v a 2 s . c o m */ @Test public void cloningLBHttpSolrClientShouldCopyHttpParamsCorrectly() throws MalformedURLException { HttpParams params = new BasicHttpParams(); params.setParameter("foo", "bar"); DefaultHttpClient client = new DefaultHttpClient(params); LBHttpSolrClient lbSolrClient = new LBHttpSolrClient(client, BASE_URL, ALTERNATE_BASE_URL); LBHttpSolrClient cloned = SolrClientUtils.clone(lbSolrClient, CORE_NAME); Assert.assertThat(cloned.getHttpClient().getParams(), IsEqual.equalTo(params)); }
From source file:com.dgwave.osrs.OsrsClient.java
/** * Create HttpParams from configuration//from w w w . j a v a 2 s. c om * @return HttpParams */ private HttpParams getHttpParams() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); return params; }
From source file:fr.itinerennes.ItineRennesApplication.java
/** * Gets a reference to the HttpClient.//from w w w .j a va 2s .c o m * * @return a reference to the {@link ProgressHttpClient} */ public final HttpClient getHttpClient() { if (httpClient == null) { final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); final HttpParams cxParams = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(cxParams, 5); HttpConnectionParams.setConnectionTimeout(cxParams, 60000); final ThreadSafeClientConnManager connexionManager = new ThreadSafeClientConnManager(cxParams, registry); final String appVersion = VersionUtils.getCurrent(this); final String userAgent = String.format("ItineRennes/%s (Android/%s; SDK %s; %s; %s)", appVersion, android.os.Build.VERSION.RELEASE, android.os.Build.VERSION.SDK_INT, android.os.Build.MODEL, android.os.Build.DEVICE); final HttpParams clientParams = new BasicHttpParams(); clientParams.setParameter(HttpProtocolParams.USER_AGENT, userAgent); httpClient = new DefaultHttpClient(connexionManager, clientParams); } return httpClient; }
From source file:br.gov.frameworkdemoiselle.behave.integration.alm.ALMIntegration.java
public HttpResponse sendRequest(HttpClient client, String resource, String id, String xmlRequest) throws ClientProtocolException, IOException { String url = urlServer + "resources/" + projectAreaAlias + "/" + resource + "/" + id; log.debug(url);/*from w ww .j a v a2 s. co m*/ HttpPut request = new HttpPut(url); request.addHeader("Content-Type", "application/xml; charset=" + ENCODING); request.addHeader("Encoding", ENCODING); HttpParams params = request.getParams(); params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); // Seta o encoding da mensagem XML ContentType ct = ContentType.create("text/xml", ENCODING); StringEntity se = new StringEntity(xmlRequest, ct); se.setContentType("text/xml"); se.setContentEncoding(ENCODING); request.setEntity(se); log.debug(xmlRequest); return client.execute(request); }
From source file:com.graphaware.test.util.TestHttpClient.java
protected void setParams(HttpRequestBase method, Map<String, String> params) { if (params == null) { return;/*from w ww . java2 s.com*/ } HttpParams httpParams = new BasicHttpParams(); for (Map.Entry<String, String> paramEntry : params.entrySet()) { httpParams.setParameter(paramEntry.getKey(), paramEntry.getValue()); } method.setParams(httpParams); }
From source file:com.akop.bach.parser.LiveParser.java
protected LiveParser(Context context) { super(context); HttpParams params = mHttpClient.getParams(); //params.setParameter("http.useragent", USER_AGENT); params.setParameter("http.protocol.max-redirects", 0); }
From source file:eu.prestoprime.p4gui.connection.P4HttpClient.java
public P4HttpClient(String userID) { HttpParams params = new BasicHttpParams(); // setup SSL/* w w w . j a va2 s . com*/ try { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000L); SSLSocket socket = (SSLSocket) sf.createSocket(params); socket.setEnabledCipherSuites(new String[] { "SSL_RSA_WITH_RC4_128_MD5" }); Scheme sch = new Scheme("https", 443, sf); this.getConnectionManager().getSchemeRegistry().register(sch); } catch (IOException | KeyManagementException | NoSuchAlgorithmException e) { logger.error("Unable to create SSL handler for HttpClient..."); e.printStackTrace(); } // save userID this.userID = userID; }