com.day.cq.commons.servlets
Class AbstractCommandServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by org.apache.sling.api.servlets.SlingSafeMethodsServlet
          extended by org.apache.sling.api.servlets.SlingAllMethodsServlet
              extended by com.day.cq.commons.servlets.AbstractPredicateServlet
                  extended by com.day.cq.commons.servlets.AbstractCommandServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig
Direct Known Subclasses:
TagCommandServlet

public abstract class AbstractCommandServlet
extends AbstractPredicateServlet

Abstract servlet to use for the client/server command interface. Note: due to a problem in SCR plugin, this class cannot extend from the AbstractPredicateServlet because the predicate provider reference would be double defined.

See Also:
Serialized Form

Field Summary
static String ACTION_PARAM
          default action parameter name
static String PATH_PARAM
          default path parameter name
 
Fields inherited from class com.day.cq.commons.servlets.AbstractPredicateServlet
FILTER_PARAM, PREDICATE_PARAM
 
Constructor Summary
AbstractCommandServlet()
           
 
Method Summary
protected  void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
          Called by the SlingSafeMethodsServlet.mayService(SlingHttpServletRequest, SlingHttpServletResponse) method to handle an HTTP GET request.
protected  void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
          Called by the SlingAllMethodsServlet.mayService(SlingHttpServletRequest, SlingHttpServletResponse) method to handle an HTTP POST request.
protected  boolean hasCommand(SlingHttpServletRequest request)
          Checks if the command in the request is supported.
protected abstract  void performCommand(SlingHttpServletRequest request, SlingHttpServletResponse response)
          Perform the command of the current request.
protected  String requireParameter(SlingHttpServletRequest request, String name)
          Get value of specified parameter, trim and verify that it's provided
 
Methods inherited from class com.day.cq.commons.servlets.AbstractPredicateServlet
doGet, getPredicate, selectorPredicateStart
 
Methods inherited from class org.apache.sling.api.servlets.SlingAllMethodsServlet
doDelete, doPut, getAllowedRequestMethods, isMethodValid, mayService
 
Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_PARAM

public static final String PATH_PARAM
default path parameter name

See Also:
Constant Field Values

ACTION_PARAM

public static final String ACTION_PARAM
default action parameter name

See Also:
Constant Field Values
Constructor Detail

AbstractCommandServlet

public AbstractCommandServlet()
Method Detail

doPost

protected void doPost(SlingHttpServletRequest request,
                      SlingHttpServletResponse response)
               throws ServletException,
                      IOException
Description copied from class: SlingAllMethodsServlet
Called by the SlingAllMethodsServlet.mayService(SlingHttpServletRequest, SlingHttpServletResponse) method to handle an HTTP POST request.

This default implementation reports back to the client that the method is not supported.

Implementations of this class should overwrite this method with their implementation for the HTTP POST method support.

Overrides:
doPost in class SlingAllMethodsServlet
Parameters:
request - The HTTP request
response - The HTTP response
Throws:
ServletException - Not thrown by this implementation.
IOException - If the error status cannot be reported back to the client.

doGet

protected void doGet(SlingHttpServletRequest request,
                     SlingHttpServletResponse response)
              throws ServletException,
                     IOException
Description copied from class: AbstractPredicateServlet
Called by the SlingSafeMethodsServlet.mayService(SlingHttpServletRequest, SlingHttpServletResponse) method to handle an HTTP GET request.

This default implementation reports back to the client that the method is not supported.

Implementations of this class should overwrite this method with their implementation for the HTTP GET method support. Calls AbstractPredicateServlet.doGet(SlingHttpServletRequest, SlingHttpServletResponse, Predicate).

Overrides:
doGet in class AbstractPredicateServlet
Parameters:
request - The HTTP request
response - The HTTP response
Throws:
ServletException - Not thrown by this implementation.
IOException - If the error status cannot be reported back to the client.

hasCommand

protected boolean hasCommand(SlingHttpServletRequest request)
                      throws ServletException
Checks if the command in the request is supported. Returns false by default.

Parameters:
request - servlet request
Returns:
true if the command is supported.
Throws:
ServletException - if a servlet error occurs

performCommand

protected abstract void performCommand(SlingHttpServletRequest request,
                                       SlingHttpServletResponse response)
                                throws ServletException,
                                       IOException
Perform the command of the current request. This method is invoked if hasCommand(SlingHttpServletRequest) returns true for a POST request.

Parameters:
request - servlet request
response - servlet response
Throws:
ServletException - if an error occurs.
IOException - if an I/O error occurs.

requireParameter

protected String requireParameter(SlingHttpServletRequest request,
                                  String name)
                           throws ServletException
Get value of specified parameter, trim and verify that it's provided

Parameters:
request - the servlet request
name - the name of the parameter
Returns:
the value of the parameter
Throws:
ServletException - if the parameter is missing or empty.


Copyright © 2011-2013 Adobe Systems Incorporated. All Rights Reserved.