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

ServletConnection

public class ServletConnection extends Object implements IConnection
Class communicating with Servlet over HTTP. Internally it uses java.net.URLConnection, for we may need to use it for both HTTP and HTTPS. In case of java.net.HttpURLConnection, only HTTP can be used.
author
Kedar Mhaswade
version
1.0

Fields Summary
static final String
UNKNOWN_HOST
static final String
INVALID_HOST_PORT
static final String
UNAUTHORIZED_ACCESS
private URLConnection
mConnection
private ObjectOutputStream
mObjectOutStream
private ObjectInputStream
mObjectInStream
Constructors Summary
ServletConnection(HttpConnectorAddress a)



      
	 try{
	   mConnection = a.openConnection("/"+AdminConstants.kAdminServletURI);
	 }
	 catch (IOException ioe){
	   handleException(ioe);
	 }
   
Methods Summary
public voidclose()

        try
        {
            mObjectInStream.close();
            mObjectOutStream.close();
        }
        catch(Exception e)
        {
            Debug.printStackTrace(e);
        }
    
private voidhandleException(java.io.IOException e)

        IOException exception = null;
        if (e instanceof java.net.UnknownHostException)
        {
            exception = new java.net.UnknownHostException(UNKNOWN_HOST + 
                                                          e.getMessage());
        }
        else if (e instanceof java.net.ConnectException)
        {
            exception = new java.net.ConnectException(INVALID_HOST_PORT);
        }
        else
        {
            int responseCode = 
                ((HttpURLConnection)mConnection).getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED)
            {
                exception = new IOException(UNAUTHORIZED_ACCESS);
            }
            else
            {
                exception = e;
            }
        }
        throw exception;
    
public java.lang.Objectreceive()
Read an incoming Object.

        Object value = null;
        try
        {
            mObjectInStream = new ObjectInputStream(
                new BufferedInputStream(mConnection.getInputStream()));
            value = mObjectInStream.readObject();
        }
        catch (IOException ioe)
        {
            handleException(ioe);
        }
        return value;
    
public voidsend(java.io.Serializable object)
Write an object to the connection

        try
        {
            mObjectOutStream = new ObjectOutputStream(
                                    new BufferedOutputStream(
                                        mConnection.getOutputStream()));
            mObjectOutStream.writeObject(object);
            mObjectOutStream.flush();
            mObjectOutStream.close();
        }
        catch (IOException ioe)
        {
            handleException(ioe);
        }