Class ServletRepository

  • All Implemented Interfaces:
    Repository

    public class ServletRepository
    extends ProxyRepository
    Proxy for a repository bound in servlet context. The configured repository attribute is looked up from the servlet context during each method call. Thus the repository does not need to exist when this class is instantiated. The repository can also be replaced with another repository during the lifetime of an instance of this class.

    A typical way to use this class would be:

     public class MyServlet extends HttpServlet {
    
         private final Repository repository = new ServletRepository(this);
    
         protected void doGet(
                 HttpServletRequest request, HttpServletResponse response)
                 throws ServletException, IOException {
              try {
                  Session session = repository.login();
                  try {
                      ...;
                  } finally {
                      session.logout();
                  }
              } catch (RepositoryException e) {
                  throw new ServletException(e);
              }
          }
    
     }
     

    Starting with version 1.6 this class can also be used by a servlet filter:

     public class MyFilter implements Filter {
    
         private Repository repository;
    
         public void init(FilterConfig config) {
             repository = new ServletRepository(config);
         }
    
         // ...
    
     }
     
    Since:
    1.4
    See Also:
    ServletRepositoryFactory, FilterRepositoryFactory
    • Constructor Detail

      • ServletRepository

        public ServletRepository​(javax.servlet.GenericServlet servlet)
        Creates a proxy for a repository found in the context of the given servlet.
        Parameters:
        servlet - servlet
      • ServletRepository

        public ServletRepository​(javax.servlet.FilterConfig config)
        Creates a proxy for a repository found in the servlet context associated with the given filter configuration.
        Parameters:
        config - filter configuration
        Since:
        Apache Jackrabbit 1.6