You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Abhi <ab...@gmail.com> on 2008/12/01 12:36:26 UTC

Resin to Tomcat migration(context name is null)

I am trying to migrate my application from Resin to Tomcat 6.0.18. The
application runs fine, but my application context name(the context is
created) is coming as null in Tomcat. I tried using context.xml but still I
am facing the same problem.

In Resin the equivalent configuration in resin.conf looks like this

<web-app id="/Foo" root-directory="webapps/Foo"/>

Can someone please let me know as to what exactly should I put in
context.xml, where should I place it in Tomcat and should it be called
context.xml or should it be renamed to my web application name?

I tried with the following:

Content of xml file(WAR file is foo.war under webapps folder):

<Context docBase="Foo" >
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

Renamed the file from context.xml to foo.xml.

Placed it in the default conf folder as well as
conf/Catalina/localhost/foo.xml and conf/Catalina/localhost/context.xml

Placed both context.xml as well as foo.xml in my web application META-INF
folder.

None of the above worked.

Also is the context.xml or <webappName>.xml automcatically picked or should
server.xml be informed of this file?
-- 
Cheers,
Abhi

Re: Resin to Tomcat migration(context name is null)

Posted by Abhi <ab...@gmail.com>.
Thanks a ton.

On Mon, Dec 1, 2008 at 6:50 PM, Mikolaj Rydzewski <mi...@ceti.pl> wrote:

> Abhi wrote:
>
>> I apologize for not being clear. The code is in the init method.
>>
>>
> Tomcat 6.x implements Servlet API 2.5. There's appropiate
> ServletContext#getContextPath() method: http://tinyurl.com/5scpfz . So you
> can use it from Filter#init() without any problems.
>
>
> --
> Mikolaj Rydzewski <mi...@ceti.pl>
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Cheers,
Abhi

Re: Resin to Tomcat migration(context name is null)

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Abhi wrote:
> I apologize for not being clear. The code is in the init method.
>   
Tomcat 6.x implements Servlet API 2.5. There's appropiate 
ServletContext#getContextPath() method: http://tinyurl.com/5scpfz . So 
you can use it from Filter#init() without any problems.


-- 
Mikolaj Rydzewski <mi...@ceti.pl>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Resin to Tomcat migration(context name is null)

Posted by Abhi <ab...@gmail.com>.
I apologize for not being clear. The code is in the init method.

On Mon, Dec 1, 2008 at 6:14 PM, André Warnier <aw...@ice-sa.com> wrote:

> Abhi wrote:
>
>> This is an issue with the way getServletContextName() is implemented in
>> Resin and Tomcat. In Tomcat this returns the display-name of the
>> application
>> where as in Resin it returns the URL prefix for the servlet context. Once
>> I
>> added a display name to my web application I am getting the context name
>> in
>> Tomcat.
>>
>> What I actually want is the URL prefix for the servlet context. The method
>> to access this would be httpServletRequest.getContextPath(). But I want to
>> access this in a filter.
>>
>
> And is there any reason why you cannot ?
> I have this in a filter :
>
> public void doFilter(ServletRequest req, ServletResponse resp,
>           FilterChain chain) throws IOException, ServletException {
>
>  HttpServletRequest request = (HttpServletRequest) req;
>  StringBuffer callURL = request.getRequestURL();
> ...
>
> }
> (and I suppose you can also call request.getContextPath())
>
>>
>> Does anybody know a container independent way to do this?
>>
> As far as I know, the above should be.
>
>
>
>
>>
>> On Mon, Dec 1, 2008 at 5:35 PM, Abhi <ab...@gmail.com> wrote:
>>
>>  Thanks Mark.
>>>
>>> I am getting the context name using the session object
>>> session.getServletContext().getServletContextName()
>>>
>>>
>>> On Mon, Dec 1, 2008 at 5:23 PM, Mark Thomas <ma...@apache.org> wrote:
>>>
>>>  Abhi wrote:
>>>>
>>>>> I am trying to migrate my application from Resin to Tomcat 6.0.18. The
>>>>> application runs fine, but my application context name(the context is
>>>>> created) is coming as null in Tomcat.
>>>>>
>>>> How are you getting the context name?
>>>>
>>>>  <web-app id="/Foo" root-directory="webapps/Foo"/>
>>>>>
>>>>> Can someone please let me know as to what exactly should I put in
>>>>> context.xml, where should I place it in Tomcat and should it be called
>>>>> context.xml or should it be renamed to my web application name?
>>>>>
>>>> In this case, you don't need a context.xml file. Just remove it from
>>>> your
>>>> webapp.
>>>>
>>>> If you had needed to use a context.xml file then it should located at
>>>> META-INF/context.xml inside your WAR.
>>>>
>>>> Tomcat will automatically extract it to CATALINA_BASE/conf/<engine
>>>> name>/<host name>/<name of web app>.xml
>>>>
>>>> For a WAR file foo.war in a default install this would be
>>>> CATALINA_BASE/conf/Catalina/localhost/foo.xml
>>>>
>>>> Mark
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To start a new topic, e-mail: users@tomcat.apache.org
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>>>
>>> --
>>> Cheers,
>>> Abhi
>>>
>>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Cheers,
Abhi

