|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectwt.httpgw.HTTPServer
public class HTTPServer
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
Then the following URL could be used to invoke the myAction method of the MyHTTPService class:http://www.wt.myco.com/servlet/windchill
The MyHTTPService class would contain myAction methods with the following signatures:http://www.wt.myco.com/servlet/windchill/MyHTTPService/myAction
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.
| Method Summary | |
|---|---|
static HTTPRequest |
getHTTPRequest()
Get HTTPRequest associated with the current method context. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static HTTPRequest getHTTPRequest()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||