public class WebResourceUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.Map<java.lang.String,com.google.common.net.MediaType> |
IMAGE_FORMAT_MIME_TYPES |
Constructor and Description |
---|
WebResourceUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
applyJsonResponse(ManagementContext mgmt,
javax.ws.rs.core.Response source,
javax.servlet.http.HttpServletResponse target)
Sets the
HttpServletResponse target (last argument) from the given source Response ;
useful in filters where we might have a Response and need to set up an HttpServletResponse . |
static javax.ws.rs.WebApplicationException |
badRequest(java.lang.String format,
java.lang.Object... args) |
static javax.ws.rs.WebApplicationException |
badRequest(java.lang.Throwable t) |
static javax.ws.rs.WebApplicationException |
badRequest(java.lang.Throwable t,
java.lang.String prefix,
java.lang.Object... prefixArgs) |
static javax.ws.rs.WebApplicationException |
forbidden(java.lang.String format,
java.lang.Object... args) |
static javax.ws.rs.core.MediaType |
getImageMediaTypeFromExtension(java.lang.String extension) |
static java.lang.String |
getPathFromVersionedId(java.lang.String versionedId) |
static java.lang.Object |
getValueForDisplay(java.lang.Object value,
boolean preferJson,
boolean isJerseyReturnValue)
as
getValueForDisplay(ObjectMapper, Object, boolean, boolean) with no mapper
(so will only handle a subset of types) |
static java.lang.Object |
getValueForDisplay(com.fasterxml.jackson.databind.ObjectMapper mapper,
java.lang.Object value,
boolean preferJson,
boolean isJerseyReturnValue)
returns an object which jersey will handle nicely, converting to json,
sometimes wrapping in quotes if needed (for outermost json return types);
if json is not preferred, this simply applies a toString-style rendering
|
static javax.ws.rs.WebApplicationException |
notFound(java.lang.String format,
java.lang.Object... args) |
static javax.ws.rs.WebApplicationException |
preconditionFailed(java.lang.String format,
java.lang.Object... args) |
static javax.ws.rs.core.UriBuilder |
resourceUriBuilder(javax.ws.rs.core.UriBuilder baseUriBuilder,
java.lang.Class<?> resourceClass)
Provides a builder with the REST URI of a resource.
|
static javax.ws.rs.WebApplicationException |
serverError(java.lang.String format,
java.lang.Object... args) |
static javax.ws.rs.core.UriBuilder |
serviceAbsoluteUriBuilder(javax.ws.rs.core.UriBuilder baseUriBuilder,
java.lang.Class<?> resourceClass,
java.lang.String method)
Provides a builder with the absolute REST URI of a service provided by a resource.
|
static javax.ws.rs.core.UriBuilder |
serviceUriBuilder(javax.ws.rs.core.UriBuilder baseUriBuilder,
java.lang.Class<?> resourceClass,
java.lang.String method)
Provides a builder with the REST URI of a service provided by a resource.
|
static javax.ws.rs.WebApplicationException |
throwWebApplicationException(javax.ws.rs.core.Response.Status status,
java.lang.String format,
java.lang.Object... args) |
static javax.ws.rs.WebApplicationException |
throwWebApplicationException(javax.ws.rs.core.Response.Status status,
java.lang.Throwable exception) |
static javax.ws.rs.WebApplicationException |
throwWebApplicationException(javax.ws.rs.core.Response.Status status,
java.lang.Throwable exception,
java.lang.String format,
java.lang.Object... args) |
static javax.ws.rs.WebApplicationException |
unauthorized(java.lang.String format,
java.lang.Object... args) |
public static final java.util.Map<java.lang.String,com.google.common.net.MediaType> IMAGE_FORMAT_MIME_TYPES
public static javax.ws.rs.WebApplicationException throwWebApplicationException(javax.ws.rs.core.Response.Status status, java.lang.String format, java.lang.Object... args)
javax.ws.rs.WebApplicationException
- with an ApiError as its body and the given status as its response code.public static javax.ws.rs.WebApplicationException throwWebApplicationException(javax.ws.rs.core.Response.Status status, java.lang.Throwable exception)
javax.ws.rs.WebApplicationException
- with an ApiError as its body and the given status as its response code.public static javax.ws.rs.WebApplicationException throwWebApplicationException(javax.ws.rs.core.Response.Status status, java.lang.Throwable exception, java.lang.String format, java.lang.Object... args)
javax.ws.rs.WebApplicationException
- with an ApiError as its body and the given status as its response code.
Exception and/or format can be null, and will be filled in / prefixed as appropriate.public static javax.ws.rs.WebApplicationException serverError(java.lang.String format, java.lang.Object... args)
javax.ws.rs.WebApplicationException
- With code 500 internal server errorpublic static javax.ws.rs.WebApplicationException badRequest(java.lang.String format, java.lang.Object... args)
javax.ws.rs.WebApplicationException
- With code 400 bad requestpublic static javax.ws.rs.WebApplicationException badRequest(java.lang.Throwable t)
javax.ws.rs.WebApplicationException
- With code 400 bad requestpublic static javax.ws.rs.WebApplicationException badRequest(java.lang.Throwable t, java.lang.String prefix, java.lang.Object... prefixArgs)
javax.ws.rs.WebApplicationException
- With code 400 bad requestpublic static javax.ws.rs.WebApplicationException unauthorized(java.lang.String format, java.lang.Object... args)
javax.ws.rs.WebApplicationException
- With code 401 unauthorizedpublic static javax.ws.rs.WebApplicationException forbidden(java.lang.String format, java.lang.Object... args)
javax.ws.rs.WebApplicationException
- With code 403 forbiddenpublic static javax.ws.rs.WebApplicationException notFound(java.lang.String format, java.lang.Object... args)
javax.ws.rs.WebApplicationException
- With code 404 not foundpublic static javax.ws.rs.WebApplicationException preconditionFailed(java.lang.String format, java.lang.Object... args)
javax.ws.rs.WebApplicationException
- With code 412 precondition failedpublic static javax.ws.rs.core.MediaType getImageMediaTypeFromExtension(java.lang.String extension)
public static java.lang.Object getValueForDisplay(java.lang.Object value, boolean preferJson, boolean isJerseyReturnValue)
getValueForDisplay(ObjectMapper, Object, boolean, boolean)
with no mapper
(so will only handle a subset of types)public static java.lang.Object getValueForDisplay(com.fasterxml.jackson.databind.ObjectMapper mapper, java.lang.Object value, boolean preferJson, boolean isJerseyReturnValue)
public static java.lang.String getPathFromVersionedId(java.lang.String versionedId)
public static void applyJsonResponse(ManagementContext mgmt, javax.ws.rs.core.Response source, javax.servlet.http.HttpServletResponse target) throws java.io.IOException
HttpServletResponse
target (last argument) from the given source Response
;
useful in filters where we might have a Response
and need to set up an HttpServletResponse
.java.io.IOException
public static javax.ws.rs.core.UriBuilder resourceUriBuilder(javax.ws.rs.core.UriBuilder baseUriBuilder, java.lang.Class<?> resourceClass)
baseUriBuilder
- An UriBuilder
pointing at the base of the REST API.resourceClass
- The target resource class.UriBuilder
that targets the specified REST resource.public static javax.ws.rs.core.UriBuilder serviceUriBuilder(javax.ws.rs.core.UriBuilder baseUriBuilder, java.lang.Class<?> resourceClass, java.lang.String method)
baseUriBuilder
- An UriBuilder
pointing at the base of the REST API.resourceClass
- The target resource class.method
- The target service (e.g. class method).UriBuilder
that targets the specified service of the REST resource.public static javax.ws.rs.core.UriBuilder serviceAbsoluteUriBuilder(javax.ws.rs.core.UriBuilder baseUriBuilder, java.lang.Class<?> resourceClass, java.lang.String method)
baseUriBuilder
- An UriBuilder
pointing at the base of the REST API.resourceClass
- The target resource class.method
- The target service (e.g. class method).UriBuilder
that targets the specified service of the REST resource.