Package dev.galasa.framework.api.common
Class BaseRoute
java.lang.Object
dev.galasa.framework.api.common.BaseRoute
- All Implemented Interfaces:
IRoute
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final GalasaGson
protected org.apache.commons.logging.Log
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkJsonElementIsValidJSON
(com.google.gson.JsonElement element) Checks the json element to make sure it is not a NULL value or an empty objectprotected boolean
checkRequestHasContent
(javax.servlet.http.HttpServletRequest request) protected String
getResponseType
(String requestedAcceptTypes, MimeType defaultType, List<MimeType> supportedTypes) javax.servlet.http.HttpServletResponse
handleDeleteRequest
(String pathInfo, QueryParameters queryParameters, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) javax.servlet.http.HttpServletResponse
handleGetRequest
(String pathInfo, QueryParameters queryParams, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) javax.servlet.http.HttpServletResponse
handlePostRequest
(String pathInfo, QueryParameters queryParameters, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) javax.servlet.http.HttpServletResponse
handlePutRequest
(String pathInfo, QueryParameters queryParameters, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) protected <T> T
parseRequestBody
(javax.servlet.http.HttpServletRequest request, Class<T> clazz) Parses a given HTTP request's body into a bean objectprotected void
validateAcceptHeader
(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.
-
Field Details
-
gson
-
logger
protected org.apache.commons.logging.Log logger
-
-
Constructor Details
-
BaseRoute
-
-
Method Details
-
getPathRegex
- Specified by:
getPathRegex
in interfaceIRoute
-
getResponseBuilder
-
handleGetRequest
public javax.servlet.http.HttpServletResponse handleGetRequest(String pathInfo, QueryParameters queryParams, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException, FrameworkException - Specified by:
handleGetRequest
in interfaceIRoute
- Throws:
javax.servlet.ServletException
IOException
FrameworkException
-
handlePutRequest
public javax.servlet.http.HttpServletResponse handlePutRequest(String pathInfo, QueryParameters queryParameters, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException, FrameworkException - Specified by:
handlePutRequest
in interfaceIRoute
- Throws:
javax.servlet.ServletException
IOException
FrameworkException
-
handlePostRequest
public javax.servlet.http.HttpServletResponse handlePostRequest(String pathInfo, QueryParameters queryParameters, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException, FrameworkException - Specified by:
handlePostRequest
in interfaceIRoute
- Throws:
javax.servlet.ServletException
IOException
FrameworkException
-
handleDeleteRequest
public javax.servlet.http.HttpServletResponse handleDeleteRequest(String pathInfo, QueryParameters queryParameters, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException, FrameworkException - Specified by:
handleDeleteRequest
in interfaceIRoute
- Throws:
javax.servlet.ServletException
IOException
FrameworkException
-
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
-