/** * 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; }
/** * 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 * @param protocol the protocol. Value <code>null</code> can be used to set default protocol */ public HttpHost(final String hostname, int port, final Protocol protocol) { super(); if (hostname == null) { throw new IllegalArgumentException("Host name may not be null"); } if (protocol == null) { throw new IllegalArgumentException("Protocol may not be null"); } this.hostname = hostname; this.protocol = protocol; if (port >= 0) { this.port = port; } else { this.port = this.protocol.getDefaultPort(); } }
/** * 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(); }
public String getPath() { if (this.targethost != null) { StringBuffer buffer = new StringBuffer(); buffer.append(this.targethost.getHost()); int port = this.targethost.getPort(); if (port == -1) { port = this.targethost.getProtocol().getDefaultPort(); } buffer.append(':'); buffer.append(port); return buffer.toString(); } else { return "/"; } }
/** * 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 true if the specified object equals this object. * @param obj The object to compare against. * @return true if the objects are equal. */ public boolean equals(Object obj) { if (obj instanceof Protocol) { Protocol p = (Protocol) obj; return ( defaultPort == p.getDefaultPort() && scheme.equalsIgnoreCase(p.getScheme()) && secure == p.isSecure() && socketFactory.equals(p.getSocketFactory())); } else { return false; } }
/** * Returns the URI of the HTTP method * * @return The URI * * @throws URIException If the URI cannot be created. * * @see org.apache.commons.httpclient.HttpMethod#getURI() */ public URI getURI() throws URIException { StringBuffer buffer = new StringBuffer(); if (this.httphost != null) { buffer.append(this.httphost.getProtocol().getScheme()); buffer.append("://"); buffer.append(this.httphost.getHostName()); int port = this.httphost.getPort(); if (port != -1 && port != this.httphost.getProtocol().getDefaultPort()) { buffer.append(":"); buffer.append(port); } } buffer.append(this.path); if (this.queryString != null) { buffer.append('?'); buffer.append(this.queryString); } String charset = getParams().getUriCharset(); return new URI(buffer.toString(), true, charset); }
buf.append(connection.getHost()); if ((connection.getPort() != -1) && (connection.getPort() != protocol.getDefaultPort()) ) { buf.append(":");
if (conn.getProtocol().getDefaultPort() != port) { host += (":" + port);
int port = conn.getPort(); if (port == -1) { port = conn.getProtocol().getDefaultPort();
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
String scheme = "https"; Protocol baseHttps = Protocol.getProtocol(scheme); int defaultPort = baseHttps.getDefaultPort(); ProtocolSocketFactory baseFactory = baseHttps.getSocketFactory(); ProtocolSocketFactory customFactory = new CustomHttpsSocketFactory(baseFactory); Protocol customHttps = new Protocol(scheme, customFactory, defaultPort); Protocol.registerProtocol(scheme, customHttps);
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
private Protocol cloneProtocolKeepingSocketFactory(Protocol protocol) { Protocol original = getProtocol(); if (protocol.getScheme().equals(original.getScheme())) { // the protocol is the same, create a copy of it but keep the original socket factory return new Protocol(protocol.getScheme(), original.getSocketFactory(), protocol.getDefaultPort()); } return protocol; }