Class JsonWithPaddingInterceptor
- java.lang.Object
-
- org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor
-
- All Implemented Interfaces:
javax.ws.rs.ext.WriterInterceptor
@Priority(4100) public class JsonWithPaddingInterceptor extends java.lang.Object implements javax.ws.rs.ext.WriterInterceptorAWriterInterceptorimplementation for JSONP format. This interceptor wraps a JSON stream obtained by a underlying JSON provider into a callback function that can be defined by theJSONPannotation.- See Also:
JSONP
-
-
Field Summary
Fields Modifier and Type Field Description private javax.inject.Provider<ContainerRequest>containerRequestProviderprivate static java.util.Map<java.lang.String,java.util.Set<java.lang.String>>JAVASCRIPT_TYPES
-
Constructor Summary
Constructors Constructor Description JsonWithPaddingInterceptor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext context)private java.lang.StringgetCallbackName(JSONP jsonp)Returns a JavaScript callback name to wrap the JSON entity into.private JSONPgetJsonpAnnotation(javax.ws.rs.ext.InterceptorContext context)Returns aJSONPannotation of the resource method responsible for handling the current request.private booleanisJavascript(javax.ws.rs.core.MediaType mediaType)Returns a flag whether the givenmedia typebelongs to the group of JavaScript media types.
-
-
-
Field Detail
-
JAVASCRIPT_TYPES
private static final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> JAVASCRIPT_TYPES
-
containerRequestProvider
@Inject private javax.inject.Provider<ContainerRequest> containerRequestProvider
-
-
Method Detail
-
aroundWriteTo
public void aroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext context) throws java.io.IOException, javax.ws.rs.WebApplicationException- Specified by:
aroundWriteToin interfacejavax.ws.rs.ext.WriterInterceptor- Throws:
java.io.IOExceptionjavax.ws.rs.WebApplicationException
-
isJavascript
private boolean isJavascript(javax.ws.rs.core.MediaType mediaType)
Returns a flag whether the givenmedia typebelongs to the group of JavaScript media types.- Parameters:
mediaType- media type to check.- Returns:
trueif the given media type is a JavaScript type,falseotherwise (or if the media type isnull}
-
getCallbackName
private java.lang.String getCallbackName(JSONP jsonp)
Returns a JavaScript callback name to wrap the JSON entity into. The callback name is determined from theJSONPannotation.- Parameters:
jsonp-JSONPannotation to determine the callback name from.- Returns:
- a JavaScript callback name.
-
getJsonpAnnotation
private JSONP getJsonpAnnotation(javax.ws.rs.ext.InterceptorContext context)
Returns aJSONPannotation of the resource method responsible for handling the current request.- Parameters:
context- aninterceptor contextto obtain the annotation from.- Returns:
JSONPannotation ornullif the resource method is not annotated with this annotation.- See Also:
InterceptorContext.getAnnotations()
-
-