Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.service.servlet;
  
  import java.util.EnumMap;
  
  
"Uber-servlet" that is usually used to route requests to handlers (sync, node status, store), instead of handler-specific servlets.
 
 @SuppressWarnings("serial")
 public class ServiceDispatchServlet<K extends EntryKey, E extends StoredEntry<K>>
     extends ServletBase
 {
     protected final RequestPathStrategy _pathStrategy;
 
     protected final EnumMap<PathTypeServletBase_servletsByPath;
     
     /*
     /**********************************************************************
     /* Life-cycle
     /**********************************************************************
      */

    
Constructor used when the servlet has been registered at proper root for resolving references to entry points, as per configured
 
     public ServiceDispatchServlet(ClusterViewByServer clusterViewString servletPathBase,
             SharedServiceStuff stuff,
             EnumMap<PathTypeServletBaseservlets)
     {
         // null -> use servlet path base as-is
         super(stuffclusterViewservletPathBase);
 
          = stuff.getPathStrategy();
          = servlets;
     }
 
     /*
     /**********************************************************************
     /* Overrides
     /**********************************************************************
      */
 
     @Override
     {
         String path = orig.getRequestURI();
 
         /* First things first: remove servlet path prefix (either override,
          * or one used for registration)
          */
         if ( == null) { // no base path; use whatever it was registered with
             path = _trimPath(pathorig.getServletPath(), true);
         } else {
             path = _trimPath(pathfalse);
         }
         // false -> not URL decoded
         return new ServletServiceRequest(origpathfalse);
     }
     
     /*
     /**********************************************************************
     /* Main dispatch methods
     /**********************************************************************
      */
 
     @Override
     public void handleGet(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics metadatathrows IOException
     {
         ServletBase servlet = _matchServlet(request);
         if (servlet != null) {
             servlet.handleGet(requestresponsemetadata);
             return;
         }
         response = response.notFound();
         response.writeOut(null);
     }
 
     @Override
     public void handleHead(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics metadatathrows IOException
     {
         ServletBase servlet = _matchServlet(request);
         if (servlet != null) {
             servlet.handleHead(requestresponsemetadata);
            return;
        }
        response = response.notFound();
        response.writeOut(null);
    }
    @Override
    public void handlePut(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics metadatathrows IOException
    {
        ServletBase servlet = _matchServlet(request);
        if (servlet != null) {
            servlet.handlePut(requestresponsemetadata);
            return;
        }
        response = response.notFound();
        response.writeOut(null);
    }
    @Override
    public void handlePost(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics metadatathrows IOException
    {
        ServletBase servlet = _matchServlet(request);
        if (servlet != null) {
            servlet.handlePost(requestresponsemetadata);
            return;
        }
        response = response.notFound();
        response.writeOut(null);
    }
    @Override
    public void handleDelete(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics metadatathrows IOException
    {
        ServletBase servlet = _matchServlet(request);
        if (servlet != null) {
            servlet.handleDelete(requestresponsemetadata);
            return;
        }
        response = response.notFound();
        response.writeOut(null);
    }
    
    /*
    /**********************************************************************
    /* Helper methods
    /**********************************************************************
     */
    protected ServletBase _matchServlet(ServletServiceRequest request)
    {
        PathType type = .matchPath(request);
        if (type != null) {
            return .get(type);
        }
        return null;
    }
New to GrepCode? Check out our FAQ X