info.sswap.api.servlet
Class SimpleSSWAPServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by info.sswap.api.servlet.AbstractSSWAPServlet
              extended by info.sswap.api.servlet.SimpleSSWAPServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public abstract class SimpleSSWAPServlet
extends AbstractSSWAPServlet

A servlet wrapper that works in concert with MapsTo for the mapping of subjects to objects. Using a service class that is an extension of MapsTo allows developers to implement their service without the constraints and subtleties of servlet programming. This is best practice for most implementations. To use, extend and add a servlet launcher; e.g.:

 public class MyServlet extends SimpleSSWAPServlet {
     ...
 }
 
The servlet launcher MyServlet can be connected to the service class via either of two methods. Via web.xml; e.g.:
 <servlet>
 
  <servlet-name>MyServlet</servlet-name>
  <servlet-class>org.mySite.sswap.servlets.MyServlet</servlet-class>
 
  <init-param>
    <param-name>ServiceClass</param-name>
    <param-value>org.mySite.sswap.services.MyService</param-value>
  </init-param>
  
 </servlet>
 
 <servlet-mapping>
  <servlet-name>MyServlet</servlet-name>
  <url-pattern>/MyService/*</url-pattern>
 </servlet-mapping>
 
 
Or, if ServiceClass is not defined in web.xml, the class may be specified by overriding the method getServiceClass; see example in getServiceClass().

MyService must extend MapsTo to implement the service.

Author:
Damian Gessler
See Also:
MapsTo, Serialized Form

Field Summary
private static long serialVersionUID
           
 
Fields inherited from class info.sswap.api.servlet.AbstractSSWAPServlet
remoteServiceURI, RRG_RETRIEVAL_SUFFIX
 
Constructor Summary
SimpleSSWAPServlet()
           
 
Method Summary
<T> java.lang.Class<T>
getServiceClass()
          Declare the class (e.g., MyService that performs the service.
protected  void handleRequest(RIG rig)
          This method is marked protected solely for package access purposes.
 void init(javax.servlet.ServletConfig servletConfig)
          Override this method (or GenericServlet.init() for custom servlet initialization code.
private  MapsTo newMapsTo(RIG rig)
          Dynamically instantiates a MapsTo object either first by name (from an init value in web.xml), or if that is not defined, by value (from getServiceClass).
 
Methods inherited from class info.sswap.api.servlet.AbstractSSWAPServlet
doGet, doPost, getTimeout, publishRRG, setTimeout
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

SimpleSSWAPServlet

public SimpleSSWAPServlet()
Method Detail

init

public void init(javax.servlet.ServletConfig servletConfig)
          throws javax.servlet.ServletException
Description copied from class: AbstractSSWAPServlet
Override this method (or GenericServlet.init() for custom servlet initialization code. If overriding this method, overriding method MUST call super.init(servletConfig) as the first line of code. This method is called once at the end of all internal initialization and before any requests are serviced.

The method is passed the Servlet Configuration and may throw a ServletException. Thrown errors are not caught and will terminate servlet initialization.

Uses for this method are to set the servlet timeout (see AbstractSSWAPServlet.setTimeout(int)), effect changes to URI caching (see SSWAP.getCache()), and so forth.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class AbstractSSWAPServlet
Parameters:
servletConfig - the ServletConfig object of the servlet
Throws:
javax.servlet.ServletException - on a servlet configuration error
See Also:
SSWAP, ServletConfig

getServiceClass

public <T> java.lang.Class<T> getServiceClass()
Declare the class (e.g., MyService that performs the service. The class must be a subclass of MapsTo. This can be done by overriding this method to return the class; e.g.:
 public class MyServlet extends SimpleSSWAPServlet {

   //@Override
   public void init(ServletConfig servletConfig) throws ServletException {
 
     // always do this
     super.init(servletConfig);
 
     // do anything else here that needs to be done once, on servlet load;
     // for example, increase the service timeout above the default in Config.
 
     int timeout = 10 * 60 * 1000;    // 10 mins in milliseconds
     setTimeout(timeout);
 
   }
   
   //@SuppressWarnings("unchecked")
   //@Override
   public <T> Class<T> getServiceClass() {
     return (Class<T>) MyService.class;
   }
 }
 
 
A value for the ServiceClass parameter in web.xml, if defined, will take precedence over this method.

Type Parameters:
T - subclass of MapsTo
Returns:
class to load for the service
See Also:
MapsTo, Config

handleRequest

protected final void handleRequest(RIG rig)
This method is marked protected solely for package access purposes. It should not be called directly and cannot be overridden. The servlet handler will call this method automatically. To perform a specific subject -> object mapping, override MapsTo.mapsTo(info.sswap.api.model.SSWAPSubject).

Specified by:
handleRequest in class AbstractSSWAPServlet
Parameters:
rig - RIG invoking the service. This RIG should be edited and will become the basis for the RRG returned by the service. Best practice is to leave most of the RIG untouched, modifying only the SSWAPObject subgraphs.
See Also:
MapsTo

newMapsTo

private MapsTo newMapsTo(RIG rig)
                  throws java.lang.InstantiationException,
                         java.lang.IllegalAccessException,
                         java.lang.ClassNotFoundException
Dynamically instantiates a MapsTo object either first by name (from an init value in web.xml), or if that is not defined, by value (from getServiceClass).

Parameters:
rig - RIG for this request
Returns:
an instance of the service class
Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.