/** * Constructor for ProxyHost. * * @param hostname the hostname (IP or DNS name). Can be <code>null</code>. * @param port the port. Value <code>-1</code> can be used to set default protocol port */ public ProxyHost(final String hostname, int port) { super(hostname, port, Protocol.getProtocol("http")); }
/** * Constructor for HttpHost. * * @param hostname the hostname (IP or DNS name). Can be <code>null</code>. */ public HttpHost(final String hostname) { this(hostname, -1, Protocol.getProtocol("http")); }
/** * Creates a new HTTP connection for the given host and port. * * @param host the host to connect to * @param port the port to connect to */ public HttpConnection(String host, int port) { this(null, -1, host, null, port, Protocol.getProtocol("http")); }
/** * Constructor for HttpHost. * * @param hostname the hostname (IP or DNS name). Can be <code>null</code>. * @param port the port. Value <code>-1</code> can be used to set default protocol port */ public HttpHost(final String hostname, int port) { this(hostname, port, Protocol.getProtocol("http")); }
/** * Creates a new HTTP connection for the given host and port via the * given proxy host and port using the default protocol. * * @param proxyHost the host to proxy via * @param proxyPort the port to proxy via * @param host the host to connect to * @param port the port to connect to */ public HttpConnection( String proxyHost, int proxyPort, String host, int port) { this(proxyHost, proxyPort, host, null, port, Protocol.getProtocol("http")); }
/** * Sets the given host, port and protocol * * @param host the host(IP or DNS name) * @param port The port * @param protocol The protocol. */ public synchronized void setHost(final String host, int port, final String protocol) { this.host = new HttpHost(host, port, Protocol.getProtocol(protocol)); }
/** * Sets the given host and port. Uses the default protocol "http". * * @param host the host(IP or DNS name) * @param port The port */ public synchronized void setHost(final String host, int port) { setHost(host, port, Protocol.getProtocol("http")); }
protected Protocol keepProtocol(String host, int port, String scheme) { final Protocol oldProtocol = getProtocol(); if (oldProtocol != null) { final String oldScheme = oldProtocol.getScheme(); if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) { return oldProtocol; } } return Protocol.getProtocol(scheme); } }
/** * Set the given host. Uses the default protocol("http") and its port. * * @param host The host(IP or DNS name). */ public synchronized void setHost(final String host) { Protocol defaultProtocol = Protocol.getProtocol("http"); setHost(host, defaultProtocol.getDefaultPort(), defaultProtocol); }
/** * URI constructor for HttpHost. * * @param uri the URI. */ public HttpHost(final URI uri) throws URIException { this(uri.getHost(), uri.getPort(), Protocol.getProtocol(uri.getScheme())); }
@Before public void setup() { original = Protocol.getProtocol("https"); }
static void replaceProtocol(ProtocolSocketFactory socketFactory, String schema, int defaultPort) { // // switch protocol // due to how HttpCommons work internally this dance is best to be kept as is // Protocol directHttp = Protocol.getProtocol(schema); if (directHttp instanceof DelegatedProtocol) { // unwrap the original directHttp = ((DelegatedProtocol)directHttp).getOriginal(); assert directHttp instanceof DelegatedProtocol == false; } Protocol proxiedHttp = new DelegatedProtocol(socketFactory, directHttp, schema, defaultPort); // NB: register the new protocol since when using absolute URIs, HttpClient#executeMethod will override the configuration (#387) // NB: hence why the original/direct http protocol is saved - as otherwise the connection is not closed since it is considered different // NB: (as the protocol identities don't match) // this is not really needed since it's being replaced later on // hostConfig.setHost(proxyHost, proxyPort, proxiedHttp); Protocol.registerProtocol(schema, proxiedHttp); // end dance }
Protocol defaultprotocol = Protocol.getProtocol("http"); socketFactory = defaultprotocol.getSocketFactory(); } else {
@Test public void testProtocolReplacement() throws Exception { final ProtocolSocketFactory socketFactory = getSocketFactory(); CommonsHttpTransport.replaceProtocol(socketFactory, "https", 443); Protocol protocol = Protocol.getProtocol("https"); assertThat(protocol, instanceOf(DelegatedProtocol.class)); DelegatedProtocol delegatedProtocol = (DelegatedProtocol) protocol; assertThat(delegatedProtocol.getSocketFactory(), sameInstance(socketFactory)); assertThat(delegatedProtocol.getOriginal(), sameInstance(original)); // ensure we do not re-wrap a delegated protocol CommonsHttpTransport.replaceProtocol(socketFactory, "https", 443); protocol = Protocol.getProtocol("https"); assertThat(protocol, instanceOf(DelegatedProtocol.class)); delegatedProtocol = (DelegatedProtocol) protocol; assertThat(delegatedProtocol.getSocketFactory(), sameInstance(socketFactory)); assertThat(delegatedProtocol.getOriginal(), sameInstance(original)); }
/** * Constructor for ProxyHost. * * @param hostname the hostname (IP or DNS name). Can be <code>null</code>. * @param port the port. Value <code>-1</code> can be used to set default protocol port */ public ProxyHost(final String hostname, int port) { super(hostname, port, Protocol.getProtocol("http")); }
/** * Constructor for HttpHost. * * @param hostname the hostname (IP or DNS name). Can be <code>null</code>. */ public HttpHost(final String hostname) { this(hostname, -1, Protocol.getProtocol("http")); }
/** * Creates a new HTTP connection for the given host and port. * * @param host the host to connect to * @param port the port to connect to */ public HttpConnection(String host, int port) { this(null, -1, host, null, port, Protocol.getProtocol("http")); }
/** * Sets the given host and port. Uses the default protocol "http". * * @param host the host(IP or DNS name) * @param port The port */ public synchronized void setHost(final String host, int port) { setHost(host, port, Protocol.getProtocol("http")); }
/** * Sets the given host, port and protocol * * @param host the host(IP or DNS name) * @param port The port * @param protocol The protocol. */ public synchronized void setHost(final String host, int port, final String protocol) { this.host = new HttpHost(host, port, Protocol.getProtocol(protocol)); }
/** * URI constructor for HttpHost. * * @param uri the URI. */ public HttpHost(final URI uri) throws URIException { this(uri.getHost(), uri.getPort(), Protocol.getProtocol(uri.getScheme())); }