List of usage examples for org.apache.commons.httpclient HttpClient getParams
public HttpClientParams getParams()
From source file:com.predic8.membrane.core.interceptor.balancer.LoadBalancingWithClusterManagerTest.java
private HttpClient getClient() { HttpClient client = new HttpClient(); client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); return client; }
From source file:com.testmax.util.FileDownLoader.java
public String downloader(WebElement element, String attribute) throws Exception { //Assuming that getAttribute does some magic to return a fully qualified URL String downloadLocation = element.getAttribute(attribute); if (downloadLocation.trim().equals("")) { throw new Exception("The element you have specified does not link to anything!"); }//w ww .ja v a2s. com URL downloadURL = new URL(downloadLocation); HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); client.setHostConfiguration(mimicHostConfiguration(downloadURL.getHost(), downloadURL.getPort())); client.setState(mimicCookieState(driver.manage().getCookies())); HttpMethod getRequest = new GetMethod(downloadURL.getPath()); String file_path = downloadPath + downloadURL.getFile().replaceFirst("/|\\\\", ""); FileWriter downloadedFile = new FileWriter(file_path, true); try { int status = client.executeMethod(getRequest); WmLog.getCoreLogger().info("HTTP Status {} when getting '{}'" + status + downloadURL.toExternalForm()); BufferedInputStream in = new BufferedInputStream(getRequest.getResponseBodyAsStream()); int offset = 0; int len = 4096; int bytes = 0; byte[] block = new byte[len]; while ((bytes = in.read(block, offset, len)) > -1) { downloadedFile.write(bytes); } downloadedFile.close(); in.close(); WmLog.getCoreLogger().info("File downloaded to '{}'" + file_path); } catch (Exception Ex) { WmLog.getCoreLogger().error("Download failed: {}", Ex); throw new Exception("Download failed!"); } finally { getRequest.releaseConnection(); } return file_path; }
From source file:jenkins.plugins.office365connector.HttpWorker.java
@Override public void run() { int tried = 0; boolean success = false; HttpClient client = getHttpClient(); client.getParams().setConnectionManagerTimeout(timeout); do {//from ww w . j a v a 2 s.co m tried++; RequestEntity requestEntity; try { // uncomment to log what message has been sent // log("Posted JSON: %s", data); requestEntity = new StringRequestEntity(data, "application/json", StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { e.printStackTrace(logger); break; } PostMethod post = new PostMethod(url); try { post.setRequestEntity(requestEntity); int responseCode = client.executeMethod(post); if (responseCode != HttpStatus.SC_OK) { String response = post.getResponseBodyAsString(); log("Posting data to %s may have failed. Webhook responded with status code - %s", url, responseCode); log("Message from webhook - %s", response); } else { success = true; } } catch (IOException e) { log("Failed to post data to webhook - %s", url); e.printStackTrace(logger); } finally { post.releaseConnection(); } } while (tried < RETRIES && !success); }
From source file:com.orange.mmp.net.http.HttpConnectionManager.java
public void initialize() throws MMPException { // prepare parameters for (int i = 0; i < POOL_SIZE; i++) { HttpClient httpClient = new HttpClient(); httpClient.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); httpClient.getParams().setParameter("http.tcp.nodelay", true); httpClient.getParams().setParameter("http.connection.stalecheck", false); httpClient.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); idleConnectionCleaner.addConnectionManager(httpClient.getHttpConnectionManager()); httpClientPool.add(httpClient);/*from w w w . j a va 2 s .com*/ } idleConnectionCleaner.setConnectionTimeout(-1000); idleConnectionCleaner.setTimeoutInterval(1000); idleConnectionCleaner.start(); }
From source file:com.lazerycode.ebselen.customhandlers.FileDownloader.java
public String downloader(WebElement element, String attribute) throws Exception { //Assuming that getAttribute does some magic to return a fully qualified URL String downloadLocation = element.getAttribute(attribute); if (downloadLocation.trim().equals("")) { throw new Exception("The element you have specified does not link to anything!"); }//from ww w . j a va2s. c om URL downloadURL = new URL(downloadLocation); HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.RFC_2965); client.setHostConfiguration(mimicHostConfiguration(downloadURL.getHost(), downloadURL.getPort())); client.setState(mimicCookieState(driver.manage().getCookies())); HttpMethod getRequest = new GetMethod(downloadURL.getPath()); FileHandler downloadedFile = new FileHandler( downloadPath + downloadURL.getFile().replaceFirst("/|\\\\", ""), true); try { int status = client.executeMethod(getRequest); LOGGER.info("HTTP Status {} when getting '{}'", status, downloadURL.toExternalForm()); BufferedInputStream in = new BufferedInputStream(getRequest.getResponseBodyAsStream()); int offset = 0; int len = 4096; int bytes = 0; byte[] block = new byte[len]; while ((bytes = in.read(block, offset, len)) > -1) { downloadedFile.getWritableFileOutputStream().write(block, 0, bytes); } downloadedFile.close(); in.close(); LOGGER.info("File downloaded to '{}'", downloadedFile.getAbsoluteFile()); } catch (Exception Ex) { LOGGER.error("Download failed: {}", Ex); throw new Exception("Download failed!"); } finally { getRequest.releaseConnection(); } return downloadedFile.getAbsoluteFile(); }
From source file:jhc.redsniff.webdriver.download.FileDownloader.java
private HttpClient createHttpClient(URL downloadURL) { HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.RFC_2965); client.setHostConfiguration(mimicHostConfiguration(downloadURL.getHost(), downloadURL.getPort())); client.setState(mimicCookieState(driver.manage().getCookies())); return client; }
From source file:eu.learnpad.cw.rest.internal.DefaultXWikiPackage.java
private void putPage(File indexFile, String spaceName, String pageName) throws XWikiRestException, JAXBException { HttpClient httpClient = new HttpClient(); httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials("Admin", "admin"); httpClient.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds); PutMethod putMethod = new PutMethod( "http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/" + spaceName + "/pages/" + pageName); putMethod.addRequestHeader("Accept", "application/xml"); putMethod.addRequestHeader("Accept-Ranges", "bytes"); RequestEntity fileRequestEntity = new FileRequestEntity(indexFile, "application/xml"); putMethod.setRequestEntity(fileRequestEntity); try {//from w w w .jav a2s . com httpClient.executeMethod(putMethod); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:eu.learnpad.cw.rest.internal.DefaultXWikiPackage.java
private void postObject(File objectFile, String spaceName, String pageName, String className) throws XWikiRestException { HttpClient httpClient = new HttpClient(); httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials("Admin", "admin"); httpClient.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds); PostMethod postMethod = new PostMethod("http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/" + spaceName + "/pages/" + pageName + "/objects"); postMethod.addRequestHeader("Accept", "application/xml"); postMethod.addRequestHeader("Accept-Ranges", "bytes"); RequestEntity fileRequestEntity = new FileRequestEntity(objectFile, "application/xml"); postMethod.setRequestEntity(fileRequestEntity); try {/* w ww . j a v a2 s.c o m*/ httpClient.executeMethod(postMethod); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.intellij.tasks.impl.BaseRepositoryImpl.java
protected void configureHttpClient(HttpClient client) { client.getParams().setConnectionManagerTimeout(3000); client.getParams().setSoTimeout(TaskSettings.getInstance().CONNECTION_TIMEOUT); if (isUseProxy()) { HttpConfigurable proxy = HttpConfigurable.getInstance(); client.getHostConfiguration().setProxy(proxy.PROXY_HOST, proxy.PROXY_PORT); if (proxy.PROXY_AUTHENTICATION) { AuthScope authScope = new AuthScope(proxy.PROXY_HOST, proxy.PROXY_PORT); Credentials credentials = getCredentials(proxy.getProxyLogin(), proxy.getPlainProxyPassword(), proxy.PROXY_HOST);//from ww w .j a va 2 s . c o m client.getState().setProxyCredentials(authScope, credentials); } } if (isUseHttpAuthentication()) { client.getParams().setCredentialCharset("UTF-8"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword())); } else { client.getState().clearCredentials(); client.getParams().setAuthenticationPreemptive(false); } }
From source file:com.google.jstestdriver.requesthandlers.RequestHandlersModule.java
@Provides @Singleton// ww w . j a va 2 s . c o m HttpClient provideHttpClient() { Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443)); MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.getParams().setDefaultMaxConnectionsPerHost(20); manager.getParams().setMaxTotalConnections(200); HttpClient client = new HttpClient(manager); client.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); return client; }