-
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
Question: how to change the configuration of ResourceConfig at runtime? #5156
Comments
The key is |
Thank you, I tried to suit the example to my needs:
but when calling
The external command returns HTTP Status 500 with the above root cause. I'm running with Jersey 2.36. Is it necessary to call |
The exception is a known issue. It occurs when one instance of the HK2 is shut down, while particular callbacks of Jersey are not shut down yet (race-condition). The new HK2 is started up, and works without the issues, while the callbacks refer to the old HK2 instance, which reports this exception. The exception (intermittent) should not have any impact on the run, once Jersey starts, it should work fine. If you have a status 500 all the time after the reload, I'd like to see the reproducer. |
No, I do not have 500 all the time after reload. Just the requests that try to reload. Is there a separate GitHub issue for this problem, so I can subscribe to it? I'm not in a hurry to have this functionality working in my project, but when the problem is resolved and a new version is released, I'd like to try again. |
Hm...Would it help just to put that to a try catch block, so that the exception is not propagated to the container that returns 500? |
Hmm, looks like I was wrong. Each subsequent request (after reload) ends up with 500 and the following exception:
I'm attaching a sample project to reproduce the issue. I run it with JDK 11 and Apache Tomcat 8.5.81 as a Jakarta EE 8 web application. After starting, the following endpoint works:
And after the Jersey container is reloaded by the following (ends up with 500 and
the hello world endpoint stops working (ends up with 500 and P.S.: even if supressing the exception solved the problem, I would prefer not to do that. I'm not in a hurry, prefer to do things thoroughly and deploy them without inherent issues. But thank you for trying to help :). |
Thank you for the reproducer. The following makes additional requests work again:
I'll try to dig what's wrong with your solution. |
What I would like is to be able to change the configuration of my singleton ResourceConfig upon external command. Right now, the configuration is locked after initialization and once that happens, it can not be changed. My ResourceConfig class is as follows:
And my web.xml is as follows:
When trying to solve this, I stumbled upon the org.glassfish.jersey.servlet.ServletContainer.reload() method, but couldn't figure out how to obtain the class's instance (injection doesn't work). If I understand correctly, this method will create and initialize a new MyApplication object, and discard the previous one. I think that would achieve what I'm after.
To clarify a little more, I would like to be able to turn monitoring and statistics counting on and off as needed, but perhaps it could be useful for request tracing and other things as well. Originally, my ResourceConfig was not a Singleton and a new instance was created for each request (at least, that was the impression I got), which might also achieve what I'm after, but personally, I consider that needlessly inefficient and wasn't sure about the effects of turning monitoring and statistics on and off (and the correctness of data).
The text was updated successfully, but these errors were encountered: