jersey
jersey copied to clipboard
JSONP annotation not support custom ExceptionMapper ?
JSONP annotation do not work when we throw a exception in resource.View the source code, we find the reason is that annotation was lost in exception process.
@GET
@Path("/jsonp")
@ApiOperation(value = "jsonp test", response = User.class)
@JSONP(queryParam = "callback")
@Produces({"application/javascript","application/json"})
public User getUserByName() {
if(1==1){
throw new BizException("abb","abb");
}
return new User(0L, "jsonp", "jsonp");
}
org.glassfish.jersey.server.model.ResourceMethodInvoker#invoke
private Response invoke(final RequestProcessingContext context, final Object resource) {
Response jaxrsResponse;
context.triggerEvent(RequestEvent.Type.RESOURCE_METHOD_START);
context.push(new Function<ContainerResponse, ContainerResponse>() {
@Override
public ContainerResponse apply(final ContainerResponse response) {
// Need to check whether the response is null or mapped from exception. In these cases we don't want to modify
// response with resource method metadata.
if (response == null
|| response.isMappedFromException()) {
return response;
}
final Annotation[] entityAnn = response.getEntityAnnotations();
org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor
public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException {
final boolean isJavascript = isJavascript(context.getMediaType());
final JSONP jsonp = getJsonpAnnotation(context);
final boolean wrapIntoCallback = isJavascript && jsonp != null;
if (wrapIntoCallback) {