Servlet.pm


NAME

Apache::Servlet - Methods for accessing the Apache JServ servlet engine from mod_perl


DESCRIPTION

Apache::Servlet is a Perl5 module made to run with mod_perl inside an Apache HTTPD process. It can be used to connect to an Apache JServ Java servlet engine the same way that mod_jserv does. It only works if mod_jserv is present because mod_jserv starts and initializes the servlet engine. But after that point, Apache::Servlet allows mod_perl scripts to make request to Java Servlets and capture the output for further processing.


SYNOPSIS

The following methods are available from Apache::Servlet:

$obj = new Apache::Servlet( $request, $servlet_dir, $servlet_class, $env_ref, $header_ref, $entity_ref, $entity_type);

$hashref = $obj-> get_headers() ;

$scalar = $obj->get_header( $name );

$scalar = $obj-> get_entity() ;

$obj-> return_results() ;

$obj-> dump_results() ;

constructor

$obj = new Apache::Servlet( $request, $servlet_dir, $servlet_class, $env_ref, $header_ref, $entity_ref, $entity_type);

$request is a reference to the Apache API's request structure. Use $r for the HTTP client request. Or if needed, you may use a subrequest if you create one.

$servlet_dir is the full path of the directory where the servlet class file can be found.

$servlet_class is a string with the name of the Java servlet class that will be invoked by the servlet engine.

$env_ref is a reference to a hash containing a CGI-like environment. You may construct your own environment from scratch if needed. Otherwise, the default is the CGI environment from mod_perl for the current HTTP request via $r->cgi_env().

$header_ref is a reference to a hash containing the servlet request headers. You may construct your own request headers. Otherwise, the default is the HTTP client headers from mod_perl for the current HTTP request via $r->headers_in().

$entity_ref is a scalar string with the entity contents. The default is an empty input entity.

$entity_type is the MIME type of the HTTP input entity. The default is an empty value, which is appropriate if the input itself is empty.

The servlet response can then be found in variables inside $obj. $obj->{resp_headers} is a reference to a hash containing the response headers and their values. (The header names have been converted to lower case for case-insensitive lookup capability.)

$obj->{resp_entity} contains the response entity. The response type may be any MIME type. For the most common example, if $obj->{resp_headers}{``content-type''} is ``text/html'' then the response entity contains HTML text. However, there's nothing to prevent a servlet from returning something humanly-unreadable like an audio clip if the MIME type is appropriately set.

$obj->{resp_logs} contains a reference to an array of log entries.

$obj->{resp_errors} contains a reference to an array of error messages from the servlet.

get_headers

$hashref = $obj-> get_headers() ;

returns a reference to a hash containing the response headers returned from the servlet.

get_header

$scalar = $obj->get_header( $name );

returns the value of a single header by name.

get_entity

$scalar = $obj-> get_entity() ;

returns a scalar containing the full response entity from the servlet. (Caution: this could be enormous!)

return_results

$obj-> return_results() ;

Send the collected servlet results back to the HTTP client. This could possibly have been done after modifying the results.

dump_results

$obj-> dump_results() ;

For debugging purposes, this dumps the servlet output on the HTTP client output, breaking it down by parts of the response.


CONFIGURATION

You must already have mod_jserv and the Apache JServ configured and running before Apache::Servlet will work.

Your Apache configuration must include ServletAuthExport On in order for Apache::Servlet to obtain the authentication and host information needed to contact the Apache JServ engine. Otherwise mod_jserv will not export this information to other Apache modules.


DEPENDENCIES

This is the version of Apache::Servlet that comes with version 0.9.10 of the Apache JServ.

In order to build and install Apache::Servlet, you must first have Apache HTTPD 1.2 or greater, mod_jserv 0.9.10, mod_perl 1.00 or greater, and any version (preferably current) of the Net::TCP perl5 module.

Note: mod_jserv and the Apache JServ engine will undergo a change in their protocol around the time frame of 0.9.11 or some release after that. Once that change occurs, this version of Apache::Servlet will no longer work and will be forever obsolete. However, a new updated version will be included with the new Apache JServ engine.


SEE ALSO

.Java-Apache Project Documentation

.mod_perl Home Page and other documentation


AUTHOR

Apache::Servlet was written by Ian Kluft. The Apache JServ servlet engine and the mod_jserv Apache module were written by many volunteers of the Java-Apache Project. mod_perl was written by Doug MacEachern with contributions by many other volunteers.


CAVEATS

This is experimental only. Apache::Servlet will soon undergo changes to the protocol to talk with the Apache JServ engine when the Apache JServ Protocol Version 2 is introduced.. If you use this perl module, you probably should join the Java-Apache developers mail list and watch for patches (or even provide your own.)