-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jersey doesn't allow to override a built-in ValidationExceptionMapper #3425
Comments
@glassfishrobot Commented |
@glassfishrobot Commented
BTW: How can I attach a sample reproducer app? Funny, I don't have permissions ^^ |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented For some reason I don't know, we hadn't implemented the interface but extended the Jersey implementation: @Provider public class ValidationExceptionHandler extends ValidationExceptionMapper. This is why I also noticed that that class is final now. Changing this to @Provider public class ValidationExceptionHandler implements ExceptionMapper still works in GF 4.1 but no longer in Payara 4.1.1.164, i.e. toResponse(...) is never called. Since Payara bundles all of the modules named by gdemecki in his workaround suggestions (and we also use all of them), none of them would be possible for us. |
@glassfishrobot Commented
and
I didn't really analyze the source code for that modification, I just noticed that those two lines were added in one of the versions > 2.14. Maybe this helps someone knowledgable in the code to find a real fix. |
@glassfishrobot Commented |
@deratzmann Commented |
@zak905 Commented |
@zak905 Commented
it works ! |
@deratzmann Commented import javax.validation.ValidationException; |
@zak905 Commented |
@zak905 Commented |
@deratzmann Commented |
@zak905 Commented |
@deratzmann Commented This was finally my fix: @priority(Priorities.USER)
} |
|
In my case I use a |
I noticed that registering an instance of custom exception, make this instance actually selected to map the exception. Suppose there's
Which is handy anyway as this mapper is managed by Spring anyway. This had me confused, as since Jersey 2.26, spring integration works by registering endpoint class of the spring bean directly (as described here : #3700) |
Have there been any updates on this? I still cannot get this to work. I've tried to use HK2 to bind my custom exception mapper class to |
@ktalebian can you provide a code sample ? |
The way how This looks like several different issues reported by multiple users, the symptoms are similar, but the cause seems to be different for each report. @bric3 Can you file your own bug with the reproducer using spring? @ktalebian Can you file a new bug with your own reproducer? |
I can at least confirm that registering a provider with |
Sorry for the late reply, I've abandonned JEE webstacks. So I'm not sure how to reproduce this. |
|
That's weird. I will try to dive into debugger to figure this one out on my side. |
From what I can understand from stepping through debugger in my project:
It seems to me that whoever is listed first in the provider list will be selected unless there is deeper logic somewhere else. The TCK test might be a fluke. I can research further with some additional pointers. I am testing on 2.28 since that is what we use in the framework but it doesn't seem like the code changed in develop. |
The exceptionMappers are sorted by the priority first here. So if yours is better (at least |
How do you register the exception mapper? |
Here is a test example that works if the ExceptionMapper is registered into
Try to play with the priority to see the difference. |
For registering it to HK2, similar to the following should work:
|
I register it via Application public Set<Class<?>> getClasses() override. I came down to this part of the code in Providers.java:
This first call only returns two mappers, JsonMappingExceptionMapper and JsonParseExceptionMapper.
So it boils down to I confirm that explicitely registering to HK2 works (only as instance, not as class). |
The classes are registered to HK2 in jersey/core-server/src/main/java/org/glassfish/jersey/server/ResourceModelConfigurator.java Line 185 in 684bbf8
Which in turn calls: jersey/core-common/src/main/java/org/glassfish/jersey/internal/inject/ProviderBinder.java Line 80 in 684bbf8
and it makes sure to use CustomAnnotationsLiteral.INSTANCE :jersey/core-common/src/main/java/org/glassfish/jersey/internal/inject/ProviderBinder.java Line 112 in 684bbf8
Can you sum up a simple reproducer for your case? |
It has something to do with CDI enabelment. I summed up the observations in the reproducer: https://github.com/cen1/jersey-validation-mapper-reproducer Guessing strictly from the jersey logs with respect to both Json* mappers in my custom mapper, mappers that are bound by Jersey CDI component provider are the issue. |
I confirm the bug in Jersey 2.28. It has been fixed in 2.29. |
Will update to 2.29 and re-test. I appreciate the support. |
Confirming, upgrading jersey solved the problem for me. |
Cool, closing the issue. Thanks. |
In attachments you can see a project which uses: Jersey, Weld, Jetty and jersey bean validation module.
The problem is, when I've upgraded Jersey from 2.14 to 2.23.1 my custom exception mapper:
is no longer called - Jersey uses the built-in exception mapper for this exception: org.glassfish.jersey.server.validation.internal.ValidationExceptionMapper and unfortunately I cannot override it.
The problem is strictly related to the Weld integration. Because without dependency to Weld, my custom exception mapper has a higher priority than the one provided by jersey-bean-validation module.
Environment
Windows 7/ Ubuntu 16.04
Oracle JDK 1.7.0_75
Jetty 9.2.13.v20150730
Any Jersey version above 2.14
Affected Versions
[2.23.1]
The text was updated successfully, but these errors were encountered: