org.apache.commons.httpclient.HttpHost Java Examples
The following examples show how to use
org.apache.commons.httpclient.HttpHost.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientFactory.java From alfresco-core with GNU Lesser General Public License v3.0 | 6 votes |
/** Get a host for the given parameters. This method need not be thread-safe. */ public HttpHost getHost(String host, int port, String scheme) { if(scheme == null) { scheme = "http"; } Protocol protocol = protocols.get(scheme); if(protocol == null) { protocol = Protocol.getProtocol("http"); if(protocol == null) { throw new IllegalArgumentException("Unrecognised scheme parameter"); } } return new HttpHost(host, port, protocol); }
Example #2
Source File: SwiftRestClient.java From hadoop with Apache License 2.0 | 4 votes |
/** * Execute a method in a new HttpClient instance. * If the auth failed, authenticate then retry the method. * * @param method methot to exec * @param <M> Method type * @return the status code * @throws IOException on any failure */ private <M extends HttpMethod> int exec(M method) throws IOException { final HttpClient client = new HttpClient(); if (proxyHost != null) { client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, proxyPort)); } int statusCode = execWithDebugOutput(method, client); if ((statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_BAD_REQUEST) && method instanceof AuthPostMethod && !useKeystoneAuthentication) { if (LOG.isDebugEnabled()) { LOG.debug("Operation failed with status " + method.getStatusCode() + " attempting keystone auth"); } //if rackspace key authentication failed - try custom Keystone authentication useKeystoneAuthentication = true; final AuthPostMethod authentication = (AuthPostMethod) method; //replace rackspace auth with keystone one authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest)); statusCode = execWithDebugOutput(method, client); } if (statusCode == HttpStatus.SC_UNAUTHORIZED ) { //unauthed -or the auth uri rejected it. if (method instanceof AuthPostMethod) { //unauth response from the AUTH URI itself. throw new SwiftAuthenticationFailedException(authRequest.toString(), "auth", authUri, method); } //any other URL: try again if (LOG.isDebugEnabled()) { LOG.debug("Reauthenticating"); } //re-auth, this may recurse into the same dir authenticate(); if (LOG.isDebugEnabled()) { LOG.debug("Retrying original request"); } statusCode = execWithDebugOutput(method, client); } return statusCode; }
Example #3
Source File: SwiftRestClient.java From big-c with Apache License 2.0 | 4 votes |
/** * Execute a method in a new HttpClient instance. * If the auth failed, authenticate then retry the method. * * @param method methot to exec * @param <M> Method type * @return the status code * @throws IOException on any failure */ private <M extends HttpMethod> int exec(M method) throws IOException { final HttpClient client = new HttpClient(); if (proxyHost != null) { client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, proxyPort)); } int statusCode = execWithDebugOutput(method, client); if ((statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_BAD_REQUEST) && method instanceof AuthPostMethod && !useKeystoneAuthentication) { if (LOG.isDebugEnabled()) { LOG.debug("Operation failed with status " + method.getStatusCode() + " attempting keystone auth"); } //if rackspace key authentication failed - try custom Keystone authentication useKeystoneAuthentication = true; final AuthPostMethod authentication = (AuthPostMethod) method; //replace rackspace auth with keystone one authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest)); statusCode = execWithDebugOutput(method, client); } if (statusCode == HttpStatus.SC_UNAUTHORIZED ) { //unauthed -or the auth uri rejected it. if (method instanceof AuthPostMethod) { //unauth response from the AUTH URI itself. throw new SwiftAuthenticationFailedException(authRequest.toString(), "auth", authUri, method); } //any other URL: try again if (LOG.isDebugEnabled()) { LOG.debug("Reauthenticating"); } //re-auth, this may recurse into the same dir authenticate(); if (LOG.isDebugEnabled()) { LOG.debug("Retrying original request"); } statusCode = execWithDebugOutput(method, client); } return statusCode; }
Example #4
Source File: HostConfigurationWithStickyProtocol.java From http4e with Apache License 2.0 | 4 votes |
public synchronized void setHost(String host, int port, String scheme) { setHost(new HttpHost(host, port, getNewProtocol(host, port, scheme))); }
Example #5
Source File: HttpHostFactory.java From http4e with Apache License 2.0 | 4 votes |
/** Get a host for the given parameters. This method need not be thread-safe. */ public HttpHost getHost(HostConfiguration old, String scheme, String host, int port) { return new HttpHost(host, port, getProtocol(old, scheme, host, port)); }
Example #6
Source File: ProtocolAwareHostConfiguration.java From elasticsearch-hadoop with Apache License 2.0 | 4 votes |
public synchronized void setHost(String host, int port, String scheme) { setHost(new HttpHost(host, port, keepProtocol(host, port, scheme))); }
Example #7
Source File: SwiftRestClient.java From sahara-extra with Apache License 2.0 | 4 votes |
/** * Execute a method in a new HttpClient instance. * If the auth failed, authenticate then retry the method. * * @param method methot to exec * @param <M> Method type * @return the status code * @throws IOException on any failure */ private <M extends HttpMethod> int exec(M method) throws IOException { final HttpClient client = new HttpClient(); if (proxyHost != null) { client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, proxyPort)); } int statusCode = execWithDebugOutput(method, client); if ((statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_BAD_REQUEST) && method instanceof AuthPostMethod && !useKeystoneAuthentication) { if (LOG.isDebugEnabled()) { LOG.debug("Operation failed with status " + method.getStatusCode() + " attempting keystone auth"); } //if rackspace key authentication failed - try custom Keystone authentication useKeystoneAuthentication = true; final AuthPostMethod authentication = (AuthPostMethod) method; //replace rackspace auth with keystone one authentication.setRequestEntity(getAuthenticationRequst(keystoneAuthRequest)); statusCode = execWithDebugOutput(method, client); } if (statusCode == HttpStatus.SC_UNAUTHORIZED ) { //unauthed -or the auth uri rejected it. if (method instanceof AuthPostMethod) { //unauth response from the AUTH URI itself. throw new SwiftAuthenticationFailedException(authRequest.toString(), "auth", authUri, method); } //any other URL: try again if (LOG.isDebugEnabled()) { LOG.debug("Reauthenticating"); } //re-auth, this may recurse into the same dir setAuthToken(method, authenticate()); if (LOG.isDebugEnabled()) { LOG.debug("Retrying original request"); } statusCode = execWithDebugOutput(method, client); } return statusCode; }