Adaptor is an abstract class that represents objects that can receive events from a WebObjects adaptor. A WebObjects adaptor is a process that handles communication between the server and a WebObjects application. The WebObjects application (a WebApplication instance) communicates with the adaptor using messages defined in the Adaptor class.
WebObjects offers several choices of adaptors that you can use, all of which handle HTTP requests. You may want to write your own adaptor to handle other kinds of requests, such as DO, CORBA, or DCOM. If you write your own adaptor, you will also need to write your own Adaptor subclass.
The purpose of the Adaptor class is to perform these tasks:
All of the provided WebObjects adaptors use a subclass of Adaptor named DefaultAdaptor to communicate with WebApplication. The source code for the DefaultAdaptor implementation is distributed with WebObjects in the directory NEXT_ROOT/NextLibrary/WOAdaptors/CGI/Source/Application. Use this class as an example when creating your own Adaptor subclass.
You specify the adaptor(s) you want to use on the command line when you start a WebObjects application. If you autostart the application or if you do not specify the adaptor, the application uses the default HTTP adaptor (DefaultAdaptor). To specify a custom subclass of Adaptor, use the -a option. For example, the following command starts up the DodgeDemo example using a subclass of Adaptor named MyHTTPSAdaptor.
DodgeDemoJava.exe -a MyHTTPSAdaptor
When the WebApplication object encounters the -a option, it sends itself an adaptorWithName message. This method constructs the Adaptor subclass (MyHTTPSAdaptor in this example).
You can specify more than one adaptor per application if they are of different types. (For example, you could have a separate adaptor with its own port for communicating directly with Java applets on the browser.) If you specify multiple HTTP adaptors, only the last one specified will be used.
If you specify an adaptor on the application command line, you can pass arguments to the Adaptor class as well. You can pass any options defined by your subclass. The application passes all options following a -a option up until the next -a, -c, or -d option or the application name to the adaptor.
For a list of options you can specify for the DefaultAdaptor, see the document Serving WebObjects.
A WebObjects application's request-response loop (or run loop) begins when the WebApplication receives a run message. Before the run method begins the loop, it traverses its list of adaptors and sends each one of them a registerForEvents message. The registerForEvents method performs all tasks necessary to ensure that the Adaptor can begin receiving events. When the application is being terminated, WebApplication traverses its list of adaptors again and issues an unregisterForEvents message to each one of them. This method undoes whatever was done in registerForEvents so that the Adaptor stops receiving events.
When the Adaptor receives an HTTP request, it reads the method lines, HTTP header information, and any HTTP content from the request message, and creates a Request object.
After it has created the Request object, the Adaptor sends it to the WebApplication using the message handleRequest. Upon receiving the request, WebApplication starts a request-response cycle. This cycle results in a response that must be sent back to the server. (That is, the handleRequest message returns a Response object.) the Adaptor receives the Response and translates it into a message that it can send back to the adaptor.
Allocates and initializes an Adaptor with the name aName arguments someArguments, and application anApplication. aName is the name of the Adaptor subclass. someArguments is the argument list passed to the application. anApplication is the WebApplication instance with which this adaptor will be associated.
The WebApplication method adaptorWithName invokes this message when it encounters an -a option on the command line.
See Also: adaptorWithName in WebApplication
Performs any actions necessary to have the Adaptor start receiving events.
Undoes the actions performed in registerForEvents so that the Adaptor stops receiving events.