eclipse-ee4j / eclipse-ee4j/jersey
JSONP annotation not support custom ExceptionMapper ?
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
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.
```java
@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
```java
private Response invoke(final RequestProcessingContext context, final Object resource) {
Response jaxrsResponse;
context.triggerEvent(RequestEvent.Type.RESOURCE_METHOD_START);
context.push(new Function() {
@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
```java
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) {
```
Contributor guide
Assessment
This issue has not been assessed yet.