wt.httpgw
Class HTTPServer

java.lang.Object
  extended bywt.httpgw.HTTPServer
All Implemented Interfaces:
CGIConstants, RemoteAccess

public class HTTPServer
extends Object
implements CGIConstants, RemoteAccess

The HTTPServer class represents the server-side service interface for dispatching HTTP requests to their corresponding service methods. The HTTPGateway object forwards requests to this class, which in turn dispatches them to service methods identified in the URL path information.

This class understands the special serialization being performed by the request and response objects and hides this from the dispatched service methods. Its main method is processRequest. This method receives a HTTPRequest object as input and returns a HTTPResponse object. The URL path information is examined to determine the actual target class and method. The target method is overloaded with two versions, one for handling posted request body content from an input stream, and another for generating the response to an output stream. These operations must be separate because the posted input stream is only available while deserializing the request object, and the response output stream is only available while serializing the response object.

A new HTTPResponse object is constructed and the target class and method is stored in this object. Response generation is deferred until serialization of the response object is underway so that the RMI marshal stream is available as a pipe to receive the generated response body.

For HTTP POST requests, the input-processing version of the target method is invoked during request unmarshaling. If reflection cannot find the input-processing version of the target method and the content is URL encoded form data, the form data is parsed and stored on the request object. This form data can then be retrieved later during result writing using the getFromData method on the request object.

Application Developers View

Application developers expose functionality to HTTP clients by implementing methods that can be called by this HTTPServer class. These are simply methods with a specific signature that can be invoked using Java reflection. The only tricky part is that input stream processing and response generation are separated into two separate methods.

For example, if the Windchill HTTP gateway URL is

 http://www.wt.myco.com/servlet/windchill
 
Then the following URL could be used to invoke the myAction method of the MyHTTPService class:
 http://www.wt.myco.com/servlet/windchill/MyHTTPService/myAction
 
The MyHTTPService class would contain myAction methods with the following signatures:
 Class MyHTTPService
 {
    void myAction (HTTPRequest req, HTTPResponse resp, InputStream is)
    {
        // Handle posted data
        // Free to set response attributes,
        // but don't try to get the output stream
    }

    void myAction (HTTPRequest req, HTTPResponse resp)
    {
       // Set response attributes
       // Generate response body
       // Free to get the output stream and write directly
    }
 }
 
The first form of the method is optional, only being required if the request is a POST type, there is a content-body, and the content-body is expected to be something other than URL encoded form data.

Supported API: true
Extendable: false


Field Summary
private static boolean ACCESS_LOG_ENABLED
           
private static String ANONYMOUS_USER
           
private static String CONFIRM_AUTH_KEY
           
private static String HOMEPAGE_CLASS
           
private static String HOMEPAGE_METHOD
           
private static String HTTP_REQUEST_KEY
           
private static String POST_DATA_KEY
           
private static String QUERYSTR_KEY
           
private static String RESOURCE
           
private static boolean SHOW_TARGET
           
private static boolean VERBOSE
           
private static String WWW_AUTHENTICATE
           
 
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
 
Fields inherited from interface wt.method.RemoteAccess
versionID
 
Constructor Summary
private HTTPServer()
           
 
Method Summary
static void echo(HTTPRequest request, HTTPResponse response)
          Echo request

Supported API: false
static HTTPRequest getHTTPRequest()
          Get HTTPRequest associated with the current method context.
private static Boolean getReauthFlag(SessionContext session)
           
protected static boolean handleAuthenticationException(HTTPRequest request, HTTPResponse response)
          Internal server-side method to handle authentication exceptions thrown during request or response processing.
protected static void processRequest(HTTPRequest request, HTTPResponse response)
          Internal server-side method to process a HTTP request.
static HTTPResponse processRequest(Integer gateway_id, HTTPRequest request)
          Client API to process a HTTP request.
static void reauth(HTTPRequest request, HTTPResponse response)
          Reauthenticate user

Supported API: false
private static void setSession(HTTPRequest request)
          Internal server-side method to associate the current request with a previous session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

VERBOSE

private static boolean VERBOSE

HOMEPAGE_CLASS

private static String HOMEPAGE_CLASS

HOMEPAGE_METHOD

private static String HOMEPAGE_METHOD

SHOW_TARGET

private static boolean SHOW_TARGET

ANONYMOUS_USER

private static String ANONYMOUS_USER

ACCESS_LOG_ENABLED

private static boolean ACCESS_LOG_ENABLED

WWW_AUTHENTICATE

private static String WWW_AUTHENTICATE

CONFIRM_AUTH_KEY

private static final String CONFIRM_AUTH_KEY
See Also:
Constant Field Values

POST_DATA_KEY

private static final String POST_DATA_KEY
See Also:
Constant Field Values

HTTP_REQUEST_KEY

private static final String HTTP_REQUEST_KEY
See Also:
Constant Field Values

QUERYSTR_KEY

private static final String QUERYSTR_KEY
See Also:
Constant Field Values
Constructor Detail

HTTPServer

private HTTPServer()
Method Detail

processRequest

public static HTTPResponse processRequest(Integer gateway_id,
                                          HTTPRequest request)
                                   throws Throwable
Client API to process a HTTP request. Obtains the target class and method from the CGI_PATH_INFO property. The target class is presumed to have the necessary target method(s) as described in the above example.

Note that the response object is available from the start to allow the target method to set HTTP response headers that will get written when the response object's getOutputStream method is called.

Supported API: false

Throws:
Throwable

processRequest

protected static void processRequest(HTTPRequest request,
                                     HTTPResponse response)
Internal server-side method to process a HTTP request. This method is responsible for parsing the path info, handling posted input, and preparing the response object. Security context for the current thread must already be established.

Supported API: false


setSession

private static void setSession(HTTPRequest request)
Internal server-side method to associate the current request with a previous session.

Supported API: false


handleAuthenticationException

protected static boolean handleAuthenticationException(HTTPRequest request,
                                                       HTTPResponse response)
Internal server-side method to handle authentication exceptions thrown during request or response processing. Returns a 401 or a redirect if the current session is trying to reauthenticate. When reauthenticating, it returns a 303 to a URL that will return a 401 the first time it is requested, but process the second request.

Supported API: false


getReauthFlag

private static Boolean getReauthFlag(SessionContext session)

getHTTPRequest

public static HTTPRequest getHTTPRequest()
Get HTTPRequest associated with the current method context.

Supported API: true


echo

public static void echo(HTTPRequest request,
                        HTTPResponse response)
                 throws IOException
Echo request

Supported API: false

Throws:
IOException

reauth

public static void reauth(HTTPRequest request,
                          HTTPResponse response)
                   throws IOException
Reauthenticate user

Supported API: false

Throws:
IOException