You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Luciano Resende <lu...@gmail.com> on 2009/10/27 06:22:20 UTC

Calculating servletContextPath, was Re: svn commit: r829733 - /tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

On Mon, Oct 26, 2009 at 2:11 AM,  <an...@apache.org> 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/

Re: Calculating servletContextPath, was Re: svn commit: r829733 - /tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Posted by Luciano Resende <lu...@gmail.com>.
On Wed, Oct 28, 2009 at 1:46 AM, ant elder <an...@apache.org> wrote:
> On Wed, Oct 28, 2009 at 8:15 AM, ant elder <an...@apache.org> wrote:
>> On Wed, Oct 28, 2009 at 4:09 AM, Luciano Resende <lu...@gmail.com> wrote:
>>> On Tue, Oct 27, 2009 at 8:03 AM, ant elder <an...@apache.org> wrote:
>>>> On Tue, Oct 27, 2009 at 2:56 PM, Luciano Resende <lu...@gmail.com> wrote:
>>>>
>>>>
>>>>> I don't see any errors running the build, but any war that I build and
>>>>> then deploy in tomcat fails (e.g the service endpoint is unavailable).
>>>>
>>>> I've tried this on Tomcat too and its working fine for me so it must
>>>> be something more complex and a difference in our environments. Happy
>>>> to help debug if you ping me when you're ready to recreate. Can anyone
>>>> else try one of the webapp samples and see if it is/isn't working for
>>>> you?
>>>>
>>>
>>> I did a quick search on the samples we have today in 2.x and it seems
>>> that we don't have any webapp that is exposing services and all the
>>> wiring and execution are happening on the server. You could check the
>>> sample on the cloud sandbox [1] and try to deploy it to tomcat to see
>>> the problem... I'll be looking into the issue again now as well.
>>>
>>> [1] https://svn.apache.org/repos/asf/tuscany/sandbox/sca-cloud-tutorial/store-catalog-ibmcloud-webapp/
>>>
>>>
>>
>> Looking that app you point to i think it will be caused by the uri in
>> the binding definition:
>>
>>   <tuscany:binding.jsonrpc
>> uri="http://localhost:8080/store-catalog-ibmcloud-webapp/Catalog"/>
>>
>> In the webapp environment we can't set the root of the url so the
>> webapp host just removes it and i expect thats why you end up with the
>> unexpected path. I'll go take a look at the code thats doing the
>> striping of the root to see if it can take account of the duplicated
>> context. But why are you including the uri?
>> <tuscany:binding.jsonrpc/> would be simpler and in 2.x works well now
>> that the computed uri works properly. I believe some SCA runtimes
>> actually throw an error in this situation instead of just ignoring the
>> root so its probably best to not have it when its not really needed.
>>
>>   ...ant
>>
>
> I've traced through the code and that is whats happening. I'm not
> totally convinced we should change this behaviour though and wonder
> wouldn't it be better to just not be having the hardcoded absolute uri
> in the binding? What do people think?
>
>   ...ant
>

Absolute URI works.. I'll just switch the sample app to use that.

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

Re: Calculating servletContextPath, was Re: svn commit: r829733 - /tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Posted by ant elder <an...@apache.org>.
On Wed, Oct 28, 2009 at 8:15 AM, ant elder <an...@apache.org> wrote:
> On Wed, Oct 28, 2009 at 4:09 AM, Luciano Resende <lu...@gmail.com> wrote:
>> On Tue, Oct 27, 2009 at 8:03 AM, ant elder <an...@apache.org> wrote:
>>> On Tue, Oct 27, 2009 at 2:56 PM, Luciano Resende <lu...@gmail.com> wrote:
>>>
>>>
>>>> I don't see any errors running the build, but any war that I build and
>>>> then deploy in tomcat fails (e.g the service endpoint is unavailable).
>>>
>>> I've tried this on Tomcat too and its working fine for me so it must
>>> be something more complex and a difference in our environments. Happy
>>> to help debug if you ping me when you're ready to recreate. Can anyone
>>> else try one of the webapp samples and see if it is/isn't working for
>>> you?
>>>
>>
>> I did a quick search on the samples we have today in 2.x and it seems
>> that we don't have any webapp that is exposing services and all the
>> wiring and execution are happening on the server. You could check the
>> sample on the cloud sandbox [1] and try to deploy it to tomcat to see
>> the problem... I'll be looking into the issue again now as well.
>>
>> [1] https://svn.apache.org/repos/asf/tuscany/sandbox/sca-cloud-tutorial/store-catalog-ibmcloud-webapp/
>>
>>
>
> Looking that app you point to i think it will be caused by the uri in
> the binding definition:
>
>   <tuscany:binding.jsonrpc
> uri="http://localhost:8080/store-catalog-ibmcloud-webapp/Catalog"/>
>
> In the webapp environment we can't set the root of the url so the
> webapp host just removes it and i expect thats why you end up with the
> unexpected path. I'll go take a look at the code thats doing the
> striping of the root to see if it can take account of the duplicated
> context. But why are you including the uri?
> <tuscany:binding.jsonrpc/> would be simpler and in 2.x works well now
> that the computed uri works properly. I believe some SCA runtimes
> actually throw an error in this situation instead of just ignoring the
> root so its probably best to not have it when its not really needed.
>
>   ...ant
>

