You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Billy Ng <ev...@hotmail.com> on 2002/08/20 20:25:25 UTC

Problem with Proxy Pass

Hi folks,

I use the proxy pass in Apache to translate the url from

http://www.myDomian.com:8080/myApp to http://www.myDomian.com

In the <html:form> tag, it looks like,

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

However,  you will notice Struts will add the app name in the action path if 
you view the html

<form action="/myApp/logon.do" method="POST" ...>

This will break the url.  Would anybody please me how can tell Struts not to 
add the app name?

Thanks!

Billy Ng

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with Proxy Pass

Posted by Adrian Brown <ad...@yahoo.com.au>.
Just following up on myself,

if you like, a better way to get the init parameters
would be through setting up config parameters by
putting the following under the <web-app> element in
your web.xml:

  <context-param>
    <param-name>useAlternateServerName</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>alternateServerName</param-name>
    <param-value>www.myDomain.com.au</param-value> 
  </context-param>

and then reference them like this in the
BaseTag.doStartTag() method:

	String value =
pageContext.getServletContext().getInitParameter("useAlternateServerName");

and

	String value =
pageContext.getServletContext().getInitParameter("alternateServerName");

instead of using getServletConfig(), and adding the
extra servlet (jsp) in your web.xml.

This has the advantage of being accessible from within
your action servlet whenever you like (just delete the
'pageContext' bit).

Hope that is not to confusing!

Adrian

 --- Adrian Brown <ad...@yahoo.com.au> wrote:
> Hi Billy,
> 
> What I had in mind was not really a silver bullet,
> but
> rather doing something like looking for a server
> property set in your web.xml file for the *actual*
> name of the server, and using that instead of
> 
> request.getServerName()
> 
> in the
> org.apache.struts.taglib.html.BaseTag.doStartTag().
> 
> Basically, replace the line in the doStartTag():
> 
> buf.append(request.getServerName());
> 
> with the following:
> 
>     String serverName = request.getServerName();
> 
> 	String value =
>
pageContext.getServletConfig().getInitParameter("useAlternateServerName");
> 
>     boolean useAlternateServerName = false;
> 	if (value != null) {
> 	    if (value.equalsIgnoreCase("true") ||
> 	        value.equalsIgnoreCase("yes"))
> 	        useAlternateServerName = true;
> 	}
>     if (useAlternateServerName)
>         serverName =
>
pageContext.getServletConfig().getInitParameter("alternateServerName");
>     buf.append(serverName);
> 
> and then in your web.xml, put in the following
> servlet
> info:
> 
>   <servlet>
>     <servlet-name>
>         jsp
>     </servlet-name>
>     <servlet-class>
>         org.apache.jasper.servlet.JspServlet
>     </servlet-class>
>     <init-param>
>      
> <param-name>useAlternateServerName</param-name>
>       <param-value>true</param-value> 
>     </init-param>
>     <init-param>
>       <param-name>alternateServerName</param-name>
>       <param-value>www.myDomain.com.au</param-value>
> 
>     </init-param>
>   </servlet>
>   <servlet-mapping>
>       <servlet-name>
>           jsp
>       </servlet-name>
>       <url-pattern>
>           *.jsp
>       </url-pattern>
>   </servlet-mapping>
> 
> This is necessary to put some init parameters into
> the
> servlet handling your jsps, and it is Tomcat
> specific.
> I have not found a method by which JSP Tags can
> access
> init parameters via servlets other than 'jsp' (eg.
> action is inaccessible). If anyone has any
> workarounds
> I'd be very interested.
> 
> I notice you also reported problems with getting the
> right context through
> 
> request.getContextPath()
> 
> Same again - you can re-use the code above with a
> couple of changes (eg. consideration of port number)
> to check you have the desired context (alternate or
> regular). Note the init params may have to appear in
> the action servlet's context if you are calling
> getContextPath() within it.
> 
> By deploying one version of your code on your
> proxied
> server and another on your test with
> useAlternateServerName set to false (or simply left
> out) you can control what server names your servlet
> believes it is called.
> 
> The problem I have not surmounted yet is how to
> interpret when a particular call is going through
> your
> proxy, and when it is not, though you could do this
> by
> perhaps setting up your app to listen on two ports -
> one for the proxied requests and one for local ones,
> that way you could tell them apart. But that I
> haven't
> done yet (I just deploy the same app to another box
> for testing with the altered web.xml, and trust that
> everything else remains the same). 
> 
> I'd be interested to hear any alternate solutions,
> 'cause I fancy this is a regular obstacle for anyone
> deploying with Apache proxying outside a firewall
> for
> a Tomcat server sitting inside a firewall.
> 
> Adrian
> 
>  --- Billy Ng <ev...@hotmail.com> wrote: > Thanks
> Adrain!  I'm interested in learning how to
> > work around with
> > properties lookup.  Please shoot me the info.
> > 
> > Thanks again!
> > 
> > Billy Ng
> > 
> > ----- Original Message -----
> > From: "Adrian Brown" <ad...@yahoo.com.au>
> > To: "Struts Users Mailing List"
> > <st...@jakarta.apache.org>
> > Sent: Tuesday, August 20, 2002 7:51 PM
> > Subject: Re: Problem with Proxy Pass
> > 
> > 
> > > Hi Billy,
> > >
> > > This might not be optimal for you, but try
> > altering
> > > the org.apache.struts.taglib.html.BaseTag to
> > generate
> > > the altered server name, this is one way to get
> it
> > to
> > > work. You might want to control it using a
> > properties
> > > lookup of some sort. If you want more details,
> let
> > me
> > > know.
> > >
> > > Adrian
> > >
> > >  --- Billy Ng <ev...@hotmail.com> wrote: > Hi
> > > folks,
> > > >
> > > > I use the proxy pass in Apache to translate
> the
> > url
> > > > from
> > > >
> > > > http://www.myDomian.com:8080/myApp to
> > > > http://www.myDomian.com
> > > >
> > > > In the <html:form> tag, it looks like,
> > > >
> > > > <html:form action="/logon.do" method="POST"
> ...>
> > > >
> > > > However,  you will notice Struts will add the
> > app
> > > > name in the action path if
> > > > you view the html
> > > >
> > > > <form action="/myApp/logon.do" method="POST"
> > ...>
> > > >
> > > > This will break the url.  Would anybody please
> > me
> > > > how can tell Struts not to
> > > > add the app name?
> > > >
> > > > Thanks!
> > > >
> > > > Billy Ng
> > > >
> > > >
> > >
> >
>
_________________________________________________________________
> > > > Send and receive Hotmail on your mobile
> device:
> > > > http://mobile.msn.com
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > >
> >
> <ma...@jakarta.apache.org>
> > > > For additional commands, e-mail:
> > > > <ma...@jakarta.apache.org>
> 
=== message truncated === 

