Class JESTServlet

  • All Implemented Interfaces:
    java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class JESTServlet
    extends javax.servlet.http.HttpServlet
    A specialized HTTP servlet to interpret HTTP requests as Java Persistent API commands on a running persistence unit. The persistence unit is identified by the name of the unit and is supplied to this servlet during its initialization. The component using the persistent unit and this servlet must be within the same module scope.

    The syntax of the request URL is described in OpenJPA web site.

    The response to a resource request is represented in various format, namely XML, JSON or a JavaScript that will dynamically render in the browser. The format can be controlled via the initialization parameter response.format in <init-param> clause or per request basis via format=xml|dojo|json encoded in the path expression of the Request URI.

    Servlet initialization parameter

    ParameterValue
    persistence.unitName of the persistence unit. Mandatory
    response.formatDefault format used for representation. Defaults to xml.

    Author:
    Pinaki Poddar
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      JESTServlet()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void createPersistenceUnit()  
      void destroy()  
      void doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Peeks into the servlet path of the request to create appropriate JEST command.
      protected boolean findPersistenceUnit()  
      protected void handleError​(JPAServletContext ctx, java.lang.Throwable t)  
      void init​(javax.servlet.ServletConfig config)  
      void log​(java.lang.String s)  
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
      • Methods inherited from class javax.servlet.GenericServlet

        getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INIT_PARA_UNIT

        public static final java.lang.String INIT_PARA_UNIT
        Servlet initialization parameter monikers
        See Also:
        Constant Field Values
      • INIT_PARA_STANDALONE

        public static final java.lang.String INIT_PARA_STANDALONE
        See Also:
        Constant Field Values
    • Constructor Detail

      • JESTServlet

        public JESTServlet()
    • Method Detail

      • init

        public void init​(javax.servlet.ServletConfig config)
                  throws javax.servlet.ServletException
        Specified by:
        init in interface javax.servlet.Servlet
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException
      • doGet

        public void doGet​(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws javax.servlet.ServletException,
                          java.io.IOException
        Peeks into the servlet path of the request to create appropriate JEST command. Passes the request on to the command which is responsible for generating a response.
        Overrides:
        doGet in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        java.io.IOException
      • createPersistenceUnit

        protected void createPersistenceUnit()
                                      throws javax.servlet.ServletException
        Throws:
        javax.servlet.ServletException
      • findPersistenceUnit

        protected boolean findPersistenceUnit()
      • handleError

        protected void handleError​(JPAServletContext ctx,
                                   java.lang.Throwable t)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Servlet
        Overrides:
        destroy in class javax.servlet.GenericServlet
      • log

        public void log​(java.lang.String s)
        Overrides:
        log in class javax.servlet.GenericServlet