List of usage examples for org.apache.commons.httpclient HostConfiguration getHost
public String getHost()
From source file:BasicAuthenticationForJSPPage.java
public static void main(String args[]) throws Exception { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "My Browser"); HostConfiguration host = client.getHostConfiguration(); host.setHost(new URI("http://localhost:8080", true)); Credentials credentials = new UsernamePasswordCredentials("tomcat", "tomcat"); AuthScope authScope = new AuthScope(host.getHost(), host.getPort()); HttpState state = client.getState(); state.setCredentials(authScope, credentials); GetMethod method = new GetMethod("/commons/chapter01/protected.jsp"); try {//from w w w . j a va 2 s. c o m client.executeMethod(host, method); System.err.println(method.getStatusLine()); System.err.println(method.getResponseBodyAsString()); } catch (Exception e) { System.err.println(e); } finally { method.releaseConnection(); } }
From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java
public static void logCurrentHttpConnection(HttpClient httpClient, HostConfiguration hostConfiguration, HttpPool poolMode) {/* ww w .j a v a2 s.c o m*/ if (Engine.logEngine.isInfoEnabled() && httpClient != null) { if (poolMode == HttpPool.no) { Engine.logEngine .info("(HttpUtils) Use a not pooled HTTP connection for " + hostConfiguration.getHost()); } else { HttpConnectionManager httpConnectionManager = httpClient.getHttpConnectionManager(); if (httpConnectionManager != null && httpConnectionManager instanceof MultiThreadedHttpConnectionManager) { MultiThreadedHttpConnectionManager mtHttpConnectionManager = (MultiThreadedHttpConnectionManager) httpConnectionManager; int connections = mtHttpConnectionManager.getConnectionsInPool(); int connectionsForHost = mtHttpConnectionManager.getConnectionsInPool(hostConfiguration); Engine.logEngine.info("(HttpUtils) Use a " + poolMode.name() + " pool with " + connections + " HTTP connections, " + connectionsForHost + " for " + hostConfiguration.getHost() + "; Getting one ... [for instance " + httpClient.hashCode() + "]"); } } } }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
/** * rewrite request method//from www . jav a 2s . c o m * @param method * @return * @throws MalformedURLException */ private static HttpMethod rewrite(HttpMethod method) throws MalformedURLException { org.apache.commons.httpclient.Header location = method.getResponseHeader("location"); if (location == null) return method; HostConfiguration config = method.getHostConfiguration(); URL url; try { url = new URL(location.getValue()); } catch (MalformedURLException e) { url = new URL(config.getProtocol().getScheme(), config.getHost(), config.getPort(), mergePath(method.getPath(), location.getValue())); } method = clone(method, url); return method; }
From source file:lucee.commons.net.http.httpclient3.HTTPResponse3Impl.java
@Override public URL getURL() { HostConfiguration config = rsp.getHostConfiguration(); try {//from w ww . j a v a 2 s . c om String qs = rsp.getQueryString(); if (StringUtil.isEmpty(qs)) return new URL(config.getProtocol().getScheme(), config.getHost(), config.getPort(), rsp.getPath()); return new URL(config.getProtocol().getScheme(), config.getHost(), config.getPort(), rsp.getPath() + "?" + qs); } catch (MalformedURLException e) { } return url; }
From source file:com.legstar.http.client.CicsHttpTest.java
/** * Try to create a host configuration./*from w w w. j a v a2 s .c o m*/ */ public void testCreateHostConfiguration() { CicsHttp cicsHttp = new CicsHttp(getName(), getEndpoint()); HostConfiguration hostConfiguration = cicsHttp.createHostConfiguration(getEndpoint()); assertEquals("mainframe", hostConfiguration.getHost()); assertEquals("http://mainframe:3080", hostConfiguration.getHostURL()); assertEquals(3080, hostConfiguration.getPort()); assertEquals("http:80", hostConfiguration.getProtocol().toString()); }
From source file:ch.cyberduck.core.dav.DAVResource.java
/** * Overwritten to make sure the client and its properties are not overwritten when * the credentials change. See #2974.//from w ww .j a va 2s . c om * * @return true if the given httpURL is the client for this resource. */ @Override protected synchronized boolean isTheClient() throws URIException { final HostConfiguration hostConfig = client.getHostConfiguration(); // Hack to enable preemptive authentication client.getState().setCredentials(null, httpURL.getHost(), hostCredentials); return httpURL.getHost().equalsIgnoreCase(hostConfig.getHost()) && httpURL.getPort() == hostConfig.getProtocol().resolvePort(hostConfig.getPort()); }
From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java
private String safeHostString(HostConfiguration hostConfiguration) { if (hostConfiguration.getHost() != null) { return hostConfiguration.getHostURL(); }/*from ww w . ja va 2s .c o m*/ return ""; }
From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java
private void signWithOAuth(HttpMethod method) throws IOException { try {//from w w w .j a va 2 s .c o m HostConfiguration hostConfiguration = client.getHostConfiguration(); URI uri = method.getURI(); URI newUri = new URI((isSSLEnabled) ? "https" : "http", uri.getUserinfo(), hostConfiguration.getHost(), hostConfiguration.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); method.setURI(newUri); //URI checkUri = method.getURI(); //String checkUriString = checkUri.toString(); CommonsHttp3OAuthConsumer oAuthConsumer = new CommonsHttp3OAuthConsumer(consumerKey, consumerSecret); oAuthConsumer.setTokenWithSecret(consumerKey, consumerSecret); oAuthConsumer.sign(method); } catch (Exception e) { throw new IOException("Failed to OAuth sign HTTPRequest", e); } }
From source file:com.liferay.portal.util.HttpImpl.java
public HttpClient getClient(HostConfiguration hostConfiguration) { if (isProxyHost(hostConfiguration.getHost())) { return _proxyHttpClient; } else {//from w w w . j a v a 2 s.c o m return _httpClient; } }
From source file:com.cyberway.issue.httpclient.ThreadLocalHttpConnectionManager.java
/** * @see HttpConnectionManager#getConnectionWithTimeout(HostConfiguration, long) * /*from www . j ava2 s . c om*/ * @since 3.0 */ public HttpConnection getConnectionWithTimeout(final HostConfiguration hostConfiguration, final long timeout) { final ConnectionInfo ci = getConnectionInfo(); HttpConnection httpConnection = ci.conn; // make sure the host and proxy are correct for this connection // close it and set the values if they are not if (httpConnection == null || !finishLastResponse(httpConnection) || !hostConfiguration.hostEquals(httpConnection) || !hostConfiguration.proxyEquals(httpConnection)) { if (httpConnection != null && httpConnection.isOpen()) { closer.closeConnection(httpConnection); } httpConnection = new HttpConnection(hostConfiguration); httpConnection.setHttpConnectionManager(this); httpConnection.getParams().setDefaults(this.params); ci.conn = httpConnection; httpConnection.setHost(hostConfiguration.getHost()); httpConnection.setPort(hostConfiguration.getPort()); httpConnection.setProtocol(hostConfiguration.getProtocol()); httpConnection.setLocalAddress(hostConfiguration.getLocalAddress()); httpConnection.setProxyHost(hostConfiguration.getProxyHost()); httpConnection.setProxyPort(hostConfiguration.getProxyPort()); } // remove the connection from the timeout handler ci.idleStartTime = Long.MAX_VALUE; return httpConnection; }