You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by groupalias v <gr...@gmail.com> on 2009/12/06 23:17:32 UTC

mod_proxy tomcat6 question

Hi,

Hope this is not off-topic on this list.

I am new to tomcat and have recently set up the bridge between apache
and tomcat. I am able to access the pages if I access them directly.
But when one servlet forwards the request to another I get an error.
For example here is what I have in my http.conf file --

<IfModule proxy_module>

ProxyPreserveHost On
ProxyPass               /test/ ajp://127.0.0.1:8009/A/

</IfModule>

I am able to call www.example.com/test/jsp/hi.jsp. The problem happens
when I call a servlet like --  www.example.com/test/hello
The hello is a servlet that sends back hi.jsp by using the following code --

RequestDispatcher req = request.getRequestDispatcher("/jsp/hi.jsp");
req.forward(request, response);

where request and response and the HttpServletRequest and Response respectively.

I get the following error -- The resource /A/jsp/hi.jsp is not available.

Obviously the URL needs to be changed  /A/jsp/hi.jsp to
/test/jsp/hi.jsp and I believe the mo_proxy can be configured to do
this. But I am not able to find it. Can someone point me to the right
direction?

 - Vas

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


Re: mod_proxy tomcat6 question

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vas,

On 12/8/2009 6:58 PM, groupalias v wrote:
> Thanks Chris. I was beginning to realize that myself. It hit me 
> yesterday that session management (though I have not started to deal 
> with it yet) could cause me problems if the apache mount and the 
> webapp do not match.

Not necessarily. If you use ProxyPassReverse (which I noticed that you
/are not/ doing), I think it'll rewrite cookie paths in the HTTP headers
for you. You might run into other problems, though, so I would recommend
that you /not/ munge your URLs when forwarding them through to Tomcat.

> Also having application code that is apache directory aware is not at
> all clean.

It's not that hard to re-name your WAR file, so just do it to match
whatever URL path you've decided to use.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksf3lkACgkQ9CaO5/Lv0PDl8ACdFkkZWZP0jnurU4KacbEjLn+T
NvEAn0LutWICYfFZ+wJL6lnzLX/dIj5H
=Pvza
-----END PGP SIGNATURE-----

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


Re: mod_proxy tomcat6 question

Posted by groupalias v <gr...@gmail.com>.
Thanks Chris. I was beginning to realize that myself. It hit me
yesterday that session management (though I have not started to deal
with it yet) could cause me problems if the apache mount and the
webapp do not match. Also having application code that is apache
directory aware is not at all clean.

- Vas

>>
>> Obviously the URL needs to be changed  /A/jsp/hi.jsp to
>> /test/jsp/hi.jsp and I believe the mo_proxy can be configured to do
>> this.
>
> No, you don't want this. When doing a "forward", everything is internal
> to Tomcat, so the URL should be what Tomcat expects (that is,
> "/A/jsp/hi.jsp"). If you were redirecting, you'd need to use
> /test/jsp/hi.jsp.
>
>> But I am not able to find it. Can someone point me to the right
>> direction?
>
> As Andre (essentially) suggests, maybe you ought to mount /A on /A
> instead of /test.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAksezY8ACgkQ9CaO5/Lv0PAu5wCfV1gn4U9Enj+9veQKM+Sqptd5
> qdUAnjM8Ax3Bqey0/j6GFe/hbUJaSsxB
> =L4zf
> -----END PGP SIGNATURE-----
>

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


Re: mod_proxy tomcat6 question

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vas,

On 12/6/2009 5:17 PM, groupalias v wrote:
> ProxyPass               /test/ ajp://127.0.0.1:8009/A/

[snip]

> I am able to call www.example.com/test/jsp/hi.jsp. The problem happens
> when I call a servlet like --  www.example.com/test/hello
> The hello is a servlet that sends back hi.jsp by using the following code --
> 
> RequestDispatcher req = request.getRequestDispatcher("/jsp/hi.jsp");
> req.forward(request, response);
> 
> where request and response and the HttpServletRequest and Response respectively.
> 
> I get the following error -- The resource /A/jsp/hi.jsp is not available.
> 
> Obviously the URL needs to be changed  /A/jsp/hi.jsp to
> /test/jsp/hi.jsp and I believe the mo_proxy can be configured to do
> this.

No, you don't want this. When doing a "forward", everything is internal
to Tomcat, so the URL should be what Tomcat expects (that is,
"/A/jsp/hi.jsp"). If you were redirecting, you'd need to use
/test/jsp/hi.jsp.

> But I am not able to find it. Can someone point me to the right
> direction?

As Andre (essentially) suggests, maybe you ought to mount /A on /A
instead of /test.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksezY8ACgkQ9CaO5/Lv0PAu5wCfV1gn4U9Enj+9veQKM+Sqptd5
qdUAnjM8Ax3Bqey0/j6GFe/hbUJaSsxB
=L4zf
-----END PGP SIGNATURE-----

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


Re: mod_proxy tomcat6 question

Posted by groupalias v <gr...@gmail.com>.
I figured it out. It turns out the module configuration is getting
overwritten by the configuration of another module.  Answers to your
questions inline.

> But what is getting close to off-topic, is being confusing in your
> explanations, to the point of making people wonder what exactly you are
> trying to achieve.

This can be easily explained. I am a C programmer trying to sink my
teeth into Java and webapps and still learning to think in those terms
and terminology :)

I am trying to set up mod_proxy_ajp to bridge apache and tomcat. I did
succeed in being able to call jsps and servlets directly in the webapp
but am running into problems when the servlet sends back a jsp file.

The client will always see the webapp code as residing under /test/
and so any response to the client will need to have the hrefs pointing
to /test. But by using the RequestDispatcher the resource is getting
created as /A/

> What exactly is the layout below your Tomcat /webapps/ directory ?

The webapp is in /webapps/A/ in my tomcat directory.

# ls /webapps/A/
# index.jsp  jsp  META-INF  WEB-INF
# ls /webapps/A/jsp/
# hi.jsp

> Why do you insist on redirecting your calls to that "/webapps/A/" place when
> obviously your servlets or jsp pages live under "/webapps/jsp/" ?

> Why do you think you need a RequestDispatcher ?

Isn't this the way to send a new resource to the client in response to
a invoked servlet? I probably still have a lot to learn but this I
thought is standard.
More so when I talk directly to tomcat over 8080 the RequestDispatcher
code works.

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


Re: mod_proxy tomcat6 question

Posted by André Warnier <aw...@ice-sa.com>.
groupalias v wrote:
> Hi,
> 
> Hope this is not off-topic on this list.

In the principle, it is not.
But what is getting close to off-topic, is being confusing in your 
explanations, to the point of making people wonder what exactly you are 
trying to achieve.

What exactly is the layout below your Tomcat /webapps/ directory ?
(show us a directory structure, showing where your "hi.jsp" page lives).

Why do you insist on redirecting your calls to that "/webapps/A/" place 
when obviously your servlets or jsp pages live under "/webapps/jsp/" ?

Why do you think you need a RequestDispatcher ?



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