Re: Resin to Tomcat migration(context name is null)

Posted by André Warnier <aw...@ice-sa.com>.
Abhi wrote:
> This is an issue with the way getServletContextName() is implemented in
> Resin and Tomcat. In Tomcat this returns the display-name of the application
> where as in Resin it returns the URL prefix for the servlet context. Once I
> added a display name to my web application I am getting the context name in
> Tomcat.
> 
> What I actually want is the URL prefix for the servlet context. The method
> to access this would be httpServletRequest.getContextPath(). But I want to
> access this in a filter.

And is there any reason why you cannot ?
I have this in a filter :

public void doFilter(ServletRequest req, ServletResponse resp,
	   FilterChain chain) throws IOException, ServletException {

   HttpServletRequest request = (HttpServletRequest) req;
   StringBuffer callURL = request.getRequestURL();
...

}
(and I suppose you can also call request.getContextPath())
> 
> Does anybody know a container independent way to do this?
As far as I know, the above should be.


> 
> 
> On Mon, Dec 1, 2008 at 5:35 PM, Abhi <ab...@gmail.com> wrote:
> 
>> Thanks Mark.
>>
>> I am getting the context name using the session object
>> session.getServletContext().getServletContextName()
>>
>>
>> On Mon, Dec 1, 2008 at 5:23 PM, Mark Thomas <ma...@apache.org> wrote:
>>
>>> Abhi wrote:
>>>> I am trying to migrate my application from Resin to Tomcat 6.0.18. The
>>>> application runs fine, but my application context name(the context is
>>>> created) is coming as null in Tomcat.
>>> How are you getting the context name?
>>>
>>>> <web-app id="/Foo" root-directory="webapps/Foo"/>
>>>>
>>>> Can someone please let me know as to what exactly should I put in
>>>> context.xml, where should I place it in Tomcat and should it be called
>>>> context.xml or should it be renamed to my web application name?
>>> In this case, you don't need a context.xml file. Just remove it from your
>>> webapp.
>>>
>>> If you had needed to use a context.xml file then it should located at
>>> META-INF/context.xml inside your WAR.
>>>
>>> Tomcat will automatically extract it to CATALINA_BASE/conf/<engine
>>> name>/<host name>/<name of web app>.xml
>>>
>>> For a WAR file foo.war in a default install this would be
>>> CATALINA_BASE/conf/Catalina/localhost/foo.xml
>>>
>>> Mark
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To start a new topic, e-mail: users@tomcat.apache.org
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>
>> --
>> Cheers,
>> Abhi
>>
> 
> 
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Resin to Tomcat migration(context name is null)

Posted by Abhi <ab...@gmail.com>.
This is an issue with the way getServletContextName() is implemented in
Resin and Tomcat. In Tomcat this returns the display-name of the application
where as in Resin it returns the URL prefix for the servlet context. Once I
added a display name to my web application I am getting the context name in
Tomcat.

