nu.staldal.lsp.framework
Interface Service

All Known Implementing Classes:
ServiceBase

Deprecated.

@Deprecated
public interface Service

Interface for Service.

Services will be loaded and instantiated using Class.forName and Class.newInstance, so they must have a public no-arg constructor.

There will be only one instance of each Service per web application per JVM (in case of a distributed application). The execute method may be invoked concurrently by several threads.

It's not recommended to have any instance fields in the Service class which can be changed by the execute method. Instance fields which are initialized by the init method and then only read by the execute method are OK. If you have instance fields which can be changed by the execute method, access to them need to be synchronized.

The life cycle and instance management of Services are very similar to Servlet, see the Servlet specification for details.


Field Summary
static java.lang.String INCLUDE_ATTR_PREFIX
          Deprecated. Prefix for request attributes for include attributes.
static int REQUEST_DELETE
          Deprecated. Request type DELETE.
static int REQUEST_GET
          Deprecated. Request type GET.
static int REQUEST_INCLUDE
          Deprecated. Request type include.
static int REQUEST_POST
          Deprecated. Request type POST.
static int REQUEST_PUT
          Deprecated. Request type PUT.
 
Method Summary
 void destroy()
          Deprecated. Invoked once by the Servlet.destroy() method.
 java.lang.String execute(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.Map<java.lang.String,java.lang.Object> pageParams, int requestType)
          Deprecated. Invoked for each request to this Service.
 void init(javax.servlet.ServletContext context)
          Deprecated. Invoked once directly after instantiation, before first use.
 

Field Detail

REQUEST_GET

static final int REQUEST_GET
Deprecated. 
Request type GET.

See Also:
Constant Field Values

REQUEST_POST

static final int REQUEST_POST
Deprecated. 
Request type POST.

See Also:
Constant Field Values

REQUEST_INCLUDE

static final int REQUEST_INCLUDE
Deprecated. 
Request type include.

See Also:
Constant Field Values

REQUEST_PUT

static final int REQUEST_PUT
Deprecated. 
Request type PUT.

See Also:
Constant Field Values

REQUEST_DELETE

static final int REQUEST_DELETE
Deprecated. 
Request type DELETE.

See Also:
Constant Field Values

INCLUDE_ATTR_PREFIX

static final java.lang.String INCLUDE_ATTR_PREFIX
Deprecated. 
Prefix for request attributes for include attributes.

See Also:
Constant Field Values
Method Detail

init

void init(javax.servlet.ServletContext context)
          throws javax.servlet.ServletException
Deprecated. 
Invoked once directly after instantiation, before first use.

The init method should not invoke DispatcherServlet.lookupService(String), DispatcherServlet.doGet(HttpServletRequest, HttpServletResponse), DispatcherServlet.doPost(HttpServletRequest, HttpServletResponse) or ServletExtLib.handleElement(String, org.xml.sax.Attributes, org.xml.sax.ContentHandler).

Parameters:
context - the ServletContext
Throws:
javax.servlet.ServletException - may throw ServletException

execute

java.lang.String execute(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response,
                         java.util.Map<java.lang.String,java.lang.Object> pageParams,
                         int requestType)
                         throws javax.servlet.ServletException,
                                java.io.IOException
Deprecated. 
Invoked for each request to this Service.

May be invoked concurrently by several threads.

Is invoked for GET, POST, PUT, DELETE and HEAD requests. You should not treat HEAD requests differently than GET requests, the framework will automatically discard the body and only send the headers. The requestType parameter indicate the type of request. See the HTTP specification for differences between GET, POST, PUT and DELETE requests.

There are three choices to create the response:

  1. Return the name of a page to display, and fill pageParams with parameters to this page. In this case, response should only be used to set headers.
  2. Send the whole response by using response and return null. In this case the framework will not touch response after this method returns, and will not use pageParams. This can be used if you want to use sendError or sendRedirect.
  3. Return the name of an other service to forward the request to, prefixed by "*". Any parameters added to pageParams are retained. You may add attributes to request in order to comnunicate with the other service.

If requestType is REQUEST_INCLUDE, choice 2 and 3 may not be used, and response may not be modified in any way. You may either return the name of page, or use the SAX2 ContentHandler passed as a request attribute with name "org.xml.sax.ContentHandler" and return null. startDocument and endDocument must not be invoked on the ContentHandler, use ContentHandlerStartEndDocumentFilter if this is a problem.

Parameters:
request - the HttpServletRequest
response - the HttpServletResponse
pageParams - map for page parameters
requestType - the type of request: REQUEST_GET, REQUEST_POST, REQUEST_PUT, REQUEST_DELETE or REQUEST_INCLUDE
Returns:
name of the page to view, or null to not use any page, or the name of an other service to forward to prefixed by "*"
Throws:
javax.servlet.ServletException - may throw ServletException
java.io.IOException - may throw IOException

destroy

void destroy()
Deprecated. 
Invoked once by the Servlet.destroy() method.