Package org.trustdeck.service
Class ResponseService
java.lang.Object
org.trustdeck.service.ResponseService
Handles the responses depending on the response type requested by the user.
- Author:
- Eric Wündisch and Armin Müller
-
Field Summary
FieldsModifier and TypeFieldDescriptionDefines a list of media types that the services is able to respond with. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> org.springframework.http.ResponseEntity<T> badRequest(String mediaType) Bad request (400) response entity.buildContentTypeHeaderStringForResponse(String mediaType) Builds the content type header string for the response.<T> org.springframework.http.ResponseEntity<T> Conflict (409) response entity.<T> org.springframework.http.ResponseEntity<T> Created (201) response entity without a body and without a location.<T> org.springframework.http.ResponseEntity<T> Created (201) response entity without a body and with a location.<T> org.springframework.http.ResponseEntity<T> Created (201) response entity with a body and with a location.<T> org.springframework.http.ResponseEntity<T> Created (201) response entity with a body and without a location.createHttpStatusDtoFromMediaType(org.springframework.http.HttpStatus status, String mediaType) Create a HTTP status DTO taking into account which media type the response should have.createHttpStatusDtoFromRequest(org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request) Create a HTTP status DTO taking the request object into account.<T> org.springframework.http.ResponseEntity<T> Forbidden (403) response entity.getMediaTypeFromRequest(org.springframework.web.context.request.WebRequest request) Retrieves the media type value from the request.getValidMediaType(String mediaType) Checks whether the given media type is valid.<T> org.springframework.http.ResponseEntity<T> Gone (410) response entity.<T> org.springframework.http.ResponseEntity<T> insufficientStorage(String mediaType) Insufficient storage (507) response entity.<T> org.springframework.http.ResponseEntity<T> internalServerError(String mediaType) Internal server error (500) response entity.booleanisMediaTypeSupportedByService(String mediaType) Checks whether or not the provided media type is in the list of supported media types.<T> org.springframework.http.ResponseEntity<T> No content (204) response entity.<T> org.springframework.http.ResponseEntity<T> notAcceptable(String mediaType) Not acceptable (406) response entity.<T> org.springframework.http.ResponseEntity<T> Not found (404) response entity.<T> org.springframework.http.ResponseEntity<T> Ok (200) response entity without a body.org.springframework.http.ResponseEntity<byte[]> Ok (200) response entity with an image in the body.<T> org.springframework.http.ResponseEntity<T> Ok (200) response entity with a body.<T> org.springframework.http.ResponseEntity<T> partialContent(String mediaType, T body) Partial Content (206) response entity with a body.<T> org.springframework.http.ResponseEntity<T> payloadTooLarge(String mediaType) Payload too large (413) response entity.<T> org.springframework.http.ResponseEntity<T> unprocessableEntity(String mediaType) Unprocessable entity (422) response entity.<T> org.springframework.http.ResponseEntity<T> unsupportedMediaType(String mediaType) Unsupported media type (415) response entity.
-
Field Details
-
supportedMediaTypes
Defines a list of media types that the services is able to respond with.
-
-
Constructor Details
-
ResponseService
public ResponseService()
-
-
Method Details
-
isMediaTypeSupportedByService
Checks whether or not the provided media type is in the list of supported media types.- Parameters:
mediaType- the media type- Returns:
- whether the media type is supported or not
-
getValidMediaType
Checks whether the given media type is valid. If not the default preferred media type is returned.- Parameters:
mediaType- the media type to validate- Returns:
- the given media type if it's valid, the preferred media type if not
-
getMediaTypeFromRequest
Retrieves the media type value from the request.- Parameters:
request- the request- Returns:
- the media type value from the request
-
createHttpStatusDtoFromRequest
public Object createHttpStatusDtoFromRequest(org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request) Create a HTTP status DTO taking the request object into account.- Parameters:
status- the HTTP statusrequest- the request- Returns:
- the HTTP status response DTO or an empty string
-
createHttpStatusDtoFromMediaType
public Object createHttpStatusDtoFromMediaType(org.springframework.http.HttpStatus status, String mediaType) Create a HTTP status DTO taking into account which media type the response should have.- Parameters:
status- the HTTP statusmediaType- the media type the response should have- Returns:
- the HTTP status response DTO or an (empty) string
-
buildContentTypeHeaderStringForResponse
Builds the content type header string for the response.- Parameters:
mediaType- the media type- Returns:
- the content type header string for the response
-
notFound
Not found (404) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
badRequest
Bad request (400) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
notAcceptable
Not acceptable (406) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
unprocessableEntity
Unprocessable entity (422) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
internalServerError
Internal server error (500) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
noContent
No content (204) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
conflict
Conflict (409) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
insufficientStorage
Insufficient storage (507) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
ok
Ok (200) response entity without a body.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
ok
Ok (200) response entity with a body.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media typebody- the body- Returns:
- the response entity
-
ok
Ok (200) response entity with an image in the body.- Parameters:
mimeType- the mime type of the imageimage- the image in byte-array representation- Returns:
- the response entity
-
created
Created (201) response entity without a body and without a location.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
created
Created (201) response entity with a body and without a location.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media typebody- the body- Returns:
- the response entity
-
created
Created (201) response entity without a body and with a location.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media typelocation- the location- Returns:
- the response entity
-
created
public <T> org.springframework.http.ResponseEntity<T> created(String mediaType, URI location, T body) Created (201) response entity with a body and with a location.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media typelocation- the locationbody- the body- Returns:
- the response entity
-
forbidden
Forbidden (403) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
partialContent
Partial Content (206) response entity with a body.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media typebody- the body- Returns:
- the response entity
-
gone
Gone (410) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
payloadTooLarge
Payload too large (413) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-
unsupportedMediaType
Unsupported media type (415) response entity.- Type Parameters:
T- the type parameter- Parameters:
mediaType- the media type- Returns:
- the response entity
-