Package com.composum.sling.core.servlet
Class AbstractServiceServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- org.apache.sling.api.servlets.SlingSafeMethodsServlet
-
- org.apache.sling.api.servlets.SlingAllMethodsServlet
-
- com.composum.sling.core.servlet.AbstractServiceServlet
-
- All Implemented Interfaces:
RestrictedService
,Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
- Direct Known Subclasses:
JobControlServlet
,NodeTreeServlet
,SetupServlet
,SystemServlet
,TranslationServlet
public abstract class AbstractServiceServlet extends org.apache.sling.api.servlets.SlingAllMethodsServlet implements RestrictedService
A basic class for all '/bin/{service}/path/to/resource' servlets.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
DATE_FORMAT
static String
PARAM_BEFORE
static String
PARAM_CMD
static String
PARAM_FILE
static String
PARAM_FILTER
static String
PARAM_ID
static String
PARAM_INDEX
static String
PARAM_JCR_CONTENT
static String
PARAM_LABEL
static String
PARAM_MIME_TYPE
static String
PARAM_NAME
static String
PARAM_PATH
static String
PARAM_QUERY
static String
PARAM_RESOURCE_TYPE
static String
PARAM_TITLE
static String
PARAM_TYPE
static String
PARAM_URL
static String
PARAM_VALUE
static String
PARAM_VERSION
-
Constructor Summary
Constructors Constructor Description AbstractServiceServlet()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
deactivate()
protected void
doDelete(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)
protected void
doGet(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)
protected void
doPost(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)
protected void
doPut(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)
static <T> T
getJsonObject(String input, Class<T> type)
static <T> T
getJsonObject(org.apache.sling.api.SlingHttpServletRequest request, Class<T> type)
static <T> T
getJsonObject(org.apache.sling.api.SlingHttpServletRequest request, Class<T> type, com.google.gson.InstanceCreator<T> instanceCreator)
protected abstract @NotNull ServletOperationSet<?,?>
getOperations()
Each servlet implementation must provide access to its operation set for request delegation.static String
getPath(org.apache.sling.api.SlingHttpServletRequest request)
static @NotNull ResourceHandle
getResource(org.apache.sling.api.SlingHttpServletRequest request)
Retrieves the resource using the suffix from the request.protected ServiceRestrictions
getRestrictions()
ServiceRestrictions.Key
getServiceKey()
protected boolean
isEnabled(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response, ServiceRestrictions.Permission needed)
protected void
jsonAnswerItemExists(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
static void
jsonValue(com.google.gson.stream.JsonWriter writer, Object value)
protected ServiceRestrictions.Permission
methodDeletePermission(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
protected ServiceRestrictions.Permission
methodGetPermission(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
protected ServiceRestrictions.Permission
methodPostPermission(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
protected ServiceRestrictions.Permission
methodPutPermission(@NotNull org.apache.sling.api.SlingHttpServletRequest request)
static void
setNoCacheHeaders(@NotNull org.apache.sling.api.SlingHttpServletResponse response)
static @NotNull ResourceHandle
tryToUseRawSuffix(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull ResourceHandle resource)
-
Methods inherited from class org.apache.sling.api.servlets.SlingAllMethodsServlet
getAllowedRequestMethods, isMethodValid, mayService
-
Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, service
-
-
-
-
Field Detail
-
PARAM_FILE
public static final String PARAM_FILE
- See Also:
- Constant Field Values
-
PARAM_CMD
public static final String PARAM_CMD
- See Also:
- Constant Field Values
-
PARAM_FILTER
public static final String PARAM_FILTER
- See Also:
- Constant Field Values
-
PARAM_ID
public static final String PARAM_ID
- See Also:
- Constant Field Values
-
PARAM_INDEX
public static final String PARAM_INDEX
- See Also:
- Constant Field Values
-
PARAM_JCR_CONTENT
public static final String PARAM_JCR_CONTENT
- See Also:
- Constant Field Values
-
PARAM_LABEL
public static final String PARAM_LABEL
- See Also:
- Constant Field Values
-
PARAM_MIME_TYPE
public static final String PARAM_MIME_TYPE
- See Also:
- Constant Field Values
-
PARAM_NAME
public static final String PARAM_NAME
- See Also:
- Constant Field Values
-
PARAM_PATH
public static final String PARAM_PATH
- See Also:
- Constant Field Values
-
PARAM_BEFORE
public static final String PARAM_BEFORE
- See Also:
- Constant Field Values
-
PARAM_QUERY
public static final String PARAM_QUERY
- See Also:
- Constant Field Values
-
PARAM_RESOURCE_TYPE
public static final String PARAM_RESOURCE_TYPE
- See Also:
- Constant Field Values
-
PARAM_TITLE
public static final String PARAM_TITLE
- See Also:
- Constant Field Values
-
PARAM_TYPE
public static final String PARAM_TYPE
- See Also:
- Constant Field Values
-
PARAM_URL
public static final String PARAM_URL
- See Also:
- Constant Field Values
-
PARAM_VALUE
public static final String PARAM_VALUE
- See Also:
- Constant Field Values
-
PARAM_VERSION
public static final String PARAM_VERSION
- See Also:
- Constant Field Values
-
DATE_FORMAT
public static final String DATE_FORMAT
- See Also:
- Constant Field Values
-
-
Method Detail
-
deactivate
protected void deactivate()
-
getRestrictions
protected ServiceRestrictions getRestrictions()
-
getServiceKey
public ServiceRestrictions.Key getServiceKey()
- Specified by:
getServiceKey
in interfaceRestrictedService
-
isEnabled
protected boolean isEnabled(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response, @NotNull ServiceRestrictions.Permission needed)
-
methodGetPermission
@NotNull protected ServiceRestrictions.Permission methodGetPermission(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
-
methodPostPermission
@NotNull protected ServiceRestrictions.Permission methodPostPermission(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
-
methodPutPermission
@NotNull protected ServiceRestrictions.Permission methodPutPermission(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
-
methodDeletePermission
@NotNull protected ServiceRestrictions.Permission methodDeletePermission(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request)
-
getOperations
@NotNull protected abstract @NotNull ServletOperationSet<?,?> getOperations()
Each servlet implementation must provide access to its operation set for request delegation.
-
doGet
protected void doGet(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doGet
in classorg.apache.sling.api.servlets.SlingSafeMethodsServlet
- Throws:
javax.servlet.ServletException
IOException
-
doPost
protected void doPost(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doPost
in classorg.apache.sling.api.servlets.SlingAllMethodsServlet
- Throws:
javax.servlet.ServletException
IOException
-
doPut
protected void doPut(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doPut
in classorg.apache.sling.api.servlets.SlingAllMethodsServlet
- Throws:
javax.servlet.ServletException
IOException
-
doDelete
protected void doDelete(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doDelete
in classorg.apache.sling.api.servlets.SlingAllMethodsServlet
- Throws:
javax.servlet.ServletException
IOException
-
setNoCacheHeaders
public static void setNoCacheHeaders(@NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response)
-
getResource
@NotNull public static @NotNull ResourceHandle getResource(org.apache.sling.api.SlingHttpServletRequest request)
Retrieves the resource using the suffix from the request.- Parameters:
request
- the sling request with the resource path in the suffix- Returns:
- the resource (NOT
null
; returns a handle with an invalid resource if not resolvable)
-
getPath
public static String getPath(org.apache.sling.api.SlingHttpServletRequest request)
-
tryToUseRawSuffix
@NotNull public static @NotNull ResourceHandle tryToUseRawSuffix(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull ResourceHandle resource)
- Returns:
- the given resource if valid, otherwise the resource referenced by the raw suffix (no XSS filter) if such a resource is available - to support select and rename of nodes with invalid names (node repair)
-
jsonAnswerItemExists
protected void jsonAnswerItemExists(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response) throws IOException
- Throws:
IOException
-
jsonValue
public static void jsonValue(com.google.gson.stream.JsonWriter writer, Object value) throws IOException
- Throws:
IOException
-
getJsonObject
public static <T> T getJsonObject(org.apache.sling.api.SlingHttpServletRequest request, Class<T> type) throws IOException
- Throws:
IOException
-
getJsonObject
public static <T> T getJsonObject(org.apache.sling.api.SlingHttpServletRequest request, Class<T> type, com.google.gson.InstanceCreator<T> instanceCreator) throws IOException
- Throws:
IOException
-
-