Version: 1.1.1

org.biomoby.service
Class MobyServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.biomoby.service.MobyServlet
All Implemented Interfaces:
Serializable, Remote, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ConvertAAtoFASTA_AA, FromFastaToDNASequence, LegacyService

@mobyService(name="MobyServlet",
             type="Testing",
             provider="moby.ucalgary.ca",
             author="gordonp@ucalgary.ca",
             in={},
             out={},
             description="No-operation base service implementation")
public class MobyServlet
extends javax.servlet.http.HttpServlet
implements Remote

This the base implementation of a MOBY servlet that can be easily extended to provide a meaningful service (by overriding processRequest()). Please see the documentation on how to use this servlet.

See Also:
Serialized Form

Field Summary
static String ADMIN_MODE
           
static int INIT_OUTPUT_BUFFER_SIZE
           
static String MOBY_AUTHORITATIVE_PARAM
           
static String MOBY_CENTRAL_URL_PARAM
           
static String MOBY_CONTACT_PARAM
           
static String MOBY_INPUT_PARAM
           
static String MOBY_OUTPUT_PARAM
           
static String MOBY_PROVIDER_URI_PARAM
           
static String MOBY_SECONDARYINPUT_PARAM
           
static String MOBY_SERVICE_DESC_PARAM
           
static String MOBY_SERVICENAME_PARAM
           
static String MOBY_SERVICETYPE_PARAM
           
static String MODE_HTTP_PARAM
           
static String RDF_MODE
           
 
Constructor Summary
MobyServlet()
           
 
Method Summary
 MobyService createServiceFromConfig(javax.servlet.http.HttpServletRequest request)
           
 void destroy()
          By default, this method does nothing.
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 Central getCentralImpl()
          Returns the Moby Central server that the service is associated with, based on the web.xml and the servlet annotation.
 MobyContentInstance getMobyContents(javax.servlet.http.HttpServletRequest request)
           
 String getServiceName()
          Reads the service name from the mobyService annotation.
 void init()
          If you override this method, be sure to call super.init()
 void log(String msg)
           
 void log(String msg, Exception ex)
           
static void main(String[] args)
          Expects one argument, an example MOBY XML input file or URL.
 void processRequest(MobyDataJob request, MobyDataJob result)
          The real worker method: implementing classes must override this method to do something useful.
 void processRequests(MobyContentInstance requestContents, MobyContentInstance resultContents)
          By default, this method will sequentially execute the individual jobs from the request payload (processRequest).
 void setCoCInitParameter(String param, String value)
           
static void setMainTerminationExit(boolean b)
          Determines whether call to main() that terminate on error should call System.exit() or not.
static MobyPrimaryData stringToPrimaryDataTemplate(String spec, Map<String,MobyDataTypeTemplate> runTimeTemplates)
          Strings have the form name:objectType:namespace, with ":namespace" optional If the input is expected to be a Collection, then the syntax is name:Collection(objectType):namespace
static MobySecondaryData stringToSecondaryDataTemplate(String template)
          Strings have the form name:paramType:default:spec where spec depends on the parameter type.
static void validateArguments(MobyDataJob job, MobyService service, String errMessagePrefix)
          Throws an exception if the data in the job does not match the input spec of the service.
 
Methods inherited from class javax.servlet.http.HttpServlet
service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOBY_CENTRAL_URL_PARAM

public static final String MOBY_CENTRAL_URL_PARAM
See Also:
Constant Field Values

MOBY_AUTHORITATIVE_PARAM

public static final String MOBY_AUTHORITATIVE_PARAM
See Also:
Constant Field Values

MOBY_CONTACT_PARAM

public static final String MOBY_CONTACT_PARAM
See Also:
Constant Field Values

MOBY_SERVICE_DESC_PARAM

public static final String MOBY_SERVICE_DESC_PARAM
See Also:
Constant Field Values

MOBY_PROVIDER_URI_PARAM

public static final String MOBY_PROVIDER_URI_PARAM
See Also:
Constant Field Values

MOBY_SERVICETYPE_PARAM

public static final String MOBY_SERVICETYPE_PARAM
See Also:
Constant Field Values

MOBY_SERVICENAME_PARAM

public static final String MOBY_SERVICENAME_PARAM
See Also:
Constant Field Values

MOBY_INPUT_PARAM

public static final String MOBY_INPUT_PARAM
See Also:
Constant Field Values

MOBY_SECONDARYINPUT_PARAM

