FileDocCategorySizeDatePackage
HttpConnectorAddress.javaAPI DocGlassfish v2 API9671Fri May 04 22:36:22 BST 2007com.sun.enterprise.admin.jmx.remote.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).
author
Kedar Mhaswade, Toby Ferguson
since
S1AS7.0
version
1.0

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

/*, 
        DefaultConfiguration.LOGGER_RESOURCE_BUNDLE_NAME );*/
/* END -- S1WS_MOD */

    
  
public HttpConnectorAddress(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

/* BEGIN -- S1WS_MOD */
/*
	this.host = host;
	this.port = port;
	this.secure = secure;
*/
    this(host, port, secure, null);
/* END -- S1WS_MOD */
  
public HttpConnectorAddress(String host, int port, boolean secure, String path)

	this.host = host;
	this.port = port;
	this.secure = secure;
    this.path = path;
  
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()

  	/* taking care of the descripancies in the Base64Encoder, for very
	   large lengths of passwords and/or usernames.
	   Abhijit did the analysis and as per his suggestion, replacing
	   a newline in Base64 encoded String by newline followed by a space
	   should work for any length of password, independent of the
	   web server buffer length. That investigation is still on, but
	   in the meanwhile, it was found that the replacement of newline
	   character with empty string "" works. Hence implementing the same.
	   Date: 10/10/2003.
	*/
	String enc = this.getBase64Encoded(this.getUser() + ":" + this.getPassword());
	/*
	String f = "\n"; // System.getProperty("line.separator");
	String t = f + " " ;
	enc = enc.replaceAll(f, t);
	f = "\r\n";
	t = f + " ";
	enc = enc.replaceAll(f, t);
	*/
	enc = enc.replaceAll(System.getProperty("line.separator"), "");
	return ( AUTHORIZATION_TYPE + enc );
  
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 java.lang.StringgetPath()

    return path;
  
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)

	return ( url.openConnection() );
  
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

/* BEGIN -- S1WS_MOD */
    if (path == null || path.trim().length() == 0)
        path = this.path;
/* END -- S1WS_MOD */
	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.URLConnectionsetOptions(java.net.URLConnection uc)

	uc.setDoOutput(true);
	uc.setUseCaches(false);
	uc.setRequestProperty("Content-type", "application/octet-stream");
	uc.setRequestProperty("Connection", "Keep-Alive"); 
	return this.setAuthentication(uc);
  
public voidsetPath(java.lang.String path)

    this.path = path;
  
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));