NextApp Echo
App Container 1.0.5

nextapp.echoservlet
Class Connection

java.lang.Object
  extended bynextapp.echoservlet.Connection

public final class Connection
extends java.lang.Object

A wrapper that holds information about an HTTP request, provides facilities to generate a response, and provides access to the application instance that is to process it.


Field Summary
private static java.lang.String CACHE_MAX_AGE
          A convenience for setting the cache header
private  boolean debugInteractiveController
          A flag that indicates whether the interactivecontroller frame should be made visible and provide debugging information.
private  boolean debugOptionsEnabled
          A flag that indicates whether any debug options may be enabled.
private  boolean debugPerformanceLogging
          A flag that indicates whether the time interval during which each request is processed will be recorded.
private  boolean debugVerboseLogging
          A flag indicating verbose logging.
private static java.lang.String INSTANCE_PEER_SESSION_KEY_PREFIX
          The prefix that will be used to determine the key name under which the application will be stored in HttpSession.
private  InstancePeer instancePeer
          Reference to the application's InstancePeer, may be null under initialization conditions.
private  java.lang.String instancePeerSessionKey
          The session key with holds the instance peer as its value.
private static long lastFreeMemory
          The amount of free memory available.
private  javax.servlet.http.HttpServletRequest request
          Reference to the HTTP request object wrapped by this Connection.
private  javax.servlet.http.HttpServletResponse response
          Reference to the HTTP response object wrapped by this Connection.
private  EchoServer server
          Reference to the EchoServer.
private static int serviceNumber
          A global counter of services invoked for the life of the VM.
private  ServletEncodingAdapter servletEncodingAdapter
          Reference to servlet encoding adapter.
private  VariableData variableData
          Holds the VariableData object associated with this Connection.
 
Constructor Summary
(package private) Connection(EchoServer server, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Creates a connection object that will handle the given request and response.
 
Method Summary
 java.lang.String correctUri(java.lang.String uri)
          Corrects relative-path URIs to include the application name, such that they can properly retrieve the desired resource.
 java.lang.String getApplicationUri()
          Returns the URI of the application.
 java.lang.String getCacheIdPrefix()
          Returns a prefix to prepend to cache ids in order to ensure that incorrect cached resources are used by client in the event either the server or the users session has restarted.
 Id getIdParameter(java.lang.String name)
          Returns the specified request parameter as an Id value.
 InstancePeer getInstancePeer()
          Returns the InstancePeer associated with this connection.
 java.io.OutputStream getOutputStream()
          Returns the OutputStream object that may be used to generate a response.
 java.lang.String getParameter(java.lang.String name)
          Returns the value of the HTTP parameter associated with the given name.
 java.util.Enumeration getParameterNames()
          Returns an enumeration of all parameter names passed in the request.
 javax.servlet.http.HttpServletRequest getRequest()
          Returns the HttpServletRequest wrapped by this Connection.
 javax.servlet.http.HttpServletResponse getResponse()
          Returns the HttpServletResponse wrapped by this Connection.
 EchoServer getServer()
          Returns the EchoServer wrapped by this Connection.
 VariableData getVariableData()
          Returns the VariableData associated with this Connection.
 java.io.PrintWriter getWriter()
          Returns the PrintWriter object that may be used to generate a response.
(package private)  boolean isDebugInteractiveControllerEnabled()
          Returns true if the interactive controller debug feature is enabled.
(package private)  boolean isDebugVerboseLoggingEnabled()
          Returns true if the verbose logging debug feature is enabled.
(package private)  void process()
          Retrieves and executes the appropriate Service requested by the client browser.
private  Service retrieveService(Id id)
          Returns the service that corresponds to the specified Id.
 void setContentType(ContentType contentType)
          Sets the content type of the response.
(package private)  void setInstancePeer(InstancePeer instancePeer)
          Sets the InstancePeer that has been created for the user making this request.
(package private)  void unbindInstancePeer()
          Unbinds the application's InstancePeer from the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE_PEER_SESSION_KEY_PREFIX

private static final java.lang.String INSTANCE_PEER_SESSION_KEY_PREFIX
The prefix that will be used to determine the key name under which the application will be stored in HttpSession. The application's URI will be appended to the session prefix to form a unique value.

See Also:
Constant Field Values

CACHE_MAX_AGE

private static final java.lang.String CACHE_MAX_AGE
A convenience for setting the cache header

See Also:
Constant Field Values

lastFreeMemory

private static long lastFreeMemory
The amount of free memory available. Used for performance testing purposes.


serviceNumber

private static int serviceNumber
A global counter of services invoked for the life of the VM. Useful only for debugging purposes.


request

private javax.servlet.http.HttpServletRequest request
Reference to the HTTP request object wrapped by this Connection.


response

private javax.servlet.http.HttpServletResponse response
Reference to the HTTP response object wrapped by this Connection.


instancePeer

private InstancePeer instancePeer
Reference to the application's InstancePeer, may be null under initialization conditions.


server

private EchoServer server
Reference to the EchoServer.


servletEncodingAdapter

private ServletEncodingAdapter servletEncodingAdapter
Reference to servlet encoding adapter.


variableData

private VariableData variableData
Holds the VariableData object associated with this Connection.


instancePeerSessionKey

private java.lang.String instancePeerSessionKey
The session key with holds the instance peer as its value.


debugOptionsEnabled

private boolean debugOptionsEnabled
A flag that indicates whether any debug options may be enabled. Debug options work only if this flag is set.


debugPerformanceLogging

private boolean debugPerformanceLogging
A flag that indicates whether the time interval during which each request is processed will be recorded. Note: the logged time is not the time required to service a particular request, as multiple requests may be processed simultaneously.


debugInteractiveController

private boolean debugInteractiveController
A flag that indicates whether the interactivecontroller frame should be made visible and provide debugging information.


debugVerboseLogging

private boolean debugVerboseLogging
A flag indicating verbose logging. Enable to see a great deal of debugging information.

Constructor Detail

Connection

Connection(EchoServer server,
           javax.servlet.http.HttpServletRequest request,
           javax.servlet.http.HttpServletResponse response)
     throws java.io.IOException,
            javax.servlet.ServletException
Creates a connection object that will handle the given request and response. The InstancePeer will be pulled from the session if one exists. A session will NOT be created if one does not exist.

Parameters:
server - The EchoServer generating the connection.
request - The HTTP request object that was passed to the servlet.
response - The HTTP response object that was passed to the servlet.
Method Detail

getApplicationUri

public java.lang.String getApplicationUri()
Returns the URI of the application.

Returns:
The URI of the application.

getCacheIdPrefix

public java.lang.String getCacheIdPrefix()
Returns a prefix to prepend to cache ids in order to ensure that incorrect cached resources are used by client in the event either the server or the users session has restarted. Returns an empty string if no InstancePeer has been created, otherwise defers responsibility to the InstancePeer.

Returns:
A prefix to prepend to cache ids to make them unique across server and session restarts.

getIdParameter

public Id getIdParameter(java.lang.String name)
Returns the specified request parameter as an Id value. If the parameter is was not provided in the request, or if the parameter is not a valid Id value, null is returned.

Parameters:
name - The parameter name.
Returns:
The parameter as an Id.

getInstancePeer

public InstancePeer getInstancePeer()
Returns the InstancePeer associated with this connection. If the session has not been initialized, null is returned.

Returns:
The InstancePeer associated with this connection.

getOutputStream

public java.io.OutputStream getOutputStream()
Returns the OutputStream object that may be used to generate a response. This method may be called once. If it is called, the getWriter() method may not be called. This method wraps a call to HttpServletResponse.getOutputStream(). The OutputStream will be closed by the servlet container.

Returns:
the OutputStream object that may be used to generate a response to the client.

getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the value of the HTTP parameter associated with the given name.

Parameters:
name - The name of the parameter to return.
Returns:
The value of the HTTP parameter associated with the given name.

getParameterNames

public java.util.Enumeration getParameterNames()
Returns an enumeration of all parameter names passed in the request.

Returns:
An enumeration of all parameter names passed in the request.

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Returns the HttpServletRequest wrapped by this Connection.

Returns:
The HttpServletRequest wrapped by this Connection.

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Returns the HttpServletResponse wrapped by this Connection.

Returns:
The HttpServletResponse wrapped by this Connection.

getServer

public EchoServer getServer()
Returns the EchoServer wrapped by this Connection.

Returns:
The EchoServer wrapped by this Connection.

getVariableData

public VariableData getVariableData()
Returns the VariableData associated with this Connection. If an InstancePeer exists, its VariableData is returned, otherwise, a temporary VariableData object is returned that contains defaults used for initialization.

Returns:
The VariableData object associated with this Connection.

getWriter

public java.io.PrintWriter getWriter()
Returns the PrintWriter object that may be used to generate a response. This method may be called once. If it is called, the getOuputStream() method may not be called. This method wraps a call to HttpServletResponse.getWriter(). The PrintWriter will be closed by the servlet container.

Returns:
the PrintWriter object that may be used to generate a response to the client.

correctUri

public java.lang.String correctUri(java.lang.String uri)
Corrects relative-path URIs to include the application name, such that they can properly retrieve the desired resource.

Parameters:
uri - The URI to correct.
Returns:
The corrected URI.

isDebugInteractiveControllerEnabled

boolean isDebugInteractiveControllerEnabled()
Returns true if the interactive controller debug feature is enabled.

Returns:
True if the interactive controller debug feature is enabled.

isDebugVerboseLoggingEnabled

boolean isDebugVerboseLoggingEnabled()
Returns true if the verbose logging debug feature is enabled.

Returns:
True if the verbose logging debug feature is enabled.

process

void process()
       throws java.io.IOException
Retrieves and executes the appropriate Service requested by the client browser. Sets cache control HTTP headers for the response. If the user does not yet have an InstancePeer, then initialization services are executed. Logs debugging information if necessary.

Throws:
java.io.IOException

retrieveService

private Service retrieveService(Id id)
Returns the service that corresponds to the specified Id.

Parameters:
id - The id of the service to return.
Returns:
The service corresponding to the specified Id.

setContentType

public void setContentType(ContentType contentType)
Sets the content type of the response. This method will automatically append a character encoding to non-binary content types.

Parameters:
contentType - The content type of the response.

setInstancePeer

void setInstancePeer(InstancePeer instancePeer)
Sets the InstancePeer that has been created for the user making this request. This method is called once, by the Initializer.

Parameters:
instancePeer - The InstancePeer that will be used by this user.

unbindInstancePeer

void unbindInstancePeer()
Unbinds the application's InstancePeer from the session. This terminates the application. If the user visits the application's URI again, a new InstancePeer will be created.


NextApp Echo
App Container 1.0.5