You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by J T <fu...@gmail.com> on 2006/01/30 21:55:00 UTC

Leading slash on forward causes problem in proxied environments

We have four environments: dev, int, stg, and prod. Each of these is fronted
by an apache server
that proxies to our weblogic application server.

The URLs to the apps look like this
(dev) http://devserver.com/dev/Application
(int) http://intserver.com/int/Application
(stg) http://stgserver.com/stg/Application
(prod) http://prodserver.com/Application (no directory)


Two of my actions look like this
<action
   path="/viewMain"
   parameter=".Main"
   name="myForm"
   validate="false"
   type="org.apache.struts.actions.ForwardAction"
   scope="session">
</action>

<action
   path="/processMain"
   name="myForm"
   input=".Main"
   type="com.company.action.ProcessFormAction"
   scope="session"
   validate="true">
    <forward name="success" path="/viewNew.do"/>
</action>


When my jsp is rendered in the dev environment it looks like this…

...
<head>
    <base href="http://devserver.com/Application/jsp/mainLayout.jsp">

...
</head>

...
<form name="myForm" method="POST" action="/Application/processMain.do">
    <input type="text" name="mynbr" value="">
    <input type="submit" value="Submit">
</form>

...

So when I click submit the POST goes to http://devserver.com/Application/
and not http://devserver.com/dev/Application

I don't want to hard code my struts-config since this needs be
deployed to 4 places.

I have read through the mailing list archives and the only viable
solution that I have seen is to create a base action that strips the
leading slash off of the forwards so that the POST goes back to
the right place.

Is there a better way of doing this?

Re: Leading slash on forward causes problem in proxied environments

Posted by J T <fu...@gmail.com>.
That would resolve the problem but it is not an option in our environment.

On 2/4/06, Max Cooper <ma...@maxcooper.com> wrote:
>
> Can you change the contextPaths on your dev, int, and stg servers?
>
> (dev) http://devserver.com/Application
> (int) http://intserver.com/Application
> (stg) http://stgserver.com/Application
> (prod) http://prodserver.com/Application (no directory)
>
> I haven't followed this thread all that closely, but it has been my
> experience that lots of things break when the "content path" (in quotes
> since httpd doesn't know about contextPaths) doesn't match between the
> web server and app server. I think there is a good chance that this
> would fix your problem, and it should be relatively easy to at least
> test it out. It may be easier to solve whatever issues these new context
> paths cause than it is to fix (or forever tip-toe around, with
> mysterious breakages just when you don't need them) the mis-matched
> "context paths".
>
> -Max
>
> On Thu, 2006-02-02 at 16:55 -0800, Michael Jouravlev wrote:
> > AFAIK, <html:base> tag won't help you, it affects only <html:link
> > href="..."> tags. I believe (though I have not verified it) that
> > <html:form> tag uses the same algorithm as <html:link action="...">
> > tag. For actions, base directory is not used. Context is used instead.
> > Server deduces context from incoming URL.
> >
> > * Browser sends request to
> http://appserver.com:6000/Application/something.do
> > * Request is transferred to appserver's
> > http://devserver.com/dev/Application/something.do, which forwards to a
> > page.
> > * Obviously, proxy server sends a new request to an appserver address,
> > therefore URL is changed!
> > * The form tag on a page reads context, gets one from [changed] URL:
> Application
> > * The form tag builds address based on context:
> /Application/processMain.do
> >
> > Now I would like to hear someone with the solution. At least, I seem
> > to understand the problem ;-))
> >
> > Michael
> >
> > On 2/2/06, J T <fu...@gmail.com> wrote:
> > > The jsp code:
> > >
> > > <html:form action="/processMain.do" method="POST">
> > > ...
> > > </html:form>
> > >
> > > When rendered produces the html:
> > >
> > > <form action="/Application/processMain.do" method="POST">
> > > ...
> > > </form>
> > >
> > > My modified form tag produces the code:
> > >
> > > <form action="/dev/Application/processMain.do" method="POST">
> > > ...
> > > </form>
> > >
> > > The application is hosted at
> > >
> > > http://appserver.com:6000/Application/
> > >
> > > but since we are using a apache to proxy requests to the app server
> the end
> > > user sees
> > >
> > > http://devserver.com/dev/Application/
> > >
> > > For what its worth I have had to override the html:link tag to do the
> same
> > > thing my modified form ta g is doing (so my index page links work). I
> would
> > > prefer using the out of the box tag libs but I am not clear how the
> > > combination of html:base and html:link would resolve my problem. Could
> you
> > > provide a specific example?
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Leading slash on forward causes problem in proxied environments

