struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adrian Brown <adrianjonbr...@yahoo.com.au>
Subject Re: Problem with Proxy Pass
Date Thu, 22 Aug 2002 03:59:09 GMT
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 <evebill8@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" <adrianjonbrown@yahoo.com.au>
> To: "Struts Users Mailing List"
> <struts-user@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 <evebill8@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:
> > >
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> > > For additional commands, e-mail:
> > > <mailto:struts-user-help@jakarta.apache.org>
> > >
> >
> > http://digital.yahoo.com.au - Yahoo! Digital How
> To
> > - Get the best out of your PC!
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> >
> 
> --
> To unsubscribe, e-mail:  
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
>  

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

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


Mime
View raw message