You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Hammant <pa...@hammant.org> on 2013/06/29 14:51:51 UTC
Help with crossContext="true" and getRequestDispatcher()
If you edit conf/context.xml and add crossContext="true", one Tomcat
mounted web-app should be able to forward to (or include content from)
another in the same request.
I can't get it working and I have a minimal Github project (
https://github.com/paul-hammant/servletDispatcherTest) that shows how far I
got. It has 'a' and 'b' as web-apps (war files) and simple five line
servlets showing the code, attempting to use
// in 'a' webapp servlet filter ...
ServletContext context =
httpsr.getSession().getServletContext().getContext("/b");
RequestDispatcher requestDispatcher =
context.getRequestDispatcher("/anything");
requestDispatcher.include(request, response);
// gives .. The requested resource (/b/anything) is not available
// If it were not for crossContext="true", there would be a n NPE.
I'm looking for a whole example of this working. I mean a downloadable and
buildable zip of a project somewhere on the web. Obviously I've tried
google searching for that. I've also looked in Tomcat's source and can't
see and example or integration test for crossContext :-(
- Paul
Re: Help with crossContext="true" and getRequestDispatcher()
Posted by Paul Hammant <pa...@hammant.org>.
Thanks Mark.
The crucial piece that I missed was the filter-mapping for the
to-be-included thing had to have
<dispatcher>INCLUDE</dispatcher>
Now that it's all working, I updated the Github repo to be a demonstration
of it all working, rather than a problem definition.
- Paul
On Tue, Jul 2, 2013 at 2:42 AM, Mark Thomas <ma...@apache.org> wrote:
> On 02/07/2013 03:28, Paul Hammant wrote:
> > Hi Mark, thanks for the reply.
> >
> > I've modified https://github.com/paul-hammant/servletDispatcherTest to
> > include scripts to reproduce the problem, and to show the two web-apps
> > working separately, but not in the getRequestDispatcher(..).include(..)
> way.
> >
> > The scripts download an anointed version of Tomcat7, add
> > the crossContext="true" attr to context.xml, and even copy the war files
> > into the webapps/ folder.
> >
> > In the README.md, which Github kindly renders into HTML on the front page
> > of the project, there's instructions to build/deploy, as well as what
> URLs
> > to click on to see the problem, as I see it.
> >
> > There are now three servlet-filters activated for different urls:
> >
> > /a/IOutputMyThreadID (class of same name)
> > /a/AIncludingContentFromB (class of same name, extends
> IOutputMyThreadID)
> > /b/IAlsoOutputMyThreadID (class of same name)
>
> There is no Tomcat bug here. The bug is in the test case.
>
> Since the test is for Tomcat 7, see the following sections of the
> Servlet 3.0 specification for an explanation:
> - section 6.2.5
> - section 9.1
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Help with crossContext="true" and getRequestDispatcher()
Posted by Mark Thomas <ma...@apache.org>.
On 02/07/2013 03:28, Paul Hammant wrote:
> Hi Mark, thanks for the reply.
>
> I've modified https://github.com/paul-hammant/servletDispatcherTest to
> include scripts to reproduce the problem, and to show the two web-apps
> working separately, but not in the getRequestDispatcher(..).include(..) way.
>
> The scripts download an anointed version of Tomcat7, add
> the crossContext="true" attr to context.xml, and even copy the war files
> into the webapps/ folder.
>
> In the README.md, which Github kindly renders into HTML on the front page
> of the project, there's instructions to build/deploy, as well as what URLs
> to click on to see the problem, as I see it.
>
> There are now three servlet-filters activated for different urls:
>
> /a/IOutputMyThreadID (class of same name)
> /a/AIncludingContentFromB (class of same name, extends IOutputMyThreadID)
> /b/IAlsoOutputMyThreadID (class of same name)
There is no Tomcat bug here. The bug is in the test case.
Since the test is for Tomcat 7, see the following sections of the
Servlet 3.0 specification for an explanation:
- section 6.2.5
- section 9.1
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Help with crossContext="true" and getRequestDispatcher()
Posted by Paul Hammant <pa...@hammant.org>.
Hi Mark, thanks for the reply.
I've modified https://github.com/paul-hammant/servletDispatcherTest to
include scripts to reproduce the problem, and to show the two web-apps
working separately, but not in the getRequestDispatcher(..).include(..) way.
The scripts download an anointed version of Tomcat7, add
the crossContext="true" attr to context.xml, and even copy the war files
into the webapps/ folder.
In the README.md, which Github kindly renders into HTML on the front page
of the project, there's instructions to build/deploy, as well as what URLs
to click on to see the problem, as I see it.
There are now three servlet-filters activated for different urls:
/a/IOutputMyThreadID (class of same name)
/a/AIncludingContentFromB (class of same name, extends IOutputMyThreadID)
/b/IAlsoOutputMyThreadID (class of same name)
- Paul
On Mon, Jul 1, 2013 at 2:34 PM, Mark Thomas <ma...@apache.org> wrote:
> On 29/06/2013 13:51, Paul Hammant wrote:
> > If you edit conf/context.xml and add crossContext="true", one Tomcat
> > mounted web-app should be able to forward to (or include content from)
> > another in the same request.
> >
> > I can't get it working and I have a minimal Github project (
> > https://github.com/paul-hammant/servletDispatcherTest) that shows how
> far I
> > got. It has 'a' and 'b' as web-apps (war files) and simple five line
> > servlets showing the code, attempting to use
> >
> > // in 'a' webapp servlet filter ...
> > ServletContext context =
> > httpsr.getSession().getServletContext().getContext("/b");
> > RequestDispatcher requestDispatcher =
> > context.getRequestDispatcher("/anything");
> > requestDispatcher.include(request, response);
> > // gives .. The requested resource (/b/anything) is not available
> > // If it were not for crossContext="true", there would be a n NPE.
>
> The test only uses filters. My suspicion (since you haven't provided any
> Tomcat config details) is that the mapper is failing to map the request
> to a Servlet and that triggers the not available error.
>
> > I'm looking for a whole example of this working. I mean a downloadable
> and
> > buildable zip of a project somewhere on the web. Obviously I've tried
> > google searching for that. I've also looked in Tomcat's source and can't
> > see and example or integration test for crossContext :-(
>
> It is tested by the Servlet 3 TCK (which every release of Tomcat 7 has
> passed).
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: Help with crossContext="true" and getRequestDispatcher()
Posted by Mark Thomas <ma...@apache.org>.
On 29/06/2013 13:51, Paul Hammant wrote:
> If you edit conf/context.xml and add crossContext="true", one Tomcat
> mounted web-app should be able to forward to (or include content from)
> another in the same request.
>
> I can't get it working and I have a minimal Github project (
> https://github.com/paul-hammant/servletDispatcherTest) that shows how far I
> got. It has 'a' and 'b' as web-apps (war files) and simple five line
> servlets showing the code, attempting to use
>
> // in 'a' webapp servlet filter ...
> ServletContext context =
> httpsr.getSession().getServletContext().getContext("/b");
> RequestDispatcher requestDispatcher =
> context.getRequestDispatcher("/anything");
> requestDispatcher.include(request, response);
> // gives .. The requested resource (/b/anything) is not available
> // If it were not for crossContext="true", there would be a n NPE.
The test only uses filters. My suspicion (since you haven't provided any
Tomcat config details) is that the mapper is failing to map the request
to a Servlet and that triggers the not available error.
> I'm looking for a whole example of this working. I mean a downloadable and
> buildable zip of a project somewhere on the web. Obviously I've tried
> google searching for that. I've also looked in Tomcat's source and can't
> see and example or integration test for crossContext :-(
It is tested by the Servlet 3 TCK (which every release of Tomcat 7 has
passed).
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org