http://digital.yahoo.com.au - Yahoo! Digital How To
- Get the best out of your PC!

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with Proxy Pass

Posted by Adrian Brown <ad...@yahoo.com.au>.
Hi Billy,

What I had in mind was not really a silver bullet, but
rather doing something like looking for a server
property set in your web.xml file for the *actual*
name of the server, and using that instead of

request.getServerName()

in the
org.apache.struts.taglib.html.BaseTag.doStartTag().

Basically, replace the line in the doStartTag():

buf.append(request.getServerName());

with the following:

    String serverName = request.getServerName();

	String value =
pageContext.getServletConfig().getInitParameter("useAlternateServerName");

    boolean useAlternateServerName = false;
	if (value != null) {
	    if (value.equalsIgnoreCase("true") ||
	        value.equalsIgnoreCase("yes"))
	        useAlternateServerName = true;
	}
    if (useAlternateServerName)
        serverName =
pageContext.getServletConfig().getInitParameter("alternateServerName");
    buf.append(serverName);

and then in your web.xml, put in the following servlet
info:

  <servlet>
    <servlet-name>
        jsp
    </servlet-name>
    <servlet-class>
        org.apache.jasper.servlet.JspServlet
    </servlet-class>
    <init-param>
      <param-name>useAlternateServerName</param-name>
      <param-value>true</param-value> 
    </init-param>
    <init-param>
      <param-name>alternateServerName</param-name>
      <param-value>www.myDomain.com.au</param-value> 
    </init-param>
  </servlet>
  <servlet-mapping>
      <servlet-name>
          jsp
      </servlet-name>
      <url-pattern>
          *.jsp
      </url-pattern>
  </servlet-mapping>

This is necessary to put some init parameters into the
servlet handling your jsps, and it is Tomcat specific.
I have not found a method by which JSP Tags can access
init parameters via servlets other than 'jsp' (eg.
action is inaccessible). If anyone has any workarounds
I'd be very interested.

I notice you also reported problems with getting the
right context through

request.getContextPath()

Same again - you can re-use the code above with a
couple of changes (eg. consideration of port number)
to check you have the desired context (alternate or
regular). Note the init params may have to appear in
the action servlet's context if you are calling
getContextPath() within it.

By deploying one version of your code on your proxied
server and another on your test with
useAlternateServerName set to false (or simply left
out) you can control what server names your servlet
believes it is called.

The problem I have not surmounted yet is how to
interpret when a particular call is going through your
proxy, and when it is not, though you could do this by
perhaps setting up your app to listen on two ports -
one for the proxied requests and one for local ones,
that way you could tell them apart. But that I haven't
done yet (I just deploy the same app to another box
for testing with the altered web.xml, and trust that
everything else remains the same). 

I'd be interested to hear any alternate solutions,
'cause I fancy this is a regular obstacle for anyone
deploying with Apache proxying outside a firewall for
a Tomcat server sitting inside a firewall.

