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)


-- 
Luciano Resende
http://people.apache.org/~lresende
http://lresende.blogspot.com/

Reply via email to