nu.staldal.lsp.framework
Class EasyService

java.lang.Object
  extended by nu.staldal.lsp.framework.ThrowawayService
      extended by nu.staldal.lsp.framework.EasyService

public abstract class EasyService
extends ThrowawayService

Abstract base class for easy services.

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

A new instance will be created for each request, and that instance is thrown away after the request. The execute method is only invoked once per instance, so there are no thread-safety issues. It's not a problem to use instance fields.

Use the Parameter annotation on instance fields to automatically populate them with HTTP request parameter values.

Use the PageParameter annotation on instance fields to automatically use them as page parameters to templates.

Author:
Mikael Ståldal

Field Summary
 
Fields inherited from class nu.staldal.lsp.framework.ThrowawayService
context, dbConn, extraArgs, INCLUDE_ATTR_PREFIX, mainDB, request, REQUEST_DELETE, REQUEST_GET, REQUEST_INCLUDE, REQUEST_POST, REQUEST_PUT, requestType, response
 
Constructor Summary
EasyService()
           
 
Method Summary
abstract  java.lang.String execute()
          Invoked for a request to this Service.
 java.lang.String execute(java.util.Map<java.lang.String,java.lang.Object> pageParams)
          Do not override this method.
 
Methods inherited from class nu.staldal.lsp.framework.ThrowawayService
getUserLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EasyService

public EasyService()
Method Detail

execute

public final java.lang.String execute(java.util.Map<java.lang.String,java.lang.Object> pageParams)
                               throws java.lang.Exception
Do not override this method.

Specified by:
execute in class ThrowawayService
Parameters:
pageParams - map for page parameters
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:
java.lang.Exception - may throw any Exception
See Also:
execute()

execute

public abstract java.lang.String execute()
                                  throws java.lang.Exception
Invoked for a request to this Service.

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

There are three choices to create the response:

  1. Return the name of a page to display, and pass parameters to this page using fields annotated with PageParameter. 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. 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 "*". You may add attributes to request in order to comnunicate with the other service.

If requestType is ThrowawayService.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.

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:
java.lang.Exception - may throw any Exception