Adrian

 --- Billy Ng <ev...@hotmail.com> wrote: > Thanks
Adrain!  I'm interested in learning how to
> work around with
> properties lookup.  Please shoot me the info.
> 
> Thanks again!
> 
> Billy Ng
> 
> ----- Original Message -----
> From: "Adrian Brown" <ad...@yahoo.com.au>
> To: "Struts Users Mailing List"
> <st...@jakarta.apache.org>
> Sent: Tuesday, August 20, 2002 7:51 PM
> Subject: Re: Problem with Proxy Pass
> 
> 
> > Hi Billy,
> >
> > This might not be optimal for you, but try
> altering
> > the org.apache.struts.taglib.html.BaseTag to
> generate
> > the altered server name, this is one way to get it
> to
> > work. You might want to control it using a
> properties
> > lookup of some sort. If you want more details, let
> me
> > know.
> >
> > Adrian
> >
> >  --- Billy Ng <ev...@hotmail.com> wrote: > Hi
> > folks,
> > >
> > > I use the proxy pass in Apache to translate the
> url
> > > from
> > >
> > > http://www.myDomian.com:8080/myApp to
> > > http://www.myDomian.com
> > >
> > > In the <html:form> tag, it looks like,
> > >
> > > <html:form action="/logon.do" method="POST" ...>
> > >
> > > However,  you will notice Struts will add the
> app
> > > name in the action path if
> > > you view the html
> > >
> > > <form action="/myApp/logon.do" method="POST"
> ...>
> > >
> > > This will break the url.  Would anybody please
> me
> > > how can tell Struts not to
> > > add the app name?
> > >
> > > Thanks!
> > >
> > > Billy Ng
> > >
> > >
> >
>
_________________________________________________________________
> > > Send and receive Hotmail on your mobile device:
> > > http://mobile.msn.com
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > >
> <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > >
> >
> > http://digital.yahoo.com.au - Yahoo! Digital How
> To
> > - Get the best out of your PC!
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>  

http://digital.yahoo.com.au - Yahoo! Digital How To
- Get the best out of your PC!

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with Proxy Pass

Posted by Billy Ng <ev...@hotmail.com>.
Thanks Adrain!  I'm interested in learning how to work around with
properties lookup.  Please shoot me the info.

Thanks again!

Billy Ng

----- Original Message -----
From: "Adrian Brown" <ad...@yahoo.com.au>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, August 20, 2002 7:51 PM
Subject: Re: Problem with Proxy Pass


> Hi Billy,
>
> This might not be optimal for you, but try altering
> the org.apache.struts.taglib.html.BaseTag to generate
> the altered server name, this is one way to get it to
> work. You might want to control it using a properties
> lookup of some sort. If you want more details, let me
> know.
>
> Adrian
>
>  --- Billy Ng <ev...@hotmail.com> wrote: > Hi
> folks,
> >
> > I use the proxy pass in Apache to translate the url
> > from
> >
> > http://www.myDomian.com:8080/myApp to
> > http://www.myDomian.com
> >
> > In the <html:form> tag, it looks like,
> >
> > <html:form action="/logon.do" method="POST" ...>
> >
> > However,  you will notice Struts will add the app
> > name in the action path if
> > you view the html
> >
> > <form action="/myApp/logon.do" method="POST" ...>
> >
> > This will break the url.  Would anybody please me
> > how can tell Struts not to
> > add the app name?
> >
> > Thanks!
> >
> > Billy Ng
> >
> >
> _________________________________________________________________
> > Send and receive Hotmail on your mobile device:
> > http://mobile.msn.com
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
>
> http://digital.yahoo.com.au - Yahoo! Digital How To
> - Get the best out of your PC!
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem with Proxy Pass

Posted by Adrian Brown <ad...@yahoo.com.au>.
Hi Billy,

This might not be optimal for you, but try altering
the org.apache.struts.taglib.html.BaseTag to generate
the altered server name, this is one way to get it to
work. You might want to control it using a properties
lookup of some sort. If you want more details, let me
know.

Adrian

 --- Billy Ng <ev...@hotmail.com> wrote: > Hi
folks,
> 
> I use the proxy pass in Apache to translate the url
> from
> 
> http://www.myDomian.com:8080/myApp to
> http://www.myDomian.com
> 
> In the <html:form> tag, it looks like,
> 
> <html:form action="/logon.do" method="POST" ...>
> 
> However,  you will notice Struts will add the app
> name in the action path if 
> you view the html
> 
> <form action="/myApp/logon.do" method="POST" ...>
> 
> This will break the url.  Would anybody please me
> how can tell Struts not to 
> add the app name?
> 
> Thanks!
> 
> Billy Ng
> 
>
_________________________________________________________________
> Send and receive Hotmail on your mobile device:
> http://mobile.msn.com
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>  

http://digital.yahoo.com.au - Yahoo! Digital How To
- Get the best out of your PC!

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>