List of usage examples for org.apache.commons.httpclient HttpClient getParams
public HttpClientParams getParams()
From source file:com.braindrainpain.docker.httpsupport.HttpClientService.java
private HttpClient createHttpClient() { HttpClient client = new HttpClient(); client.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, this.getSystemProperty("docker.repo.connection.timeout", 10 * 1000)); client.getParams().setSoTimeout(this.getSystemProperty("docker.repo.socket.timeout", 5 * 60 * 1000)); return client; }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClientIT.java
@Test public void test() throws Exception { HttpClient client = new HttpClient(); client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT); client.getParams().setSoTimeout(SO_TIMEOUT); GetMethod method = new GetMethod(webServer.getCallHttpUrl()); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") }); try {/* w ww.j a v a2s . co m*/ // Execute the method. client.executeMethod(method); } catch (Exception ignored) { } finally { method.releaseConnection(); } PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); }
From source file:com.lp.client.frame.component.phone.HttpPhoneDialer.java
protected void prepareClient(HttpClient client, GetMethod method) { client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true); }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClientIT.java
@Test public void hostConfig() throws Exception { HttpClient client = new HttpClient(); client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT); client.getParams().setSoTimeout(SO_TIMEOUT); HostConfiguration config = new HostConfiguration(); config.setHost("weather.naver.com", 80, "http"); GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn"); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") }); try {// www . j av a2 s.com // Execute the method. client.executeMethod(config, method); } catch (Exception ignored) { } finally { method.releaseConnection(); } PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); }
From source file:edu.du.penrose.systems.fedoraApp.tests.sendEctdRestResults.java
public void testRun() { try {//from w w w .j av a 2s . c om HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "fedoraProxy Client"); final String HOST = "130.253.33.105"; final String PORT = "8085"; final String CMD = "/library/updatePid"; final String KEY = "6b476c7e50726949347162353c7e3d7271336e6f3e3e4c2d703d762d24"; String objid = "du_174_1793_primary_1999_kelly"; String pid = "178"; StringBuffer ectdResultsUrl = new StringBuffer("http://"); ectdResultsUrl.append(HOST); ectdResultsUrl.append(":"); ectdResultsUrl.append(PORT); ectdResultsUrl.append(CMD); GetMethod method = new GetMethod(ectdResultsUrl.toString()); HttpMethodParams params = new HttpClientParams(); params.setParameter("id", objid); params.setParameter("pid", pid); method.setParams(params); try { int returnCode = client.executeMethod(method); if (returnCode != HttpStatus.SC_OK) { System.err.println("ERROR"); } } catch (Exception e) { System.err.println(e); } finally { method.releaseConnection(); } } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }
From source file:com.gs.jrpip.client.AuthenticatedUrl.java
public void setCredentialsOnClient(HttpClient client) { if (this.credentials != null) { client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, this.credentials); }/*from w ww . j a v a 2 s . c o m*/ if (this.cookies != null && this.cookies.length > 0) { client.getState().addCookies(this.cookies); } }
From source file:com.trunghoang.teammedical.utils.FileDownloader.java
public File urlDownloader(String downloadLocation) throws Exception { URL downloadURL = new URL(downloadLocation); HttpClient client = new HttpClient(); client.getParams().setCookiePolicy(CookiePolicy.RFC_2965); client.setHostConfiguration(mimicHostConfiguration(downloadURL.getHost(), downloadURL.getPort())); client.getParams().makeLenient();/* w ww . ja v a 2 s . c o m*/ client.setState(mimicCookieState(driver.manage().getCookies())); HttpMethod getRequest = new GetMethod(downloadLocation); getRequest.setFollowRedirects(true); FileHandler downloadedFile = new FileHandler( downloadPath + downloadURL.getFile().replaceFirst("/|\\\\", ""), true); try { int status = client.executeMethod(getRequest); log.info("HTTP Status {} when getting '{}'", status, downloadURL.toExternalForm()); downloadedFile.getWritableFileOutputStream().write(getRequest.getResponseBody()); downloadedFile.close(); log.info("File downloaded to '{}'", downloadedFile.getAbsoluteFile()); } catch (Exception Ex) { log.error("Download failed: {}", Ex); throw new Exception("Download failed!"); } finally { getRequest.releaseConnection(); } return downloadedFile.getFile(); }
From source file:jenkins.plugins.elanceodesk.workplace.notifier.HttpWorker.java
public void run() { int tried = 0; boolean success = false; HttpClient client = getHttpClient(); client.getParams().setConnectionManagerTimeout(timeout); do {//from w w w . j a v a 2 s . co m tried++; RequestEntity requestEntity; try { requestEntity = new StringRequestEntity(data, "application/json", "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(logger); break; } logger.println(String.format("Posting data to webhook - %s. Already Tried %s times", url, tried)); PostMethod post = new PostMethod(url); try { post.setRequestEntity(requestEntity); int responseCode = client.executeMethod(post); if (responseCode != HttpStatus.SC_OK) { String response = post.getResponseBodyAsString(); logger.println(String.format( "Posting data to - %s may have failed. Webhook responded with status code - %s", url, responseCode)); logger.println(String.format("Message from webhook - %s", response)); } else { success = true; logger.println(String.format("Posting data to webhook - %s completed ", url)); } } catch (Exception e) { logger.println(String.format("Failed to post data to webhook - %s", url)); e.printStackTrace(logger); } finally { post.releaseConnection(); } } while (tried < retries && !success); }
From source file:eu.impact_project.iif.t2.client.InfoGenerator.java
/** * Gets information about a workflow.//from w w w . ja v a 2 s . c om */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); String wfId = request.getParameter("id"); String urlString = "http://www.myexperiment.org/workflow.xml?id=" + wfId; String user = (String) session.getAttribute("user"); String password = (String) session.getAttribute("password"); // prepare httpclient for basic authentication HttpClient client = new HttpClient(); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(new AuthScope("www.myexperiment.org", 80), new UsernamePasswordCredentials(user, password)); GetMethod get = new GetMethod(urlString); get.setDoAuthentication(true); client.executeMethod(get); InputStream responseBody = get.getResponseBodyAsStream(); try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(responseBody); WorkflowDetails details = new WorkflowDetails(); Element root = doc.getRootElement(); details.setTitle(root.getChild("title").getTextTrim()); details.setDescription(root.getChild("description").getTextTrim()); details.setImageUrl(root.getChild("preview").getTextTrim()); session.setAttribute("wfDetails", details); } catch (JDOMException e) { e.printStackTrace(); } RequestDispatcher rd = getServletContext().getRequestDispatcher("/info.jsp"); rd.forward(request, response); }
From source file:edu.unc.lib.dl.cdr.sword.server.test.DepositClientsByHand.java
@Test public void testUpload() throws Exception { String user = ""; String password = ""; String pid = "uuid:c9aba0a2-12e9-4767-822e-b285a37b07d7"; String payloadMimeType = "text/xml"; String payloadPath = "src/test/resources/dcDocument.xml"; String metadataPath = "src/test/resources/atompubMODS.xml"; String depositPath = "https://localhost:444/services/sword/collection/"; String testSlug = "ingesttestslug"; HttpClient client = HttpClientUtil.getAuthenticatedClient(depositPath + pid, user, password); client.getParams().setAuthenticationPreemptive(true); PostMethod post = new PostMethod(depositPath + pid); File payload = new File(payloadPath); File atom = new File(metadataPath); FilePart payloadPart = new FilePart("payload", payload); payloadPart.setContentType(payloadMimeType); payloadPart.setTransferEncoding("binary"); Part[] parts = { payloadPart, new FilePart("atom", atom, "application/atom+xml", "utf-8") }; MultipartRequestEntity mpEntity = new MultipartRequestEntity(parts, post.getParams()); String boundary = mpEntity.getContentType(); boundary = boundary.substring(boundary.indexOf("boundary=") + 9); Header header = new Header("Content-type", "multipart/related; type=application/atom+xml; boundary=" + boundary); post.addRequestHeader(header);// w ww . j a v a 2 s . c om Header slug = new Header("Slug", testSlug); post.addRequestHeader(slug); post.setRequestEntity(mpEntity); LOG.debug("" + client.executeMethod(post)); }