FileDocCategorySizeDatePackage
HttpConnectorAddress.javaAPI DocGlassfish v2 API8197Fri May 04 22:33:16 BST 2007com.sun.enterprise.admin.comm

HttpConnectorAddress

public final class HttpConnectorAddress extends Object implements GenericHttpConnectorAddress
This class abstracts the details of URLS from a client. allowing the client to set the host, port, security property and authorization informaiton. This information is then used to create an URLConnection which will only connect to the admin servlet using basic authorization (if authorization information is given).

Fields Summary
private static final String
HTTP_CONNECTOR
private static final String
HTTPS_CONNECTOR
private static final String
AUTHORIZATION_KEY
private static final String
AUTHORIZATION_TYPE
private String
host
private int
port
private AuthenticationInfo
authInfo
private boolean
secure
Constructors Summary
public HttpConnectorAddress()


    
  
public HttpConnectorAddress(com.sun.enterprise.admin.util.HostAndPort h)

	this(h.getHost(), h.getPort(), h.isSecure());
  
public HttpConnectorAddress(String host, int port)

	this(host, port, false);
  
public HttpConnectorAddress(String host, int port, boolean secure)
construct an address which indicates the host, port and security attributes desired.

param
host a host address
param
port a port number
secure
an indication of whether the connection should be secure (i.e. confidential) or not

	this.host = host;
	this.port = port;
	this.secure = secure;
  
Methods Summary
private final java.lang.StringasURLSpec(java.lang.String path)
Return a string which can be used as the specification to form an URL.

return
a string which can be used as the specification to form an URL. This string is in the form of >protocol>://>host>:>port>/ with the appropriate substitutions

	return this.getConnectorType()
	+"://"+this.getAuthority()
	+(path != null? path : "");
  
  
public AuthenticationInfogetAuthenticationInfo()

	return authInfo;
  
private final java.lang.StringgetAuthority()
Return the authority portion of the URL spec

	return this.getHost() + ":" + this.getPort();
  
private static final java.lang.StringgetBase64Encoded(java.lang.String clearString)

	return new BASE64Encoder().encode(clearString.getBytes());
  
private final java.lang.StringgetBasicAuthString()

	return AUTHORIZATION_TYPE+ this.getBase64Encoded(this.getUser() + ":" + this.getPassword());
  
public java.lang.StringgetConnectorType()
get the protocol prefix to be used for a connection for the receiver

return
the protocol prefix - one of http or https depending upon the security setting.

	return this.isSecure() ? HTTPS_CONNECTOR : HTTP_CONNECTOR;
  
public java.lang.StringgetHost()

	return host;
  
private final java.lang.StringgetPassword()

	return authInfo != null ? authInfo.getPassword() : "";
  
public intgetPort()

	return port;
  
private final java.lang.StringgetUser()

	return authInfo != null ? authInfo.getUser() : "";
  
public booleanisSecure()
Indicate if the reciever represents a secure address

	return secure;
  
private final java.net.URLConnectionmakeConnection(java.net.URL url)

	URLConnection uc = url.openConnection();
	if (uc instanceof HttpsURLConnection){
	  setHostnameVerifier((HttpsURLConnection) uc);
	}
	return uc;
  
private final java.net.URLConnectionopenConnection(java.net.URL url)

	return this.setOptions(this.makeConnection(url));
  
public java.net.URLConnectionopenConnection(java.lang.String path)
Open a connection using the reciever and the given path

param
path the path to the required resource (path here is the portion after the hostname:port portion of a URL)
returns
a connection to the required resource. The connection returned may be a sub-class of URLConnection including HttpsURLConnection. If the sub-class is a HttpsURLConnection then this connection will accept any certificate from any server where the server's name matches the host name of this object. Specifically we allows the certificate not to contain the name of the server. This is a potential security hole, but is also a usability enhancement.
throws
IOException if there's a problem in connecting to the resource

	return this.openConnection(this.toURL(path));
  
private final java.net.URLConnectionsetAuthentication(java.net.URLConnection uc)

	if (authInfo != null) {
	  uc.setRequestProperty(AUTHORIZATION_KEY, this.getBasicAuthString());
	}
	return uc;
  
public voidsetAuthenticationInfo(AuthenticationInfo authInfo)

	this.authInfo = authInfo;
  
public voidsetHost(java.lang.String host)

	this.host = host;
  
private final java.net.URLConnectionsetHostnameVerifier(javax.net.ssl.HttpsURLConnection uc)
Set the hostname verifier on the given connection so that a peer which appears to be the one we want to connect to is accepted.

param
uc the non-null URL connection whose hostname verifier may be set.
returns
the URLConnection argument

	uc.setHostnameVerifier(
	  new HostnameVerifier() {
		private final String expected = host;
		public boolean verify(String h, SSLSession s){
		  return expected.equals(h);
		}
	  }
	  );
	return uc;
  
private final java.net.URLConnectionsetOptions(java.net.URLConnection uc)

	uc.setDoOutput(true);
	uc.setUseCaches(false);
	uc.setRequestProperty("Content-type", "application/octet-stream");
	return this.setAuthentication(uc);
  
public voidsetPort(int port)

	this.port = port;
  
public voidsetSecure(boolean secure)
Set the security attibute

	this.secure = secure;
  
private final java.net.URLtoURL(java.lang.String path)

	return new URL(this.asURLSpec(path));