Skip to content
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

Ability to inject ServletContext into Application constructor #2456

Closed
jerseyrobot opened this issue Oct 31, 2013 · 9 comments
Closed

Ability to inject ServletContext into Application constructor #2456

jerseyrobot opened this issue Oct 31, 2013 · 9 comments

Comments

@jerseyrobot
Copy link
Contributor

Jersey runs on top of ServletContainer. We should be able to pass servlet init parameters using web.xml and read them from Application by injecting ServletContext and using ServletContext.getInitParameter(). Currently, injecting @context ServletContext into Application's constructor results in a null value.

Affected Versions

[2.4]

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Reported by cowwoc

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Issue-Links:
is related to
JERSEY-1950

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
@mpotociar said:
Reclassifying as bug. Spec mandates support for injection of ServletContext into JAX-RS components. (I am not 100% sure if it does not somehow exclude Application from the injectable list, but cannot see a reason why it would.)

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
cowwoc said:
This issue is loosely related to #2531. We should be able to inject values using ServletContext for both production and unit tests.

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
q3aiml said:
I notice you've already started on this so I may be late, but I was interested in seeing this fixed so I took a look a few days ago.

It seems as if this is caused by the provider of the ServletContext binding, WebComponentBinder, not taking effect until resourceConfig.configureMetaProviders. Unfortunately configureMetaProviders is called after the creation of the Application even though the registration of the binder, which seems to only stick it somewhere for holding, happens before.

A second call to configureMetaProviders before the creation of the application does fix the injection, but I don't understand the binder registration and other things well enough to know if it breaks anything else by calling it twice. Maybe if the Application tries to override some existing built-in injection? All tests as part of the normal build still pass, though.

--- a/core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java
+++ b/core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java
@@ -276,6 +276,7 @@ public final class ApplicationHandler {
         if (application instanceof ResourceConfig) {
             final ResourceConfig rc = (ResourceConfig) application;
             if (rc.getApplicationClass() != null) {
+               rc.configureMetaProviders(locator);
 rc.setApplication(createApplication(rc.getApplicationClass()));
             }
         }

I suppose similar would need to also be done for the other constructor.

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
@AdamLindenthal said:
Fixed, integration test has been added (tests/integration/jersey2184).

@q3aiml: thanks a lot, but finally I went for a different fix.

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Marked as fixed on Thursday, December 12th 2013, 7:03:01 am

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
This issue was imported from java.net JIRA JERSEY-2184

@jerseyrobot
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant