wt.httpgw
Class HTTPResponseImpl

java.lang.Object
  extended bywt.httpgw.HTTPResponse
      extended bywt.httpgw.HTTPResponseImpl
All Implemented Interfaces:
CGIConstants, Externalizable, Runnable, Serializable

public class HTTPResponseImpl
extends HTTPResponse
implements Externalizable, Runnable, CGIConstants

This class is a carrier of HTTP response information back to an HTTP gateway from a method server. It uses customized serialization code to stream response bodies to the gateway.

Server-side Serialization The server (NetFactor method server) constructs response objects to carry response information back to the gateway. The object contains fields to store response header information, an output stream reference, and a target class and method.

Object serialization stores the RMI marshal stream reference in the object and invokes the target method using Java's reflection API. The target method uses methods on the response object to set response attributes (content-type, status, etc.) and eventually calls a method to retrieve the output stream on which to write the response body. This call causes the response attributes to be written to the marshal stream. When the target method returns, serialization is complete.

Client-side Deserialization The client (HTTP gateway) receives the response object as the return value of a RMI call. It is deserialized before the RMI call completes. In order to support processing of streamed data, the deserialization code looks up the corresponding HTTPGateway object and uses it to send the response directly from the deserialization code.

First the headers are set on the real gateway response, then the content body is forwarded by reading blocks of data from the input stream and writing them to real response output stream until the entire body has been sent.

  Note: Four response headers are set by default:
        Protocol is set to HTTP/1.0;
        Status is set to 200 (OK); and
        Content-Type is set to text/html.
        Expires is set to long ago, the Java epoch - date(0)

        If you need to set other headers or change these defaults,
        you must do so in your response processing PRIOR to calling
        getOutputStream.
 



Supported API: true
Extendable: false

See Also:
Serialized Form

Field Summary
private static int BUFSIZ
           
private  Integer gatewayId
           
private  HTTPResponseHeaders hdrs
           
private  boolean hdrsSent
           
private static String HOMEPAGE_CLASS
           
private static String HOMEPAGE_METHOD
           
private  InputStream inputStream
           
private  ObjectOutput objOut
          ObjectOutputStream to which Business Classes write responses.
private  String remoteHost
           
private static String RESOURCE
           
private  OutputStream responseStream
           
private  Object[] respTargetArgs
           
private  Method respTargetMethod
           
(package private) static long serialVersionUID
           
private  long startTime
           
private static boolean VERBOSE_CLIENT
           
private static boolean VERBOSE_SERVER
           
private static int WRITE_TIMEOUT
           
private  Thread writer
           
 
Fields inherited from class wt.httpgw.HTTPResponse
respException
 
Fields inherited from interface wt.httpgw.CGIConstants
CGI_ACCEPT, CGI_ACCEPT_CHARSET, CGI_ACCEPT_LANGUAGE, CGI_AUTH_TYPE, CGI_AUTHORIZATION, CGI_CONNECTION, CGI_CONTENT_LENGTH, CGI_CONTENT_TYPE, CGI_CONTEXT_PATH, CGI_DELETE_METHOD, CGI_GATEWAY_INTERFACE, CGI_GET_METHOD, CGI_HEAD_METHOD, CGI_HOST, CGI_IF_MODIFIED_SINCE, CGI_MULTIPART_BOUNDARY, CGI_PATH_INFO, CGI_PATH_TRANSLATED, CGI_POST_METHOD, CGI_PRAGMA, CGI_PROPERTY_PREFIX, CGI_PROTOCOL, CGI_PUT_METHOD, CGI_QUERY_STRING, CGI_REFERER, CGI_REMOTE_ADDR, CGI_REMOTE_HOST, CGI_REMOTE_IDENT, CGI_REMOTE_USER, CGI_REQUEST_METHOD, CGI_SCHEME, CGI_SCRIPT_NAME, CGI_SERVER_NAME, CGI_SERVER_PORT, CGI_SERVER_PROTOCOL, CGI_SERVER_SOFTWARE, CGI_SERVLET_SESSION, CGI_TRACE_METHOD, CGI_UA_COLOR, CGI_UA_CPU, CGI_UA_OS, CGI_UA_PIXELS, CGI_URI, CGI_URL, CGI_USER_AGENT, versionID
 
Constructor Summary
HTTPResponseImpl()
          Externalizable constructor used on receiving side.
HTTPResponseImpl(Integer gateway_id)
          Constructor used on sending side.
 
Method Summary
 boolean containsHeader(String s)
          Checks if the response header is present.
 Object get(String s)
          Gets the value of this response header key.
 OutputStream getOutputStream()
          Called to get the output stream to write the data to.
 Enumeration keys()
          Gets the response header keys.
private  void printException(Throwable t, boolean traceback)
           
 void readExternal(ObjectInput input_stream)
           
 void run()
          Run method for write timer thread

Supported API: false
 void setDateHeader(String s1, long date)
          Sets a date type response header.
 void setHeader(String s1, String s2)
          Sets a string type response header.
 void setIntHeader(String s1, int v1)
          Sets a int type response header.
 void setRemoteHost(String remote_host)
          Setter for the remote host that will be displayed in exception tracebacks.
 void setRespTarget(Method method, Object[] args)
          Setter for the target method that will generate the real response to the output stream.
 void setStatus(int v1)
          Sets a simple Status response header.
 void setStatus(int v1, String s1)
          Sets a Status response header.
 void writeExternal(ObjectOutput output_stream)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

VERBOSE_SERVER

private static boolean VERBOSE_SERVER

VERBOSE_CLIENT

private static boolean VERBOSE_CLIENT

WRITE_TIMEOUT

private static int WRITE_TIMEOUT

HOMEPAGE_CLASS

private static String HOMEPAGE_CLASS

HOMEPAGE_METHOD

private static String HOMEPAGE_METHOD

BUFSIZ

private static final int BUFSIZ
See Also:
Constant Field Values

gatewayId

private Integer gatewayId

hdrs

private HTTPResponseHeaders hdrs

hdrsSent

private transient boolean hdrsSent

respTargetArgs

private transient Object[] respTargetArgs

respTargetMethod

private transient Method respTargetMethod

remoteHost

private transient String remoteHost

objOut

private transient ObjectOutput objOut
ObjectOutputStream to which Business Classes write responses. This stream is only available when the business class is called during the serialization of the response object on the sending side.


responseStream

private transient OutputStream responseStream

startTime

private transient long startTime

writer

private transient Thread writer

inputStream

private transient InputStream inputStream
Constructor Detail

HTTPResponseImpl

public HTTPResponseImpl(Integer gateway_id)
Constructor used on sending side. Supported API: false


HTTPResponseImpl

public HTTPResponseImpl()
Externalizable constructor used on receiving side.

Method Detail

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Called to get the output stream to write the data to. It also causes the HTTPResponseHeaders object to be written out to the RMI marshal stream.

Supported API: true

Specified by:
getOutputStream in class HTTPResponse
Returns:
OutputStream for writing response body
Throws:
IOException - if not marshaling response in writeObject. the output stream is null until such time. Also, if the response target class or method is null. There is not a proper business class or method to write the response.

readExternal

public void readExternal(ObjectInput input_stream)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput output_stream)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

printException

private void printException(Throwable t,
                            boolean traceback)

run

public void run()
Run method for write timer thread

Supported API: false

Specified by:
run in interface Runnable

setRespTarget

public void setRespTarget(Method method,
                          Object[] args)
Setter for the target method that will generate the real response to the output stream.

Supported API: false

Specified by:
setRespTarget in class HTTPResponse
Parameters:
method - is the target business Method
args - are the object array of arguments needed my the target method.

setRemoteHost

public void setRemoteHost(String remote_host)
Setter for the remote host that will be displayed in exception tracebacks.

Supported API: false

Specified by:
setRemoteHost in class HTTPResponse

containsHeader

public boolean containsHeader(String s)
Checks if the response header is present.

Supported API: true

Specified by:
containsHeader in class HTTPResponse
Parameters:
s - String the header to search for.
Returns:
A boolean if the header is set.

keys

public Enumeration keys()
Gets the response header keys.

Supported API: false

Specified by:
keys in class HTTPResponse
Returns:
An Enumeration of the header keys.

get

public Object get(String s)
Gets the value of this response header key.

Supported API: false

Specified by:
get in class HTTPResponse
Parameters:
s - the key, as a string, to get the value of.
Returns:
the value of this key as an Object.

setHeader

public void setHeader(String s1,
                      String s2)
Sets a string type response header.

Supported API: true

Specified by:
setHeader in class HTTPResponse
Parameters:
s1 - String name of the header
s2 - String value to which header is set

setDateHeader

public void setDateHeader(String s1,
                          long date)
Sets a date type response header.

Supported API: true

Specified by:
setDateHeader in class HTTPResponse
Parameters:
s1 - String name of the header
date - long value to which header is set value is milliseconds since the epoch.

setIntHeader

public void setIntHeader(String s1,
                         int v1)
Sets a int type response header.

Supported API: true

Specified by:
setIntHeader in class HTTPResponse
Parameters:
s1 - String name of the header
v1 - int value to which header is set

setStatus

public void setStatus(int v1)
Sets a simple Status response header.

Supported API: true

Specified by:
setStatus in class HTTPResponse
Parameters:
v1 - Integer Status code

setStatus

public void setStatus(int v1,
                      String s1)
Sets a Status response header.

Supported API: true

Specified by:
setStatus in class HTTPResponse
Parameters:
v1 - Integer Status code
s1 - String Status reason code