List of usage examples for org.apache.commons.httpclient HttpConnection getHost
public String getHost()
From source file:com.exalead.io.failover.MonitoredHttpConnectionManager.java
/** * Gets the host configuration for a connection. * @param conn the connection to get the configuration of * @return a new HostConfiguration/* w w w . java 2 s. c om*/ */ static HostConfiguration rebuildConfigurationFromConnection(HttpConnection conn) { HostConfiguration connectionConfiguration = new HostConfiguration(); connectionConfiguration.setHost(conn.getHost(), conn.getPort(), conn.getProtocol()); if (conn.getLocalAddress() != null) { connectionConfiguration.setLocalAddress(conn.getLocalAddress()); } if (conn.getProxyHost() != null) { connectionConfiguration.setProxy(conn.getProxyHost(), conn.getProxyPort()); } return connectionConfiguration; }
From source file:edu.utah.further.core.ws.HttpResponseTo.java
/** * Generates HTTP request line according to the specified attributes. * // ww w .ja va2 s . com * @param connection * the {@link HttpConnection connection} used to execute this HTTP method * @param name * the method name generate a request for * @param requestPath * the path string for the request * @param query * the query string for the request * @param version * the protocol version to use (e.g. HTTP/1.0) * * @return HTTP request line */ protected static String generateRequestLine(final HttpConnection connection, final String name, final String requestPath, final String query, final String version) { final StringBuffer buf = new StringBuffer(); // Append method name buf.append(name).append(Strings.SPACE_STRING); // Absolute or relative URL? if (!connection.isTransparent()) { final Protocol protocol = connection.getProtocol(); buf.append(protocol.getScheme().toLowerCase()); buf.append("://"); buf.append(connection.getHost()); if ((connection.getPort() != -1) && (connection.getPort() != protocol.getDefaultPort())) { buf.append(":"); buf.append(connection.getPort()); } } // Append path, if any if (requestPath == null) { buf.append("/"); } else { if (!connection.isTransparent() && !requestPath.startsWith("/")) { buf.append("/"); } buf.append(requestPath); } // Append query, if any if (query != null) { if (query.indexOf("?") != 0) { buf.append("?"); } buf.append(query); } // Append protocol buf.append(Strings.SPACE_STRING).append(version).append(Strings.UNIX_NEW_LINE_STRING); return buf.toString(); }
From source file:com.exalead.io.failover.HttpConnectionAdapter.java
/** * Creates a new HttpConnectionAdapter./*w w w .j a v a2 s. c o m*/ * @param connection the connection to be wrapped */ public HttpConnectionAdapter(HttpConnection connection) { super(connection.getHost(), connection.getPort(), connection.getProtocol()); this.wrappedConnection = connection; }
From source file:com.navercorp.pinpoint.plugin.httpclient3.interceptor.HttpMethodBaseExecuteMethodInterceptor.java
private String getHost(HttpMethod httpMethod, HttpConnection httpConnection) { try {// www .j a v a 2s . c o m final URI uri = httpMethod.getURI(); // if uri have schema if (uri.isAbsoluteURI()) { return HttpClient3RequestWrapper.getEndpoint(uri.getHost(), uri.getPort()); } if (httpConnection != null) { final String host = httpConnection.getHost(); final int port = HttpClient3RequestWrapper.getPort(httpConnection); return HttpClient3RequestWrapper.getEndpoint(host, port); } } catch (Exception e) { if (isDebug) { logger.debug("Failed to get host. httpMethod={}", httpMethod, e); } } return null; }
From source file:org.apache.webdav.lib.methods.MoveMethod.java
/** * A client of the {@link MoveMethod} can specify a destination as either an * absolute URL (possibly to a different server), or as a absolute path on * the same server, but this function makes sure that the path sent to the * server is always an absolute URL./* www. java 2s. c o m*/ * * <p>Note that this function will add server and port to the request - * however, port is not added if it is the default port for the scheme * in question. </p> * * <p>This function is static so that it can be reused by the {@link CopyMethod}. * </p> * * @param conn The connection for the current request, in case the caller * specifies an absolute path. * * @param absolutePathOrURL If an absolute URL, nothing done, but if an absolute * path, it is converted into an absolute URL. * * @return An absolute URL */ static String getAbsoluteDestination(HttpConnection conn, String absolutePathOrURL) { String absoluteDestination = absolutePathOrURL; // is this an absolute path? if (absolutePathOrURL.startsWith("/")) { // yes - get the protocol to start the URL with the appropriate scheme. Protocol protocol = conn.getProtocol(); StringBuffer bufDest = new StringBuffer(protocol.getScheme()); bufDest.append("://").append(conn.getHost()); // only add in the port if it is not the default port. if (conn.getPort() != protocol.getDefaultPort()) { bufDest.append(':').append(conn.getPort()); } // append the path. bufDest.append(absolutePathOrURL); absoluteDestination = bufDest.toString(); } return absoluteDestination; }
From source file:org.bibsonomy.recommender.tags.database.IdleClosingConnectionManager.java
@Override public void releaseConnection(HttpConnection conn) { log.debug("Freeing connection to " + conn.getHost()); super.releaseConnection(conn); log.debug("Closing connection to " + conn.getHost()); conn.close();/*ww w . j ava 2 s . c o m*/ deleteClosedConnections(); }