List of usage examples for org.apache.http.params HttpParams setParameter
HttpParams setParameter(String str, Object obj);
From source file:com.jrodeo.queue.messageset.provider.TestHttpClient5.java
public TestHttpClient5() { super();//from www . j av a 2 s. c o m HttpParams params = new SyncBasicHttpParams(); params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false); params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024); params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 15000); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); this.mgr = new PoolingClientConnectionManager(schemeRegistry); this.httpclient = new DefaultHttpClient(this.mgr, params); this.httpclient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() { public boolean retryRequest(final IOException exception, int executionCount, final HttpContext context) { return false; } }); }
From source file:com.sap.core.odata.fit.basic.UrlRewriteTest.java
private HttpRequestBase createRedirectRequest(final Class<? extends HttpRequestBase> clazz) throws Exception { String endpoint = getEndpoint().toASCIIString(); endpoint = endpoint.substring(0, endpoint.length() - 1); final HttpRequestBase httpMethod = clazz.newInstance(); httpMethod.setURI(URI.create(endpoint)); final HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.handle-redirects", false); httpMethod.setParams(params);//from ww w .j ava 2 s .c o m return httpMethod; }
From source file:com.sap.core.odata.fit.basic.UrlRewriteTest.java
@Test public void testGetServiceDocumentWithSlash() throws Exception { final HttpGet get = new HttpGet(URI.create(getEndpoint().toString())); final HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.handle-redirects", false); get.setParams(params);/*from w ww . j a va2s . c o m*/ final HttpResponse response = getHttpClient().execute(get); final String payload = StringHelper.inputStreamToString(response.getEntity().getContent()); assertEquals("service document", payload); assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode()); }
From source file:com.sap.core.odata.fit.basic.UrlRewriteTest.java
@Test public void testGetMetadata() throws Exception { final HttpGet get = new HttpGet(URI.create(getEndpoint().toString() + "$metadata")); final HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.handle-redirects", false); get.setParams(params);/* ww w . j a va 2s . c o m*/ final HttpResponse response = getHttpClient().execute(get); final String payload = StringHelper.inputStreamToString(response.getEntity().getContent()); assertEquals("metadata", payload); assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode()); }
From source file:io.undertow.server.handlers.HttpContinueConduitWrappingHandlerTestCase.java
@Test public void testHttpContinueAcceptedWithChunkedRequest() throws IOException { accept = true;// www .java 2s .c om String message = "My HTTP Request!"; HttpParams httpParams = new BasicHttpParams(); httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE); TestHttpClient client = new TestHttpClient(); client.setParams(httpParams); try { HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path"); post.addHeader("Expect", "100-continue"); post.setEntity(new StringEntity(message) { @Override public long getContentLength() { return -1; } }); HttpResponse result = client.execute(post); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); Assert.assertEquals(message, HttpClientUtils.readResponse(result)); } finally { client.getConnectionManager().shutdown(); } }
From source file:com.citrix.g2w.webdriver.util.FileDownloader.java
public String downloader(String fileToDownloadLocation, String localDownloadPath) throws IOException, URISyntaxException { URL fileToDownload = new URL(fileToDownloadLocation); String fileNameURI = fileToDownload.getFile(); String filePath = ""; if (fileNameURI.contains("?")) { filePath = localDownloadPath//from w w w .java 2 s. co m + fileNameURI.substring(fileNameURI.substring(0, fileNameURI.indexOf("?")).lastIndexOf("/") + 1, fileNameURI.indexOf("?")); } else { filePath = localDownloadPath + fileNameURI.substring(fileNameURI.lastIndexOf("/") + 1); } File downloadedFile = new File(filePath); if (downloadedFile.canWrite() == false) { downloadedFile.setWritable(true); } HttpClient client = new DefaultHttpClient(); BasicHttpContext localContext = new BasicHttpContext(); if (this.mimicWebDriverCookieState) { localContext.setAttribute(ClientContext.COOKIE_STORE, this.mimicCookieState(this.driver.manage().getCookies())); } HttpGet httpget = new HttpGet(fileToDownload.toURI()); HttpParams httpRequestParameters = httpget.getParams(); httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects); httpget.setParams(httpRequestParameters); HttpResponse response = client.execute(httpget, localContext); FileUtils.copyInputStreamToFile(response.getEntity().getContent(), downloadedFile); response.getEntity().getContent().close(); String downloadedFileAbsolutePath = downloadedFile.getAbsolutePath(); this.logger.log("File downloaded to '" + downloadedFileAbsolutePath + "'"); return downloadedFileAbsolutePath; }
From source file:gmusic.api.comm.ApacheConnector.java
public ApacheConnector() { HttpParams params = new BasicHttpParams(); params.removeParameter("User-Agent"); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH); // HttpConnectionParams.setConnectionTimeout(params, 150000); // HttpConnectionParams.setSoTimeout(params, socketTimeoutMillis); httpClient = new DefaultHttpClient(params); cookieStore = new BasicCookieStore(); localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }
From source file:org.bug4j.client.HttpConnector.java
private HttpConnector(String serverUrl, String proxyHost, int proxyPort, String applicationName, String applicationVersion, long buildDate, boolean devBuild, Integer buildNumber) { serverUrl = serverUrl.trim();/* w ww . jav a 2 s.c om*/ if (!serverUrl.endsWith("/")) { serverUrl = serverUrl + "/"; } _serverUri = serverUrl; _applicationName = applicationName; _applicationVersion = applicationVersion; _buildDate = buildDate; _devBuild = devBuild; _buildNumber = buildNumber; _httpClient = new DefaultHttpClient(); if (proxyHost != null) { final HttpHost proxyHttpHost = new HttpHost(proxyHost, proxyPort); final HttpParams httpClientParams = _httpClient.getParams(); httpClientParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHttpHost); } }
From source file:com.almende.util.ApacheHttpClient.java
/** * Instantiates a new apache http client. * /*w w w . j av a 2s. co m*/ */ private ApacheHttpClient() { // generate httpclient httpClient = new DefaultHttpClient(); // Set cookie policy and persistent cookieStore try { httpClient.setCookieStore(new MyCookieStore()); } catch (final Exception e) { LOG.log(Level.WARNING, "Failed to initialize persistent cookieStore!", e); } final HttpParams params = httpClient.getParams(); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); params.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false); httpClient.setParams(params); }
From source file:com.DGSD.DGUtils.Http.BetterHttp.java
public static void updateProxySettings() { if (appContext == null) { return;//from ww w. j ava 2 s.co m } HttpParams httpParams = httpClient.getParams(); ConnectivityManager connectivity = (ConnectivityManager) appContext .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nwInfo = connectivity.getActiveNetworkInfo(); if (nwInfo == null) { return; } Log.i(LOG_TAG, nwInfo.toString()); if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) { String proxyHost = Proxy.getHost(appContext); if (proxyHost == null) { proxyHost = Proxy.getDefaultHost(); } int proxyPort = Proxy.getPort(appContext); if (proxyPort == -1) { proxyPort = Proxy.getDefaultPort(); } if (proxyHost != null && proxyPort > -1) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } } else { httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null); } }