I've traced through the code and that is whats happening. I'm not
totally convinced we should change this behaviour though and wonder
wouldn't it be better to just not be having the hardcoded absolute uri
in the binding? What do people think?

   ...ant

Re: Calculating servletContextPath, was Re: svn commit: r829733 - /tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Posted by ant elder <an...@apache.org>.
On Wed, Oct 28, 2009 at 4:09 AM, Luciano Resende <lu...@gmail.com> wrote:
> On Tue, Oct 27, 2009 at 8:03 AM, ant elder <an...@apache.org> wrote:
>> On Tue, Oct 27, 2009 at 2:56 PM, Luciano Resende <lu...@gmail.com> wrote:
>>
>>
>>> I don't see any errors running the build, but any war that I build and
>>> then deploy in tomcat fails (e.g the service endpoint is unavailable).
>>
>> I've tried this on Tomcat too and its working fine for me so it must
>> be something more complex and a difference in our environments. Happy
>> to help debug if you ping me when you're ready to recreate. Can anyone
>> else try one of the webapp samples and see if it is/isn't working for
>> you?
>>
>
> I did a quick search on the samples we have today in 2.x and it seems
> that we don't have any webapp that is exposing services and all the
> wiring and execution are happening on the server. You could check the
> sample on the cloud sandbox [1] and try to deploy it to tomcat to see
> the problem... I'll be looking into the issue again now as well.
>
> [1] https://svn.apache.org/repos/asf/tuscany/sandbox/sca-cloud-tutorial/store-catalog-ibmcloud-webapp/
>
>

Looking that app you point to i think it will be caused by the uri in
the binding definition:

   <tuscany:binding.jsonrpc
uri="http://localhost:8080/store-catalog-ibmcloud-webapp/Catalog"/>

In the webapp environment we can't set the root of the url so the
webapp host just removes it and i expect thats why you end up with the
unexpected path. I'll go take a look at the code thats doing the
striping of the root to see if it can take account of the duplicated
context. But why are you including the uri?
<tuscany:binding.jsonrpc/> would be simpler and in 2.x works well now
that the computed uri works properly. I believe some SCA runtimes
actually throw an error in this situation instead of just ignoring the
root so its probably best to not have it when its not really needed.

   ...ant

Re: Calculating servletContextPath, was Re: svn commit: r829733 - /tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Posted by Luciano Resende <lu...@gmail.com>.
On Tue, Oct 27, 2009 at 8:03 AM, ant elder <an...@apache.org> wrote:
> On Tue, Oct 27, 2009 at 2:56 PM, Luciano Resende <lu...@gmail.com> wrote:
>
>
>> I don't see any errors running the build, but any war that I build and
>> then deploy in tomcat fails (e.g the service endpoint is unavailable).
>
> I've tried this on Tomcat too and its working fine for me so it must
> be something more complex and a difference in our environments. Happy
> to help debug if you ping me when you're ready to recreate. Can anyone
> else try one of the webapp samples and see if it is/isn't working for
> you?
>

I did a quick search on the samples we have today in 2.x and it seems
that we don't have any webapp that is exposing services and all the
wiring and execution are happening on the server. You could check the
sample on the cloud sandbox [1] and try to deploy it to tomcat to see
the problem... I'll be looking into the issue again now as well.

[1] https://svn.apache.org/repos/asf/tuscany/sandbox/sca-cloud-tutorial/store-catalog-ibmcloud-webapp/

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

Re: Calculating servletContextPath, was Re: svn commit: r829733 - /tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Posted by ant elder <an...@apache.org>.
On Tue, Oct 27, 2009 at 2:56 PM, Luciano Resende <lu...@gmail.com> wrote:


> I don't see any errors running the build, but any war that I build and
> then deploy in tomcat fails (e.g the service endpoint is unavailable).

I've tried this on Tomcat too and its working fine for me so it must
be something more complex and a difference in our environments. Happy
to help debug if you ping me when you're ready to recreate. Can anyone
else try one of the webapp samples and see if it is/isn't working for
you?

   ...ant

Re: Calculating servletContextPath, was Re: svn commit: r829733 - /tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Posted by Luciano Resende <lu...@gmail.com>.
On Tue, Oct 27, 2009 at 1:36 AM, ant elder <an...@gmail.com> wrote:
>> 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?
>

Removing changes from r829733 makes things working for me again.

> 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?
>

I don't see any errors running the build, but any war that I build and
then deploy in tomcat fails (e.g the service endpoint is unavailable).
You probably won't see the issue in standalone applications as they
don't use the context root. I can try to give you more details little
later today, as I'd need to revert some local changes to be able to
reproduce the problem again and I'm trying to solve a new classLoading
issue so my app can work again.


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

Re: Calculating servletContextPath, was Re: svn commit: r829733 - /tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Posted by ant elder <an...@gmail.com>.
On Tue, Oct 27, 2009 at 5:22 AM, Luciano Resende <lu...@gmail.com> wrote:
> On Mon, Oct 26, 2009 at 2:11 AM,  <an...@apache.org> 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