public static final String MOBY_SECONDARYINPUT_PARAM
See Also:
Constant Field Values

MOBY_OUTPUT_PARAM

public static final String MOBY_OUTPUT_PARAM
See Also:
Constant Field Values

MODE_HTTP_PARAM

public static final String MODE_HTTP_PARAM
See Also:
Constant Field Values

RDF_MODE

public static final String RDF_MODE
See Also:
Constant Field Values

ADMIN_MODE

public static final String ADMIN_MODE
See Also:
Constant Field Values

INIT_OUTPUT_BUFFER_SIZE

public static final int INIT_OUTPUT_BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

MobyServlet

public MobyServlet()
Method Detail

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.servlet.ServletException,
                  IOException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException,
                   IOException
Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

getMobyContents

public MobyContentInstance getMobyContents(javax.servlet.http.HttpServletRequest request)
                                    throws Exception
Throws:
Exception

validateArguments

public static void validateArguments(MobyDataJob job,
                                     MobyService service,
                                     String errMessagePrefix)
                              throws Exception
Throws an exception if the data in the job does not match the input spec of the service.

Throws:
Exception

log

public void log(String msg)
Overrides:
log in class javax.servlet.GenericServlet

log

public void log(String msg,
                Exception ex)

init

public void init()
If you override this method, be sure to call super.init()

Overrides:
init in class javax.servlet.GenericServlet

getCentralImpl

public Central getCentralImpl()
Returns the Moby Central server that the service is associated with, based on the web.xml and the servlet annotation. If the servlet hasn't been initialized yet (init() hasn't been called), null will be returned.


setCoCInitParameter

public void setCoCInitParameter(String param,
                                String value)

createServiceFromConfig

public MobyService createServiceFromConfig(javax.servlet.http.HttpServletRequest request)
                                    throws Exception
Throws:
Exception

getServiceName

public String getServiceName()
Reads the service name from the mobyService annotation.


stringToSecondaryDataTemplate

public static MobySecondaryData stringToSecondaryDataTemplate(String template)
                                                       throws Exception
Strings have the form name:paramType:default:spec where spec depends on the parameter type. Currently, these are the valid paramTypes and their specs: e.g. db:String:nr:[nr,nt,est,swissprot] e.g. filter:Boolean:true e.g. hits:Integer:100:[0,]

Throws:
Exception

stringToPrimaryDataTemplate

public static MobyPrimaryData stringToPrimaryDataTemplate(String spec,
                                                          Map<String,MobyDataTypeTemplate> runTimeTemplates)
                                                   throws Exception
Strings have the form name:objectType:namespace, with ":namespace" optional If the input is expected to be a Collection, then the syntax is name:Collection(objectType):namespace

Throws:
Exception

destroy

public void destroy()
By default, this method does nothing. If any additional resources were allocated in an override of init(), they should be freed in an override of this method.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

processRequests

public void processRequests(MobyContentInstance requestContents,
                            MobyContentInstance resultContents)
                     throws Exception
By default, this method will sequentially execute the individual jobs from the request payload (processRequest). Override this method if you want to implement some division-of-labour scheme.

Parameters:
resultContents - is a Map prepopulated with pairs for the response
Throws:
Exception

processRequest

public void processRequest(MobyDataJob request,
                           MobyDataJob result)
                    throws Exception
The real worker method: implementing classes must override this method to do something useful. By default, nothing is done. If a ServiceException is thrown in this method, it is copied verbatim into the MOBY response. Any other exceptions thrown will be automatically wrapped in a ServiceException of severity ERROR and type INTERNAL_PROCESSING_ERROR. To add any other type of non-fatal error (e.g. a WARN), call addException() explicitly, rather than throwing a Java Exception which stops the job's execution.

Parameters:
request - the request to process, with params guaranteed to be of the type specified in the mobyService annotation, or values overriding the annjotation in a WAR file's WEB-INF/web.xml
Throws:
Exception

setMainTerminationExit

public static void setMainTerminationExit(boolean b)
Determines whether call to main() that terminate on error should call System.exit() or not. This is the default behaviour, and should generally be switched only for unit testing purposes.


main

public static void main(String[] args)
                 throws Exception
Expects one argument, an example MOBY XML input file or URL. processRequest() is then called for every job in the input data, and the results are printed to the screen.

Throws:
Exception

Version: 1.1.1

Submit a bug or feature
Generated: Sat May 29 04:26:35 EDT 2010