@Priority(value=4100)
public class JsonWithPaddingInterceptor
extends java.lang.Object
implements javax.ws.rs.ext.WriterInterceptor
WriterInterceptor
implementation for JSONP format. This interceptor wraps a JSON stream obtained by a underlying
JSON provider into a callback function that can be defined by the JSONP
annotation.JSONP
Modifier and Type | Field and Description |
---|---|
private javax.inject.Provider<ContainerRequest> |
containerRequestProvider |
private static java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
JAVASCRIPT_TYPES |
Constructor and Description |
---|
JsonWithPaddingInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
aroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext context) |
private java.lang.String |
getCallbackName(JSONP jsonp)
Returns a JavaScript callback name to wrap the JSON entity into.
|
private JSONP |
getJsonpAnnotation(javax.ws.rs.ext.InterceptorContext context)
Returns a
JSONP annotation of the resource method responsible for handling the current request. |
private boolean |
isJavascript(javax.ws.rs.core.MediaType mediaType)
Returns a flag whether the given
media type belongs to the group of JavaScript media types. |
private static final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> JAVASCRIPT_TYPES
@Inject private javax.inject.Provider<ContainerRequest> containerRequestProvider
public void aroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext context) throws java.io.IOException, javax.ws.rs.WebApplicationException
aroundWriteTo
in interface javax.ws.rs.ext.WriterInterceptor
java.io.IOException
javax.ws.rs.WebApplicationException
private boolean isJavascript(javax.ws.rs.core.MediaType mediaType)
media type
belongs to the group of JavaScript media types.mediaType
- media type to check.true
if the given media type is a JavaScript type, false
otherwise (or if the media type is
null
}private java.lang.String getCallbackName(JSONP jsonp)
JSONP
annotation.jsonp
- JSONP
annotation to determine the callback name from.private JSONP getJsonpAnnotation(javax.ws.rs.ext.InterceptorContext context)
JSONP
annotation of the resource method responsible for handling the current request.context
- an interceptor context
to obtain the annotation from.JSONP
annotation or null
if the resource method is not annotated with this annotation.InterceptorContext.getAnnotations()