[jboss-jira] [JBoss JIRA] (AS7-4722) META-INF/resources not available until after Servlet initialization is complete
Remy Maucherat (JIRA)
jira-events at lists.jboss.org
Tue May 22 10:15:18 EDT 2012
[ https://issues.jboss.org/browse/AS7-4722?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Remy Maucherat resolved AS7-4722.
---------------------------------
Fix Version/s: 7.2.0.Alpha1
Resolution: Done
Overlay config now moved to AFTER_START_EVENT.
> META-INF/resources not available until after Servlet initialization is complete
> -------------------------------------------------------------------------------
>
> Key: AS7-4722
> URL: https://issues.jboss.org/browse/AS7-4722
> Project: Application Server 7
> Issue Type: Bug
> Components: Web
> Affects Versions: 7.1.1.Final
> Environment: Generic
> Reporter: Eric Sirianni
> Assignee: Remy Maucherat
> Fix For: 7.2.0.Alpha1
>
>
> Using the new modular webapps facility in Servlet 3.0, I have a WAR that includes a component JAR with a servlet definition:
> {code:title=HelloServlet.java}
> @WebServlet(value = "/HelloWorld", loadOnStartup = 1)
> public class HelloServlet extends HttpServlet {
> @Override
> public void init() throws ServletException {
> InputStream stream = getServletContext().getResourceAsStream("/foo.txt");
> System.err.println("foo.txt stream: " + stream);
> }
>
> @Override
> protected void doGet(HttpServletRequest req, HttpServletResponse resp)
> throws ServletException, IOException {
> resp.getOutputStream().print("<h1>Hello World!</h1>");
> }
> }
> {code}
> The JAR also packages a resource inside META-INF/resources (as defined in section 4.6 of the Servlet 3.0 spec)
> {noformat}
> $ jar -tf hello.jar
> com/eric/HelloServlet.class
> META-INF/resources/foo.txt
> {noformat}
> That JAR is incorporated into a WAR, which is then deployed in AS7:
> {noformat}
> $ jar -tf standalone/deployments/hello.war
> WEB-INF/lib/hello.jar
> {noformat}
> The issue is with the ordering in which AS7 processes "overlays" (specifically in org.apache.catalina.core.StandardContext.start()). The "overlay" is what makes the META-INF resource available to the ServletContext. The overlays are added *after* the servlets are initialized (via a listener to the COMPLETE_CONFIG_EVENT):
> {code:title=StandardContext.java}
> // Load and initialize all "load on startup" servlets
> if (ok) {
> loadOnStartup(findChildren());
> }
>
> if (ok) {
> if (!listenerStart()) {
> log.error( "Error listenerStart");
> ok = false;
> }
> }
> if (ok) {
> // Notify our interested LifecycleListeners
> lifecycle.fireLifecycleEvent(COMPLETE_CONFIG_EVENT, null);
> }
> {code}
> Given this, the following behavior is observed:
> *With loadOnStartup=-1* the stream for foo.txt is available
> {noformat}
> 11:44:52,708 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "hello.war"
> 11:44:53,464 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /hello
> 11:44:53,481 INFO [org.jboss.as] (MSC service thread 1-3) JBAS015951: Admin console listening on http://127.0.0.1:9990
> 11:44:53,496 INFO [org.jboss.as] (MSC service thread 1-3) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 4611ms - Started 173 of 250 services (76 services are passive or on-demand)
> 11:44:53,588 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "hello.war"
> 11:45:21,460 ERROR [stderr] (http--127.0.0.1-8080-1) foo.txt stream: java.io.ByteArrayInputStream at 13f0c45f
> {noformat}
> *With loadOnStartup=1* the stream for foo.txt is null
> {noformat}
> 11:43:53,224 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "hello.war"
> 11:43:54,152 ERROR [stderr] (MSC service thread 1-3) foo.txt stream: null
> 11:43:54,174 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /hello
> 11:43:54,189 INFO [org.jboss.as] (MSC service thread 1-4) JBAS015951: Admin console listening on http://127.0.0.1:9990
> {noformat}
> The expected behavior is that resources from overlays be made available prior to servlet initialization for loadOnStartup servlets.
> This is, of course, a toy example, but this presents serious issues when modularizing a large scale web application.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list