Posted by Max Cooper <ma...@maxcooper.com>.
Can you change the contextPaths on your dev, int, and stg servers?

(dev) http://devserver.com/Application
(int) http://intserver.com/Application
(stg) http://stgserver.com/Application
(prod) http://prodserver.com/Application (no directory)

I haven't followed this thread all that closely, but it has been my
experience that lots of things break when the "content path" (in quotes
since httpd doesn't know about contextPaths) doesn't match between the
web server and app server. I think there is a good chance that this
would fix your problem, and it should be relatively easy to at least
test it out. It may be easier to solve whatever issues these new context
paths cause than it is to fix (or forever tip-toe around, with
mysterious breakages just when you don't need them) the mis-matched
"context paths".

-Max

On Thu, 2006-02-02 at 16:55 -0800, Michael Jouravlev wrote:
> AFAIK, <html:base> tag won't help you, it affects only <html:link
> href="..."> tags. I believe (though I have not verified it) that
> <html:form> tag uses the same algorithm as <html:link action="...">
> tag. For actions, base directory is not used. Context is used instead.
> Server deduces context from incoming URL.
> 
> * Browser sends request to http://appserver.com:6000/Application/something.do
> * Request is transferred to appserver's
> http://devserver.com/dev/Application/something.do, which forwards to a
> page.
> * Obviously, proxy server sends a new request to an appserver address,
> therefore URL is changed!
> * The form tag on a page reads context, gets one from [changed] URL: Application
> * The form tag builds address based on context: /Application/processMain.do
> 
> Now I would like to hear someone with the solution. At least, I seem
> to understand the problem ;-))
> 
> Michael
> 
> On 2/2/06, J T <fu...@gmail.com> wrote:
> > The jsp code:
> >
> > <html:form action="/processMain.do" method="POST">
> > ...
> > </html:form>
> >
> > When rendered produces the html:
> >
> > <form action="/Application/processMain.do" method="POST">
> > ...
> > </form>
> >
> > My modified form tag produces the code:
> >
> > <form action="/dev/Application/processMain.do" method="POST">
> > ...
> > </form>
> >
> > The application is hosted at
> >
> > http://appserver.com:6000/Application/
> >
> > but since we are using a apache to proxy requests to the app server the end
> > user sees
> >
> > http://devserver.com/dev/Application/
> >
> > For what its worth I have had to override the html:link tag to do the same
> > thing my modified form ta g is doing (so my index page links work). I would
> > prefer using the out of the box tag libs but I am not clear how the
> > combination of html:base and html:link would resolve my problem. Could you
> > provide a specific example?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Leading slash on forward causes problem in proxied environments

Posted by Michael Jouravlev <jm...@gmail.com>.
AFAIK, <html:base> tag won't help you, it affects only <html:link
href="..."> tags. I believe (though I have not verified it) that
<html:form> tag uses the same algorithm as <html:link action="...">
tag. For actions, base directory is not used. Context is used instead.
Server deduces context from incoming URL.

* Browser sends request to http://appserver.com:6000/Application/something.do
* Request is transferred to appserver's
http://devserver.com/dev/Application/something.do, which forwards to a
page.
* Obviously, proxy server sends a new request to an appserver address,
therefore URL is changed!
* The form tag on a page reads context, gets one from [changed] URL: Application
* The form tag builds address based on context: /Application/processMain.do

Now I would like to hear someone with the solution. At least, I seem
to understand the problem ;-))

Michael

On 2/2/06, J T <fu...@gmail.com> wrote:
> The jsp code:
>
> <html:form action="/processMain.do" method="POST">
> ...
> </html:form>
>
> When rendered produces the html:
>
> <form action="/Application/processMain.do" method="POST">
> ...
> </form>
>
> My modified form tag produces the code:
>
> <form action="/dev/Application/processMain.do" method="POST">
> ...
> </form>
>
> The application is hosted at
>
> http://appserver.com:6000/Application/
>
> but since we are using a apache to proxy requests to the app server the end
> user sees
>
> http://devserver.com/dev/Application/
>
> For what its worth I have had to override the html:link tag to do the same
> thing my modified form ta g is doing (so my index page links work). I would
> prefer using the out of the box tag libs but I am not clear how the
> combination of html:base and html:link would resolve my problem. Could you
> provide a specific example?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Leading slash on forward causes problem in proxied environments

Posted by J T <fu...@gmail.com>.
The jsp code:

<html:form action="/processMain.do" method="POST">
...
</html:form>

When rendered produces the html:

<form action="/Application/processMain.do" method="POST">
...
</form>

My modified form tag produces the code:

<form action="/dev/Application/processMain.do" method="POST">
...
</form>

The application is hosted at

http://appserver.com:6000/Application/

but since we are using a apache to proxy requests to the app server the end
user sees

http://devserver.com/dev/Application/

For what its worth I have had to override the html:link tag to do the same
thing my modified form ta g is doing (so my index page links work). I would
prefer using the out of the box tag libs but I am not clear how the
combination of html:base and html:link would resolve my problem. Could you
provide a specific example?


----
Someone else with the same issue. I tried modifing my forwardPattern
attribute to no avail.
http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/efabed9f151fbf61/77826e1486db5d87?tvc=1&q=struts+relative+path+not+found&hl=en#77826e1486db5d87

On 2/2/06, Rick Reumann <st...@reumann.net> wrote:
>
> Frank W. Zammetti wrote the following on 2/2/2006 3:33 PM:
> > On Thu, February 2, 2006 3:22 pm, Rick Reumann said:
>
> > I haven't been following this thread, but on this particular point...
> > IIRC, the "context name" is defined as the first part of the URI
> following
> > the host:port/ portion.  So, in the URI
> > http://devserver.com/dev/Application the context name is actually dev,
> and
> > Application is just a path underneath the context.
> >
> > Not sure if this helps any (or even with 100% certainty if I'm right,
> > although this is my recollection).
>
> Good point. Thanks. I see the problem now.
>
>
> --
> Rick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Leading slash on forward causes problem in proxied environments

Posted by Rick Reumann <st...@reumann.net>.
Frank W. Zammetti wrote the following on 2/2/2006 3:33 PM:
> On Thu, February 2, 2006 3:22 pm, Rick Reumann said:

> I haven't been following this thread, but on this particular point...
> IIRC, the "context name" is defined as the first part of the URI following
> the host:port/ portion.  So, in the URI
> http://devserver.com/dev/Application the context name is actually dev, and
> Application is just a path underneath the context.
> 
> Not sure if this helps any (or even with 100% certainty if I'm right,
> although this is my recollection).

Good point. Thanks. I see the problem now.


-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Leading slash on forward causes problem in proxied environments

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Thu, February 2, 2006 3:22 pm, Rick Reumann said:
>
> J T wrote the following on 1/30/2006 3:55 PM:
>> We have four environments: dev, int, stg, and prod. Each of these is
>> fronted
>> by an apache server
>> that proxies to our weblogic application server.
>>
>> The URLs to the apps look like this
>> (dev) http://devserver.com/dev/Application
>> (int) http://intserver.com/int/Application
>> (stg) http://stgserver.com/stg/Application
>> (prod) http://prodserver.com/Application (no directory)
>
> <snip>
>
>> ...
>> <form name="myForm" method="POST" action="/Application/processMain.do">
>>     <input type="text" name="mynbr" value="">
>>     <input type="submit" value="Submit">
>> </form>
>>
>> ...
>>
>> So when I click submit the POST goes to
>> http://devserver.com/Application/
>> and not http://devserver.com/dev/Application
>>
>> I don't want to hard code my struts-config since this needs be
>> deployed to 4 places.
>
> I'm still confused though. Why would your form action be:
>
> action="/processMain.do"> <--- (don't use /Application)
>
> Isn't in this case your appname "Application"? If so I don't see the
> problem. If for example you deploy "Application.war" to those four
> environments, I don't see why the /dev/ part would ever be stripped off.
> Everything before your context name shouldn't be affected by Struts.
>
> I'm probably missing something though:)

I haven't been following this thread, but on this particular point...
IIRC, the "context name" is defined as the first part of the URI following
the host:port/ portion.  So, in the URI
http://devserver.com/dev/Application the context name is actually dev, and
Application is just a path underneath the context.

Not sure if this helps any (or even with 100% certainty if I'm right,
although this is my recollection).

>
> --
> Rick

Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Leading slash on forward causes problem in proxied environments

Posted by Rick Reumann <st...@reumann.net>.
J T wrote the following on 1/30/2006 3:55 PM:
> We have four environments: dev, int, stg, and prod. Each of these is fronted
> by an apache server
> that proxies to our weblogic application server.
> 
> The URLs to the apps look like this
> (dev) http://devserver.com/dev/Application
> (int) http://intserver.com/int/Application
> (stg) http://stgserver.com/stg/Application
> (prod) http://prodserver.com/Application (no directory)

<snip>

> ...
> <form name="myForm" method="POST" action="/Application/processMain.do">
>     <input type="text" name="mynbr" value="">
>     <input type="submit" value="Submit">
> </form>
> 
> ...
> 
> So when I click submit the POST goes to http://devserver.com/Application/
> and not http://devserver.com/dev/Application
> 
> I don't want to hard code my struts-config since this needs be
> deployed to 4 places.

I'm still confused though. Why would your form action be:

action="/processMain.do"> <--- (don't use /Application)

Isn't in this case your appname "Application"? If so I don't see the 
problem. If for example you deploy "Application.war" to those four 
environments, I don't see why the /dev/ part would ever be stripped off. 
Everything before your context name shouldn't be affected by Struts.

I'm probably missing something though:)


-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Leading slash on forward causes problem in proxied environments

Posted by Laurie Harper <la...@holoweb.net>.
J T wrote:
> We have four environments: dev, int, stg, and prod. Each of these is fronted
> by an apache server
> that proxies to our weblogic application server.
> 
> The URLs to the apps look like this
> (dev) http://devserver.com/dev/Application
> (int) http://intserver.com/int/Application
> (stg) http://stgserver.com/stg/Application
> (prod) http://prodserver.com/Application (no directory)
> 
> 
> Two of my actions look like this
> <action
>    path="/viewMain"
>    parameter=".Main"
>    name="myForm"
>    validate="false"
>    type="org.apache.struts.actions.ForwardAction"
>    scope="session">
> </action>
> 
> <action
>    path="/processMain"
>    name="myForm"
>    input=".Main"
>    type="com.company.action.ProcessFormAction"
>    scope="session"
>    validate="true">
>     <forward name="success" path="/viewNew.do"/>
> </action>
> 
> 
> When my jsp is rendered in the dev environment it looks like this…
> 
> ...
> <head>
>     <base href="http://devserver.com/Application/jsp/mainLayout.jsp">
> 
> ...
> </head>
> 
> ...
> <form name="myForm" method="POST" action="/Application/processMain.do">
>     <input type="text" name="mynbr" value="">
>     <input type="submit" value="Submit">
> </form>
> 
> ...
> 
> So when I click submit the POST goes to http://devserver.com/Application/
> and not http://devserver.com/dev/Application
> 
> I don't want to hard code my struts-config since this needs be
> deployed to 4 places.
> 
> I have read through the mailing list archives and the only viable
> solution that I have seen is to create a base action that strips the
> leading slash off of the forwards so that the POST goes back to
> the right place.
> 
> Is there a better way of doing this?

See:

http://struts.apache.org/struts-doc-1.2.x/userGuide/struts-html.html#base
html:base tag, will set up your <base> element for you so you can use 
relative URLs

http://struts.apache.org/struts-doc-1.2.x/userGuide/struts-html.html#link
html:link tag, helps construct URLs without having to know the 
deployment context path, etc.

Between the two, you should be able to make your application independent 
of the path under which you deploy it.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org