List of usage examples for org.apache.commons.httpclient HostConfiguration HostConfiguration
public HostConfiguration()
From source file:org.pentaho.di.trans.steps.webservices.WebService.java
private void initWsdlEnv() throws KettleException { if (meta.equals(cachedMeta)) { return;// w ww . j a v a 2 s .c o m } cachedMeta = meta; try { cachedWsdl = new Wsdl(new java.net.URI(data.realUrl), null, null, meta.getHttpLogin(), meta.getHttpPassword()); } catch (Exception e) { throw new KettleStepException(BaseMessages.getString(PKG, "WebServices.ERROR0013.ExceptionLoadingWSDL"), e); } cachedURLService = cachedWsdl.getServiceEndpoint(); cachedHostConfiguration = new HostConfiguration(); cachedHttpClient = getHttpClient(cachedHostConfiguration); // Generate the XML to send over, determine the correct name for the request... // cachedOperation = cachedWsdl.getOperation(meta.getOperationName()); if (cachedOperation == null) { throw new KettleException(BaseMessages.getString(PKG, "WebServices.Exception.OperarationNotSupported", meta.getOperationName(), meta.getUrl())); } }
From source file:org.pentaho.marketplace.util.web.HttpUtil.java
public static HttpClient getClient() { int connectionTimeout = 3000; int pageTimeout = 7000; HttpConnectionManager connectionManager = new SimpleHttpConnectionManager(); HttpConnectionManagerParams connectionParams = connectionManager.getParams(); connectionParams.setConnectionTimeout(connectionTimeout); connectionParams.setSoTimeout(pageTimeout); HttpClient httpClient = null;// w ww .ja v a2s.c om if (connectionManager != null) { httpClient = new HttpClient(connectionManager); } try { HostConfiguration hostConfig = null; final String proxyHost = System.getProperty(PROXY_HOST_PROPERTY_NAME); final int proxyPort = Integer.parseInt(System.getProperty(PROXY_PORT_PROPERTY_NAME)); if (StringUtils.isNotEmpty(proxyHost)) { hostConfig = new HostConfiguration() { @Override public synchronized String getProxyHost() { return proxyHost; } @Override public synchronized int getProxyPort() { return proxyPort; } }; httpClient.setHostConfiguration(hostConfig); String proxyUser = System.getProperty(PROXY_USER_PROPERTY_NAME); String proxyPassword = System.getProperty(PROXY_PASSWORD_PROPERTY_NAME); if (proxyUser != null && proxyUser.trim().length() > 0) { httpClient.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword)); } } } catch (Exception ignored) { } return httpClient; }
From source file:org.pentaho.platform.util.web.HttpUtil.java
public static boolean getURLContent(final String url, final StringBuffer content) throws MalformedURLException, IOException { HttpClient httpClient = HttpUtil.getClient(); try {/*from w ww. j a v a 2 s . com*/ HostConfiguration hostConfig = null; if (StringUtils.isNotEmpty(System.getProperty("http.proxyHost"))) { hostConfig = new HostConfiguration() { @Override public synchronized String getProxyHost() { return System.getProperty("http.proxyHost"); } @Override public synchronized int getProxyPort() { return Integer.parseInt(System.getProperty("http.proxyPort")); } }; httpClient.setHostConfiguration(hostConfig); if (System.getProperty("http.proxyUser") != null && System.getProperty("http.proxyUser").trim().length() > 0) { httpClient.getState().setProxyCredentials( new AuthScope(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort"))), new UsernamePasswordCredentials(System.getProperty("http.proxyUser"), System.getProperty("http.proxyPassword"))); } } GetMethod call = new GetMethod(url); int status = httpClient.executeMethod(hostConfig, call); if (status == 200) { InputStream response = call.getResponseBodyAsStream(); try { byte[] buffer = new byte[2048]; int size = response.read(buffer); while (size > 0) { for (int idx = 0; idx < size; idx++) { content.append((char) buffer[idx]); } size = response.read(buffer); } } catch (Exception e) { // we can ignore this because the content comparison will fail } } } catch (Throwable e) { StringWriter writer = new StringWriter(); PrintWriter writer2 = new PrintWriter(writer); e.printStackTrace(writer2); content.append(writer.getBuffer()); return false; } return true; }
From source file:org.portletbridge.portlet.DefaultHttpClientTemplate.java
public Object service(HttpMethodBase method, HttpClientState state, HttpClientCallback callback) throws ResourceException { try {// w w w .ja v a 2s .co m HostConfiguration hostConfiguration = new HostConfiguration(); if (state.getProxyHost() != null && state.getProxyHost().trim().length() > 0) { hostConfiguration.setProxy(state.getProxyHost(), state.getProxyPort()); } hostConfiguration.setHost(method.getURI()); int statusCode = httpClient.executeMethod(hostConfiguration, method, state.getHttpState()); return callback.doInHttpClient(statusCode, method); } catch (ResourceException e) { throw e; } catch (Throwable e) { throw new ResourceException("error.httpclient", e.getMessage(), e); } finally { method.releaseConnection(); } }
From source file:org.redpill.alfresco.pdfapilot.client.PdfaPilotClientImpl.java
private HttpClient createHttpClient(int retries, int connectionTimeoutInMillis) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient client = new HttpClient(connectionManager); client.getHttpConnectionManager().getParams().setTcpNoDelay(true); client.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeoutInMillis); client.getHttpConnectionManager().getParams().setSoTimeout(_transformationTimeout * 1000); client.getHttpConnectionManager().getParams().setMaxTotalConnections(_maxTotalConnections); client.getHttpConnectionManager().getParams().setDefaultMaxConnectionsPerHost(_maxConcurrentConnections); URI uri;//from ww w .j av a 2 s .co m try { uri = new URI(_serverUrl); } catch (URISyntaxException e) { throw new RuntimeException(e); } HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(uri.getHost(), uri.getPort(), uri.getScheme()); client.getHttpConnectionManager().getParams().setMaxConnectionsPerHost(hostConfiguration, _maxConcurrentConnections); client.getState().setCredentials(new AuthScope(null, -1, null), new UsernamePasswordCredentials(_username, _password)); client.getParams().setAuthenticationPreemptive(true); DefaultHttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(retries, true); client.getParams().setParameter("http.method.retry-handler", retryhandler); return client; }
From source file:org.seasr.meandre.components.tools.tapor.restservice.Concordance.java
@Override public void executeCallBack(ComponentContext cc) throws Exception { String htmlTag = cc.getProperty(PROP_HTML_TAG); String pattern = cc.getProperty(PROP_PATTERN); String context = cc.getProperty(PROP_CONTEXT); String contextLen = cc.getProperty(PROP_CONTEXT_LENGTH); String outFormat = cc.getProperty(PROP_OUT_FORMAT); String htmlInput = DataTypeParser.parseAsString(cc.getDataComponentFromInput(IN_TEXT))[0]; try {/*from www . j a va 2s . c o m*/ URL url = new URL(serviceLoc); HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost(url.getHost(), url.getPort()); HttpClient httpClient = new HttpClient(new SimpleHttpConnectionManager()); httpClient.setHostConfiguration(hostConfig); PostMethod postMethod = new PostMethod(serviceLoc); postMethod.addParameter("htmlInput", htmlInput); postMethod.addParameter("htmlTag", htmlTag); ; postMethod.addParameter("pattern", pattern); postMethod.addParameter("context", context); postMethod.addParameter("contextlength", contextLen); postMethod.addParameter("outFormat", outFormat); httpClient.executeMethod(postMethod); BufferedReader in = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream())); String line = null; StringBuffer buf = new StringBuffer(); while ((line = in.readLine()) != null) buf.append(line).append("\n"); in.close(); cc.pushDataComponentToOutput(OUT_TEXT, BasicDataTypesTools.stringToStrings(buf.toString())); } catch (Exception e) { throw new ComponentExecutionException(e); } }
From source file:org.seasr.meandre.components.tools.tapor.restservice.ListWords.java
@Override public void executeCallBack(ComponentContext cc) throws Exception { String htmlInput = DataTypeParser.parseAsString(cc.getDataComponentFromInput(IN_TEXT))[0]; URL url = new URL(serviceLoc); HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost(url.getHost(), url.getPort()); HttpClient httpClient = new HttpClient(new SimpleHttpConnectionManager()); httpClient.setHostConfiguration(hostConfig); PostMethod postMethod = new PostMethod(serviceLoc); postMethod.addParameter("htmlInput", htmlInput); postMethod.addParameter("htmlTag", htmlTag); postMethod.addParameter("listOption", listOption); postMethod.addParameter("optionSelection", optionSelection); postMethod.addParameter("sorting", sorting); postMethod.addParameter("outFormat", outFormat); httpClient.executeMethod(postMethod); BufferedReader in = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream())); String line = null;// w w w. ja va 2 s. c om boolean firstLine = true; StringBuilder buf = new StringBuilder(); while ((line = in.readLine()) != null) { if (firstLine && line.startsWith("<pre>")) { line = line.substring(5); firstLine = false; } else if (line.trim().equals("</pre>")) continue; buf.append(line).append("\n"); } in.close(); cc.pushDataComponentToOutput(OUT_TEXT, BasicDataTypesTools.stringToStrings(buf.toString())); }
From source file:org.socraticgrid.displaycalendarlib.SogoCalendar.java
public HostConfiguration createHostConfiguration() { HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost(host, port, protocol); return hostConfig; }
From source file:org.springframework.security.saml.websso.ArtifactResolutionProfileImplTest.java
/** * Verifies that hostConfiguration is correctly cloned when HttpClient contains defaults. *///from w ww .j av a 2s . c om @Test public void testHostConfigurationWithDefaults() throws Exception { // Client object with default settings HttpClient client = new HttpClient(); HostConfiguration defaultConfiguration = new HostConfiguration(); defaultConfiguration.setProxy("testProxy", 8000); defaultConfiguration.getParams().setParameter("testParam", "testValue"); client.setHostConfiguration(defaultConfiguration); ArtifactResolutionProfileImpl artifactResolutionProfile = new ArtifactResolutionProfileImpl(client); URI uri = new URI("http", "test", "/artifact", null); HostConfiguration hostConfiguration = artifactResolutionProfile.getHostConfiguration(uri, null); // Verify that settings were cloned assertNotNull(hostConfiguration); assertEquals("test", hostConfiguration.getHost()); assertEquals("testProxy", hostConfiguration.getProxyHost()); assertEquals(8000, hostConfiguration.getProxyPort()); assertEquals("testValue", hostConfiguration.getParams().getParameter("testParam")); // Make sure default object and newly created configuration are independent defaultConfiguration.setProxyHost(null); assertEquals("testProxy", hostConfiguration.getProxyHost()); assertEquals(8000, hostConfiguration.getProxyPort()); }
From source file:org.springframework.ws.transport.http.CommonsHttpMessageSender.java
/** * Sets the maximum number of connections per host for the underlying HttpClient. The maximum number of connections * per host can be set in a form accepted by the {@code java.util.Properties} class, like as follows: * <pre>//from w ww. j a va 2s .c o m * https://www.example.com=1 * http://www.example.com:8080=7 * www.springframework.org=10 * *=5 * </pre> * The host can be specified as hostname, or as URI (with scheme and port). The special host name {@code *} can be * used to specify {@link org.apache.commons.httpclient.HostConfiguration#ANY_HOST_CONFIGURATION}. * * @param maxConnectionsPerHost a properties object specifying the maximum number of connection * @see org.apache.commons.httpclient.params.HttpConnectionManagerParams#setMaxConnectionsPerHost(org.apache.commons.httpclient.HostConfiguration, * int) */ public void setMaxConnectionsPerHost(Map<String, String> maxConnectionsPerHost) throws URIException { for (String host : maxConnectionsPerHost.keySet()) { HostConfiguration hostConfiguration = new HostConfiguration(); if ("*".equals(host)) { hostConfiguration = HostConfiguration.ANY_HOST_CONFIGURATION; } else if (host.startsWith("http://")) { HttpURL httpURL = new HttpURL(host); hostConfiguration.setHost(httpURL); } else if (host.startsWith("https://")) { HttpsURL httpsURL = new HttpsURL(host); hostConfiguration.setHost(httpsURL); } else { hostConfiguration.setHost(host); } int maxHostConnections = Integer.parseInt(maxConnectionsPerHost.get(host)); getHttpClient().getHttpConnectionManager().getParams().setMaxConnectionsPerHost(hostConfiguration, maxHostConnections); } }