What I actually want is the URL prefix for the servlet context. The method
to access this would be httpServletRequest.getContextPath(). But I want to
access this in a filter.

Does anybody know a container independent way to do this?


On Mon, Dec 1, 2008 at 5:35 PM, Abhi <ab...@gmail.com> wrote:

> Thanks Mark.
>
> I am getting the context name using the session object
> session.getServletContext().getServletContextName()
>
>
> On Mon, Dec 1, 2008 at 5:23 PM, Mark Thomas <ma...@apache.org> wrote:
>
>> Abhi wrote:
>> > I am trying to migrate my application from Resin to Tomcat 6.0.18. The
>> > application runs fine, but my application context name(the context is
>> > created) is coming as null in Tomcat.
>>
>> How are you getting the context name?
>>
>> > <web-app id="/Foo" root-directory="webapps/Foo"/>
>> >
>> > Can someone please let me know as to what exactly should I put in
>> > context.xml, where should I place it in Tomcat and should it be called
>> > context.xml or should it be renamed to my web application name?
>>
>> In this case, you don't need a context.xml file. Just remove it from your
>> webapp.
>>
>> If you had needed to use a context.xml file then it should located at
>> META-INF/context.xml inside your WAR.
>>
>> Tomcat will automatically extract it to CATALINA_BASE/conf/<engine
>> name>/<host name>/<name of web app>.xml
>>
>> For a WAR file foo.war in a default install this would be
>> CATALINA_BASE/conf/Catalina/localhost/foo.xml
>>
>> Mark
>>
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
>
> --
> Cheers,
> Abhi
>



-- 
Cheers,
Abhi

Re: Resin to Tomcat migration(context name is null)

Posted by Abhi <ab...@gmail.com>.
Thanks Mark.

I am getting the context name using the session object
session.getServletContext().getServletContextName()

On Mon, Dec 1, 2008 at 5:23 PM, Mark Thomas <ma...@apache.org> wrote:

> Abhi wrote:
> > I am trying to migrate my application from Resin to Tomcat 6.0.18. The
> > application runs fine, but my application context name(the context is
> > created) is coming as null in Tomcat.
>
> How are you getting the context name?
>
> > <web-app id="/Foo" root-directory="webapps/Foo"/>
> >
> > Can someone please let me know as to what exactly should I put in
> > context.xml, where should I place it in Tomcat and should it be called
> > context.xml or should it be renamed to my web application name?
>
> In this case, you don't need a context.xml file. Just remove it from your
> webapp.
>
> If you had needed to use a context.xml file then it should located at
> META-INF/context.xml inside your WAR.
>
> Tomcat will automatically extract it to CATALINA_BASE/conf/<engine
> name>/<host name>/<name of web app>.xml
>
> For a WAR file foo.war in a default install this would be
> CATALINA_BASE/conf/Catalina/localhost/foo.xml
>
> Mark
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
Cheers,
Abhi

Re: Resin to Tomcat migration(context name is null)

Posted by Mark Thomas <ma...@apache.org>.
Abhi wrote:
> I am trying to migrate my application from Resin to Tomcat 6.0.18. The
> application runs fine, but my application context name(the context is
> created) is coming as null in Tomcat.

How are you getting the context name?

> <web-app id="/Foo" root-directory="webapps/Foo"/>
> 
> Can someone please let me know as to what exactly should I put in
> context.xml, where should I place it in Tomcat and should it be called
> context.xml or should it be renamed to my web application name?

In this case, you don't need a context.xml file. Just remove it from your
webapp.

If you had needed to use a context.xml file then it should located at
META-INF/context.xml inside your WAR.

Tomcat will automatically extract it to CATALINA_BASE/conf/<engine
name>/<host name>/<name of web app>.xml

For a WAR file foo.war in a default install this would be
CATALINA_BASE/conf/Catalina/localhost/foo.xml

Mark



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org