public void doit() throws IOException { setSocket(socketfactory.createSocket(host, port, localAddress, localPort)); } };
/** * 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")); }
/** * Resolves the correct port for this protocol. Returns the given port if * valid or the default port otherwise. * * @param port the port to be resolved * * @return the given port or the defaultPort */ public int resolvePort(int port) { return port <= 0 ? getDefaultPort() : port; }
/** * Lazily registers the protocol with the given id. * * @param id the protocol ID * * @return the lazily registered protocol * * @throws IllegalStateException if the protocol with id is not recognized */ private static Protocol lazyRegisterProtocol(String id) throws IllegalStateException { if ("http".equals(id)) { final Protocol http = new Protocol("http", DefaultProtocolSocketFactory.getSocketFactory(), 80); Protocol.registerProtocol("http", http); return http; } if ("https".equals(id)) { final Protocol https = new Protocol("https", SSLProtocolSocketFactory.getSocketFactory(), 443); Protocol.registerProtocol("https", https); return https; } throw new IllegalStateException("unsupported protocol: '" + id + "'"); }
@After public void reset() { Protocol.registerProtocol("https", original); }
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); }
/** * Return the host uri. * * @return The host uri. */ public String toURI() { StringBuffer buffer = new StringBuffer(50); buffer.append(this.protocol.getScheme()); buffer.append("://"); buffer.append(this.hostname); if (this.port != this.protocol.getDefaultPort()) { buffer.append(':'); buffer.append(this.port); } return buffer.toString(); }
/** * Returns <tt>true</tt> if the connection is established over * a secure protocol. * * @return <tt>true</tt> if connected over a secure protocol. */ public boolean isSecure() { return protocolInUse.isSecure(); }
public boolean equals(Object obj) { return (obj instanceof DelegatedProtocol ? true : original.equals(obj)); }
/** Execute the logic in this object and keep track of any exceptions. */ public void run() { try { doit(); } catch (IOException e) { exception = e; } } }
public int hashCode() { return original.hashCode(); }
/** * 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")); }
/** * 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"); }