Package dev.galasa.framework.api.common
Class BaseRoute
java.lang.Object
dev.galasa.framework.api.common.BaseRoute
- All Implemented Interfaces:
IRoute
- Direct Known Subclasses:
ProtectedRoute,PublicRoute
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final GalasaGsonprotected org.apache.commons.logging.Log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckJsonElementIsValidJSON(com.google.gson.JsonElement element) Checks the json element to make sure it is not a NULL value or an empty objectprotected booleancheckRequestHasContent(javax.servlet.http.HttpServletRequest request) protected StringgetResponseType(String requestedAcceptTypes, MimeType defaultType, List<MimeType> supportedTypes) javax.servlet.http.HttpServletResponsehandleDeleteRequest(String pathInfo, HttpRequestContext requestContext, javax.servlet.http.HttpServletResponse response) javax.servlet.http.HttpServletResponsehandleGetRequest(String pathInfo, QueryParameters queryParams, HttpRequestContext requestContext, javax.servlet.http.HttpServletResponse response) javax.servlet.http.HttpServletResponsehandlePostRequest(String pathInfo, HttpRequestContext requestContext, javax.servlet.http.HttpServletResponse response) javax.servlet.http.HttpServletResponsehandlePutRequest(String pathInfo, HttpRequestContext requestContext, javax.servlet.http.HttpServletResponse response) protected <T> TparseRequestBody(javax.servlet.http.HttpServletRequest request, Class<T> clazz) Parses a given HTTP request's body into a bean objectprotected voidvalidateAcceptHeader(javax.servlet.http.HttpServletRequest request, MimeType... supportedTypes) Checks if a given HTTP request contains an "Accept" header and if the values of that header are part of the default or the supplied list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.galasa.framework.api.common.IRoute
isActionPermitted
-
Field Details
-
gson
-
logger
protected org.apache.commons.logging.Log logger
-
-
Constructor Details
-
BaseRoute
-
-
Method Details
-
getPathRegex
- Specified by:
getPathRegexin interfaceIRoute
-
getResponseBuilder
-
handleGetRequest
public javax.servlet.http.HttpServletResponse handleGetRequest(String pathInfo, QueryParameters queryParams, HttpRequestContext requestContext, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException, FrameworkException - Specified by:
handleGetRequestin interfaceIRoute- Throws:
javax.servlet.ServletExceptionIOExceptionFrameworkException
-
handlePutRequest
public javax.servlet.http.HttpServletResponse handlePutRequest(String pathInfo, HttpRequestContext requestContext, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException, FrameworkException - Specified by:
handlePutRequestin interfaceIRoute- Throws:
javax.servlet.ServletExceptionIOExceptionFrameworkException
-
handlePostRequest
public javax.servlet.http.HttpServletResponse handlePostRequest(String pathInfo, HttpRequestContext requestContext, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException, FrameworkException - Specified by:
handlePostRequestin interfaceIRoute- Throws:
javax.servlet.ServletExceptionIOExceptionFrameworkException
-
handleDeleteRequest
public javax.servlet.http.HttpServletResponse handleDeleteRequest(String pathInfo, HttpRequestContext requestContext, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException, FrameworkException - Specified by:
handleDeleteRequestin interfaceIRoute- Throws:
javax.servlet.ServletExceptionIOExceptionFrameworkException
-
checkRequestHasContent
protected boolean checkRequestHasContent(javax.servlet.http.HttpServletRequest request) throws InternalServletException - Throws:
InternalServletException
-
parseRequestBody
protected <T> T parseRequestBody(javax.servlet.http.HttpServletRequest request, Class<T> clazz) throws IOException, InternalServletException Parses a given HTTP request's body into a bean object- Parameters:
request- the HTTP request to be parsedclazz- the bean class to parse the request body into- Returns:
- the parsed HTTP request body
- Throws:
IOException- if there is an issue reading the request bodyInternalServletException- if the request does not contain a body
-
checkJsonElementIsValidJSON
protected void checkJsonElementIsValidJSON(com.google.gson.JsonElement element) throws InternalServletException Checks the json element to make sure it is not a NULL value or an empty object- Parameters:
element- The json element we want to check- Throws:
InternalServletException- if the json element is empty or null
-
validateAcceptHeader
protected void validateAcceptHeader(javax.servlet.http.HttpServletRequest request, MimeType... supportedTypes) throws InternalServletException Checks if a given HTTP request contains an "Accept" header and if the values of that header are part of the default or the supplied list. If no supported types are given, then "application/json" will be assumed as the default supported type.- Parameters:
request- the HTTP request to be validatedsupportedTypes- the MIME types that are supported by the route- Throws:
InternalServletException- if an unsupported Accept header value was provided
-
getResponseType
protected String getResponseType(String requestedAcceptTypes, MimeType defaultType, List<MimeType> supportedTypes) throws InternalServletException - Throws:
InternalServletException
-
getSupportedQueryParameterNames
- Specified by:
getSupportedQueryParameterNamesin interfaceIRoute- Returns:
- A set of query parameter names which are supported by this route. Any extra parameters will be reported as an error.
-