You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicemix.apache.org by Jean Jacobs <jj...@progress.com> on 2009/05/12 17:59:02 UTC

HTTP ManagedContextManager

Hi,

I'm in the process of adding unit tests for the servicemix-http
component.  One of the classes in this component is called
ManagedContextManager.  It has a method called createContext() to add a
context for a given URL and HTTP processor to the map of managed
contexts.  There is some code in that method that is confusing.
Following is the implementation of the method:

    public synchronized Object createContext(String strUrl,
HttpProcessor processor) throws Exception {
        URI uri = new URI(strUrl);
        String path = uri.getPath();
        if (!path.startsWith("/")) {
            path = path + "/";
        }
        if (!path.endsWith("/")) {
            path = path + "/";
        }
        managedContexts.put(path, processor);
        return path;
    }

Why would one append "/" if the path did not start with "/"?  Couldn't
this possibly lead to a path with "//" at the end?  Is this the intended
behavior?  I searched all of the smx4 code to see where this class is
used and I could not find where it is used.  Is it possible that this
class is not used?

Thanks for your help,

Jean

***********************************************
Jean Jacobs
Software QA Architect
Progress Software Corporation
14 Oak Park Drive
Bedford, MA 01730
jjacobs@progress.com
***********************************************



RE: HTTP ManagedContextManager

Posted by Jean Jacobs <jj...@progress.com>.
Gert,

Thanks for your reply.  I will put in a Jira issue for this and add a patch to fix the problem.

Regards,

Jean 

-----Original Message-----
From: Gert Vanthienen [mailto:gert.vanthienen@gmail.com] 
Sent: Monday, May 18, 2009 9:46 AM
To: dev@servicemix.apache.org
Subject: Re: HTTP ManagedContextManager

Jean,

First of all, thanks for looking into the unit tests and enhancing them!  When deploying ServiceMix stand-alone, it will be running its own Jetty instance but when running in web container, it will use a plain Servlet in the web container to handle the HTTP requests.  The ManagedContextManager is used there to keep track of the HTTP context paths that are being handled by the servlet.

This bit of code here is meant to normalize the context paths, making sure that all of them have the same leading/trailing slashes.  My guess is that this a bug in the codebase and that the code should by trying to add a slash at the beginning if there isn't one yet (like what happens in the HttpConfiguration.setMapping() method).

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/5/12 Jean Jacobs <jj...@progress.com>:
> Hi,
>
> I'm in the process of adding unit tests for the servicemix-http 
> component.  One of the classes in this component is called 
> ManagedContextManager.  It has a method called createContext() to add 
> a context for a given URL and HTTP processor to the map of managed 
> contexts.  There is some code in that method that is confusing.
> Following is the implementation of the method:
>
>    public synchronized Object createContext(String strUrl, 
> HttpProcessor processor) throws Exception {
>        URI uri = new URI(strUrl);
>        String path = uri.getPath();
>        if (!path.startsWith("/")) {
>            path = path + "/";
>        }
>        if (!path.endsWith("/")) {
>            path = path + "/";
>        }
>        managedContexts.put(path, processor);
>        return path;
>    }
>
> Why would one append "/" if the path did not start with "/"?  Couldn't 
> this possibly lead to a path with "//" at the end?  Is this the 
> intended behavior?  I searched all of the smx4 code to see where this 
> class is used and I could not find where it is used.  Is it possible 
> that this class is not used?
>
> Thanks for your help,
>
> Jean
>
> ***********************************************
> Jean Jacobs
> Software QA Architect
> Progress Software Corporation
> 14 Oak Park Drive
> Bedford, MA 01730
> jjacobs@progress.com
> ***********************************************
>
>
>

Re: HTTP ManagedContextManager

Posted by Gert Vanthienen <ge...@gmail.com>.
Jean,

First of all, thanks for looking into the unit tests and enhancing
them!  When deploying ServiceMix stand-alone, it will be running its
own Jetty instance but when running in web container, it will use a
plain Servlet in the web container to handle the HTTP requests.  The
ManagedContextManager is used there to keep track of the HTTP context
paths that are being handled by the servlet.

This bit of code here is meant to normalize the context paths, making
sure that all of them have the same leading/trailing slashes.  My
guess is that this a bug in the codebase and that the code should by
trying to add a slash at the beginning if there isn't one yet (like
what happens in the HttpConfiguration.setMapping() method).

Regards,

Gert Vanthienen
------------------------
Open Source SOA: http://fusesource.com
Blog: http://gertvanthienen.blogspot.com/



2009/5/12 Jean Jacobs <jj...@progress.com>:
> Hi,
>
> I'm in the process of adding unit tests for the servicemix-http
> component.  One of the classes in this component is called
> ManagedContextManager.  It has a method called createContext() to add a
> context for a given URL and HTTP processor to the map of managed
> contexts.  There is some code in that method that is confusing.
> Following is the implementation of the method:
>
>    public synchronized Object createContext(String strUrl,
> HttpProcessor processor) throws Exception {
>        URI uri = new URI(strUrl);
>        String path = uri.getPath();
>        if (!path.startsWith("/")) {
>            path = path + "/";
>        }
>        if (!path.endsWith("/")) {
>            path = path + "/";
>        }
>        managedContexts.put(path, processor);
>        return path;
>    }
>
> Why would one append "/" if the path did not start with "/"?  Couldn't
> this possibly lead to a path with "//" at the end?  Is this the intended
> behavior?  I searched all of the smx4 code to see where this class is
> used and I could not find where it is used.  Is it possible that this
> class is not used?
>
> Thanks for your help,
>
> Jean
>
> ***********************************************
> Jean Jacobs
> Software QA Architect
> Progress Software Corporation
> 14 Oak Park Drive
> Bedford, MA 01730
> jjacobs@progress.com
> ***********************************************
>
>
>