On Tue, Oct 27, 2009 at 5:22 AM, Luciano Resende <[email protected]> wrote: > On Mon, Oct 26, 2009 at 2:11 AM, <[email protected]> wrote: >> Author: antelder >> Date: Mon Oct 26 09:11:58 2009 >> New Revision: 829733 >> >> URL: http://svn.apache.org/viewvc?rev=829733&view=rev >> Log: >> Update to re-register servlets if the servelt host context path is updated. >> Thats necessary of servlets are registered before the context path is >> initialized, which can happene when extensions register servlets during >> startup >> >> Modified: >> >> tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java >> >> Modified: >> tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java >> URL: >> http://svn.apache.org/viewvc/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=829733&r1=829732&r2=829733&view=diff >> ============================================================================== >> --- >> tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java >> (original) >> +++ >> tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java >> Mon Oct 26 09:11:58 2009 >> @@ -25,8 +25,10 @@ >> import java.net.URI; >> import java.net.URL; >> import java.net.UnknownHostException; >> +import java.util.ArrayList; >> import java.util.Collections; >> import java.util.HashMap; >> +import java.util.List; >> import java.util.Map; >> import java.util.logging.Logger; >> >> @@ -229,6 +231,8 @@ >> @SuppressWarnings("unchecked") >> public void initContextPath(ServletConfig config) { >> >> + String oldContextPath = contextPath; >> + >> if >> (Collections.list(config.getInitParameterNames()).contains("contextPath")) { >> contextPath = config.getInitParameter("contextPath"); >> } else { >> @@ -245,6 +249,22 @@ >> } >> >> logger.info("ContextPath: " + contextPath); >> + >> + // if the context path changes after some servlets have been >> registered then >> + // need to reregister them (this can happen if extensions start >> before webapp init) >> + if (!oldContextPath.endsWith(contextPath)) { >> + List<String> oldServletURIs = new ArrayList<String>(); >> + for (String oldServletURI : servlets.keySet()) { >> + if (oldServletURI.startsWith(oldContextPath)) { >> + oldServletURIs.add(oldServletURI); >> + } >> + } >> + for (String oldURI : oldServletURIs) { >> + String ns = contextPath + "/" + >> oldURI.substring(oldContextPath.length()); >> + servlets.put(ns, servlets.remove(oldURI)); >> + } >> + } >> + >> } >> >> void destroy() { > > Could you please explain why we need this ? This breaks webApp in > general for me again, and services URI now have the webapp context > twice (e.g > /store-catalog-ibmcloud-2x-webapp/store-catalog-ibmcloud-2x-webapp/Catalog) > >
If a servlet is registered before WebAppServletHost init has been called then the servlet would be registered using the default context path value (which is "/"), when init does run and updates to the correct contextPath value (eg /store-catalog-ibmcloud-2x-webapp) then the servlet needs to be reregistered on the correct value otherwise its lookups will fail. Are you sure its caused by this bit of code and not the change to the fiddlePath method in r829732 which is also in the area? If you've traced through the code to see this is where its going wrong then can you see how the first "store-catalog-ibmcloud-2x-webapp" is getting in there? That seems odd, is it possible that WebAppServletHost.init is running twice? I've tried the webapp samples in Jetty, Tomcat, in the itest integration, and running standalone, and they're all working properly for me with this, and the Hudson build which is testing running all the webapp samples is working too. How can I recreate what you're doing to debug where its going wrong? There's a log message outputs the contextPath just before that code runs, what does it show the contextPath is? ...ant
