List of usage examples for org.apache.commons.httpclient HostConfiguration HostConfiguration
public HostConfiguration()
From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java
public void testMultipleConnectionRelease() throws Exception { CommonsHttpConnectionManager manager = new CommonsHttpConnectionManager(null); HostConfiguration h1 = new HostConfiguration(); h1.setHost(address, server1.getLocalPort()); HttpConnection c1 = manager.getConnection(h1); assertTrue(!c1.isOpen());// ww w. j a va2 s . c om c1.open(); c1.releaseConnection(); c1.releaseConnection(); HttpConnection c2 = manager.getConnection(h1); assertTrue(c1 == c2); HttpConnection c3 = manager.getConnection(h1); assertTrue(c3 != c2); }
From source file:org.globus.axis.transport.commons.tests.CommonsHttpConnectionManagerTest.java
public void testHTTPContinue() throws Exception { HostConfiguration config = new HostConfiguration(); config.setHost(address, server1.getLocalPort()); HttpClient httpClient = new HttpClient(); PostMethod method = new PostMethod("/foo/bar"); method.setRequestBody("helloworld\r\n\r\n"); int returnCode = httpClient.executeMethod(config, method, null); assertEquals(200, returnCode);// w w w . j a va 2 s . c om }
From source file:org.globus.axis.transport.commons.tests.ExtendedHostConfigurationTest.java
private HostConfiguration getHostConfiguration(String[] params, String valueA, String valueB) { HostConfiguration h1 = new HostConfiguration(); h1.setHost("foobar", 80); ExtendedHostConfiguration eh1 = new ExtendedHostConfiguration(h1, params); eh1.getParams().setParameter("A", valueA); eh1.getParams().setParameter("B", valueB); // even if C is different it's not included in the test eh1.getParams().setParameter("C", String.valueOf(counter++)); return eh1;//from w ww . j a v a2s . c om }
From source file:org.globus.workspace.cloud.client.util.CumulusParameterConvert.java
private S3Service getService() throws S3ServiceException { String host = this.args.getXferHostPort(); int ndx = host.lastIndexOf(":"); int port = 80; String portS = "80"; String httpsPortS = "443"; int httpsPort = 443; if (ndx > 0) { portS = host.substring(ndx + 1); httpsPortS = portS;//from w w w. j a v a 2 s . co m port = new Integer(portS).intValue(); httpsPort = new Integer(httpsPortS).intValue(); host = host.substring(0, ndx); } Jets3tProperties j3p = new Jets3tProperties(); j3p.setProperty("s3service.s3-endpoint-http-port", portS); j3p.setProperty("s3service.s3-endpoint-https-port", httpsPortS); j3p.setProperty("s3service.disable-dns-buckets", "true"); j3p.setProperty("s3service.s3-endpoint", host); j3p.setProperty("s3service.https-only", this.useHttps); j3p.setProperty("storage-service.internal-error-retry-max", "0"); j3p.setProperty("httpclient.socket-timeout-ms", "0"); HostConfiguration hc = new HostConfiguration(); if (allowSelfSigned && this.useHttps.equalsIgnoreCase("true")) { // magic needed for jets3t to work with self signed cert. try { Protocol easyhttps = new Protocol("https", new CumulusProtocolSocketFactory(), 443); Protocol.registerProtocol("https", easyhttps); hc.setHost(host, httpsPort, easyhttps); } catch (Exception ex) { throw new S3ServiceException("Could not make the self signed handler " + ex.toString(), ex); } } AWSCredentials awsCredentials = this.getAwsCredentail(); S3Service s3Service = new RestS3Service(awsCredentials, "cloud-client", null, j3p, hc); return s3Service; }
From source file:org.gss_project.gss.web.client.TestClient.java
public static void main(String[] args) { String user = "ebstest@grnet-hq.admin.grnet.gr"; String token = "PcxaZ/4oIqCqIvCYgsUcKr1hAFcsW40G3kcWJSRPJV5GjzoNuo8RsA=="; String host = "pithos.grnet.gr"; String restPath = "/pithos/rest"; String path = "/" + user + "/files/"; String now = DateUtil.formatDate(new Date()); String signature = sign("GET", now, path, token); HttpClient client = new HttpClient(); HostConfiguration hostconfig = new HostConfiguration(); hostconfig.setHost(host);/* w ww. j av a2 s . co m*/ HttpMethod method = new GetMethod(restPath + path); Collection<Header> headers = new ArrayList<Header>(); Header auth = new Header("Authorization", user + " " + signature); headers.add(auth); Header date = new Header("X-GSS-Date", now); headers.add(date); System.out.println(headers.toString()); hostconfig.getParams().setParameter("http.default-headers", headers); try { // Execute the method. int statusCode = client.executeMethod(hostconfig, method); if (statusCode != HttpStatus.SC_OK) System.err.println("Method failed: " + method.getStatusLine()); // Read the response body. byte[] responseBody = method.getResponseBody(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data System.out.println(new String(responseBody)); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }
From source file:org.hydracache.client.transport.HttpTransport.java
@Override public Transport establishConnection(String hostName, int port) { HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(hostName, port); this.httpClient.setHostConfiguration(hostConfiguration); return this; }
From source file:org.intalio.tempo.workflow.tas.nuxeo.NuxeoStorageStrategy.java
/** * Everything we need to do to have an authenticated http client * /*from w w w. jav a2 s. c om*/ * @throws URIException */ private void initHttpClient() throws URIException { httpclient = new HttpClient(); HostConfiguration hostConfig = new HostConfiguration(); org.apache.commons.httpclient.URI uri = new org.apache.commons.httpclient.URI(getNuxeoRestUrl(), false); hostConfig.setHost(uri); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); int maxHostConnections = 20; params.setMaxConnectionsPerHost(hostConfig, maxHostConnections); connectionManager.setParams(params); httpclient = new HttpClient(connectionManager); httpclient.setHostConfiguration(hostConfig); Credentials creds = new UsernamePasswordCredentials(userName, password); AuthScope authScope = new AuthScope(hostConfig.getHost(), hostConfig.getPort()); httpclient.getState().setCredentials(authScope, creds); httpclient.getParams().setAuthenticationPreemptive(true); }
From source file:org.intalio.tempo.workflow.tas.sling.SlingStorageStrategy.java
public void init() throws HttpException, IOException { HostConfiguration hostConfig = new HostConfiguration(); // hostConfig.setHost("www.somehost.com"); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); int maxHostConnections = 20; params.setMaxConnectionsPerHost(hostConfig, maxHostConnections); connectionManager.setParams(params); httpclient = new HttpClient(connectionManager); Credentials creds = new UsernamePasswordCredentials(userName, password); httpclient.getState().setCredentials(AuthScope.ANY, creds); httpclient.setHostConfiguration(hostConfig); MkColMethod col = new MkColMethod(getUploadFolder()); int ret = httpclient.executeMethod(col); log.debug(MessageFormatter.format("Created folder {0} in sling: {1}", getUploadFolder(), ret)); }
From source file:org.jivesoftware.openfire.update.UpdateManager.java
/** * Queries the igniterealtime.org server for new server and plugin updates. * * @param notificationsEnabled true if admins will be notified when new updates are found. * @throws Exception if some error happens during the query. *///from w w w . j a v a 2s .c o m public synchronized void checkForServerUpdate(boolean notificationsEnabled) throws Exception { // Get the XML request to include in the HTTP request String requestXML = getServerUpdateRequest(); // Send the request to the server HttpClient httpClient = new HttpClient(); // Check if a proxy should be used if (isUsingProxy()) { HostConfiguration hc = new HostConfiguration(); hc.setProxy(getProxyHost(), getProxyPort()); httpClient.setHostConfiguration(hc); } PostMethod postMethod = new PostMethod(updateServiceURL); NameValuePair[] data = { new NameValuePair("type", "update"), new NameValuePair("query", requestXML) }; postMethod.setRequestBody(data); if (httpClient.executeMethod(postMethod) == 200) { // Process answer from the server String responseBody = postMethod.getResponseBodyAsString(); processServerUpdateResponse(responseBody, notificationsEnabled); } }
From source file:org.jivesoftware.openfire.update.UpdateManager.java
public synchronized void checkForPluginsUpdates(boolean notificationsEnabled) throws Exception { // Get the XML request to include in the HTTP request String requestXML = getAvailablePluginsUpdateRequest(); // Send the request to the server HttpClient httpClient = new HttpClient(); // Check if a proxy should be used if (isUsingProxy()) { HostConfiguration hc = new HostConfiguration(); hc.setProxy(getProxyHost(), getProxyPort()); httpClient.setHostConfiguration(hc); }/*from w w w . ja v a 2 s. c om*/ PostMethod postMethod = new PostMethod(updateServiceURL); NameValuePair[] data = { new NameValuePair("type", "available"), new NameValuePair("query", requestXML) }; postMethod.setRequestBody(data); if (httpClient.executeMethod(postMethod) == 200) { // Process answer from the server String responseBody = postMethod.getResponseBodyAsString(); processAvailablePluginsResponse(responseBody, notificationsEnabled); } }