You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bill Clinton <bc...@snipermail.com> on 2002/02/26 20:03:20 UTC

How can I get rid of the port on redirects.

Hello,

I am running on port 8060, but the outside world sees my my application 
through a proxy run on port 80.  When I set a forward to an action and 
use the redirect=true flag, the port "8060" gets tagged on to the 
redirect and it times out since this port is not open on the proxy.  I 
am trying to look for somewhere in the struts source code where I can 
strip out the refernce to this port on redirects.  Can someone please 
show me where I would need to modify the source?  I am unable to find it.

Bill


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


RE: How can I get rid of the port on redirects.

Posted by Robert Nocera <rn...@neosllc.com>.
Bill,

If you don't absolutely need to redirect then set the flag to false.

If you do, getting rid of the base tag might help as per:
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg05647.html


Robert Nocera
New England Open Solutions
www.neosllc.com
"You supply the vision, we'll do the rest."
 

-----Original Message-----
From: Bill Clinton [mailto:bclinton@snipermail.com] 
Sent: Tuesday, February 26, 2002 2:03 PM
To: Struts Users Mailing List
Subject: How can I get rid of the port on redirects.

Hello,

I am running on port 8060, but the outside world sees my my application 
through a proxy run on port 80.  When I set a forward to an action and 
use the redirect=true flag, the port "8060" gets tagged on to the 
redirect and it times out since this port is not open on the proxy.  I 
am trying to look for somewhere in the struts source code where I can 
strip out the refernce to this port on redirects.  Can someone please 
show me where I would need to modify the source?  I am unable to find
it.

Bill


--
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: How can I get rid of the port on redirects.

Posted by Bill Clinton <bc...@snipermail.com>.
Robert wrote:

>Hmm.. ok maybe I'm confused here on the terminology of what you are
>saying. So:
>
>1) is all of www.mydomain.com/app running on port 8060, or ONLY the
>app/submitComplete.do ? I'm _guessing_ the whole thing is on one port.
>
As i mentioned in my first post, the application is running on port 
8060.  But the users are connecting through a proxy on port 80.  They 
should never see port 8060.

>
>2) Are you actually doing a redirect to the browser OR are you doing a
>forward from one action to the other? Meaning, could your formSubmit.do
>Action perform a forward to the other action, submitComplete.do. Now, IF
>this is what you are doing (a forward and not a redirect), then I see
>what you are asking as the server (Struts) is doing a forward and the
>browser is showing the resulting page's URL, which you don't want. In
>that case I'm not sure how it is done :-) Unless you have the 'redirect'
>attribute set to 'true' in the forward tag, in which case the browser is
>going to show the URL like mentioned before.
>
If I forward to the the other action, the URL on the user's browser will 
still read formSubmit.do.  If the user  hits reload, he will be asked to 
repost his data and could submit the form twice.  I would rather 
redirect him to a new location.

I already had to write a workaround into the BaseTag in the html tag 
library for this same port problem.  I don't mind recompiling struts 
classes if there is somewhere I can modify this.

I would be surprised if this is the first time someone has had this 
problem.   Connecting to an app server through a proxy run on a 
different port is not an uncommon configuration.  Perhaps I should be 
looking to resolve this on the proxy?

>
>If I'm way off on these then I apologize :-)
>
>Robert
>

bp Robert - thanks for the responses.  It could be that I am the one way 
off here


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


RE: How can I get rid of the port on redirects.

Posted by Robert <rm...@bull-enterprises.com>.
Hmm.. ok maybe I'm confused here on the terminology of what you are
saying. So:

1) is all of www.mydomain.com/app running on port 8060, or ONLY the
app/submitComplete.do ? I'm _guessing_ the whole thing is on one port.

2) Are you actually doing a redirect to the browser OR are you doing a
forward from one action to the other? Meaning, could your formSubmit.do
Action perform a forward to the other action, submitComplete.do. Now, IF
this is what you are doing (a forward and not a redirect), then I see
what you are asking as the server (Struts) is doing a forward and the
browser is showing the resulting page's URL, which you don't want. In
that case I'm not sure how it is done :-) Unless you have the 'redirect'
attribute set to 'true' in the forward tag, in which case the browser is
going to show the URL like mentioned before.

If I'm way off on these then I apologize :-)

Robert

-----Original Message-----
From: Bill Clinton [mailto:bclinton@snipermail.com] 
Sent: Tuesday, February 26, 2002 1:43 PM
To: Struts Users Mailing List
Subject: Re: How can I get rid of the port on redirects.

Thanks for your answer Robert, but perhaps I am not being descriptive 
enough.

I have an action called formSubmit.  It would look to the user like: 
http://www.mydomain.com/app/formSubmit.do
when they hit the submit button on the form.

If this action is successful, I would like to redirect to an action 
called submitComplete.  This should look to the user like:
http://www.mydomain.com/app/submitComplete.do

but instead, it attempts to send my user to:
http://www.mydomain.com:8060/app/submitComplete.do
which is incorrect.

I assume the internals of struts are using the getServerName() and 
getServerPort() methods to form this URL.  My only question is where?   
I have seen other examples in the struts source where there are work 
arounds for port 80 and the https port (443).  You can look at these 
workarounds in the org.apache.struts.util.RequestUtils class.  I am 
looking for a smiliar workaround where i can avoid having struts append 
the port to the URL when I redirect.

Bill


Robert wrote:

>You could probably do that, but if you take out the port BEFORE doing
>the redirect, then the browser won't have the correct port and you
would
>end up with a 404 error, no?
>
>Remember that in a redirect, the server tells the browser where to go,
>and thus it has to supply the correct URL including the port. In a
>forward, all the action takes place on the server, so the browser
>doesn't really know that a forward took place.
>
>If I'm wrong here, someone let me know!
>
>- Robert
>
>-----Original Message-----
>From: Bill Clinton [mailto:bclinton@snipermail.com] 
>Sent: Tuesday, February 26, 2002 1:23 PM
>To: Struts Users Mailing List
>Subject: Re: How can I get rid of the port on redirects.
>
>But, isn't there a spot to intercept it and screen out the port before 
>it is handed off to the browser?  Struts has to be forming that URL 
>somewhere, I just can't find it.
>
>Robert wrote:
>
>>If it's a redirect, I don't think you can, since the redirect URL is
>>given to the browser, as opposed to a forward. Maybe you can with
>>frames, but frames isn't exactly an 'elegant' solution.
>>
>>- Robert
>>
>>-----Original Message-----
>>From: Bill Clinton [mailto:bclinton@snipermail.com] 
>>Sent: Tuesday, February 26, 2002 1:03 PM
>>To: Struts Users Mailing List
>>Subject: How can I get rid of the port on redirects.
>>
>>Hello,
>>
>>I am running on port 8060, but the outside world sees my my
application
>>
>
>>through a proxy run on port 80.  When I set a forward to an action and

>>use the redirect=true flag, the port "8060" gets tagged on to the 
>>redirect and it times out since this port is not open on the proxy.  I

>>am trying to look for somewhere in the struts source code where I can 
>>strip out the refernce to this port on redirects.  Can someone please 
>>show me where I would need to modify the source?  I am unable to find
>>it.
>>
>>Bill
>>
>>
>>--
>>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>
>
>>
>>.
>>
>
>
>
>--
>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>
>
>
>.
>



--
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: How can I get rid of the port on redirects.

Posted by Bill Clinton <bc...@snipermail.com>.
Hi,
   Thanks alot to everyone who sent me ideas.  As someone else 
mentioned. this behavior was determined by the servlet container (i am 
using orion), and the method pointed out by Chuck here was the location  
I was looking for.  Basically I copied a bunch of code from 
RequestUtils.java, added the port i wanted to screen, and added it to 
this method.  I changed this line:

response.sendRedirect(response.encodeRedirectURL(path));

to:

                    StringBuffer url = new StringBuffer();
                    String scheme = request.getScheme();
                    int port = request.getServerPort();
                    if (port < 0)
                        port = 80; // Work around java.net.URL bug
                    url.append(scheme);
                    url.append("://");
                    url.append(request.getServerName());
                    if ((scheme.equals("http") && (port != 80 && port != 
8060)) ||
                        (scheme.equals("https") && (port != 443))) {
                            url.append(':');
                            url.append(port);
                    }
                    url.append(path);

                    
response.sendRedirect(response.encodeRedirectURL(url.toString()));




Thanks again,

Bill



struts-user@japache.org wrote:

>I'm not that that the answer lies in the Struts framework exactly. I was looking in the method "processActionForward" in the ActionServlet class.
>
>It has this line for a redirect:
>
>response.sendRedirect(response.encodeRedirectURL(path));
>
>I think it's the job of the servlet container to translate the relative URL to a fully qualified URL for transmission back to the client. So it may actually depend on the container that you're using and if it provides the hooks for doing this.
>
>You might try playing around with the value passed to the sendRedirect method or the response headers to see what happens.
>Chuck
>--
>Sent via jApache.org
>
>--
>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: How can I get rid of the port on redirects.

Posted by st...@japache.org.
I'm not that that the answer lies in the Struts framework exactly. I was looking in the method "processActionForward" in the ActionServlet class.

It has this line for a redirect:

response.sendRedirect(response.encodeRedirectURL(path));

I think it's the job of the servlet container to translate the relative URL to a fully qualified URL for transmission back to the client. So it may actually depend on the container that you're using and if it provides the hooks for doing this.

You might try playing around with the value passed to the sendRedirect method or the response headers to see what happens.
Chuck
--
Sent via jApache.org

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


Re: How can I get rid of the port on redirects.

Posted by Bill Clinton <bc...@snipermail.com>.
Thanks for your answer Robert, but perhaps I am not being descriptive 
enough.

I have an action called formSubmit.  It would look to the user like: 
http://www.mydomain.com/app/formSubmit.do
when they hit the submit button on the form.

If this action is successful, I would like to redirect to an action 
called submitComplete.  This should look to the user like:
http://www.mydomain.com/app/submitComplete.do

but instead, it attempts to send my user to:
http://www.mydomain.com:8060/app/submitComplete.do
which is incorrect.

I assume the internals of struts are using the getServerName() and 
getServerPort() methods to form this URL.  My only question is where?   
I have seen other examples in the struts source where there are work 
arounds for port 80 and the https port (443).  You can look at these 
workarounds in the org.apache.struts.util.RequestUtils class.  I am 
looking for a smiliar workaround where i can avoid having struts append 
the port to the URL when I redirect.

Bill


Robert wrote:

>You could probably do that, but if you take out the port BEFORE doing
>the redirect, then the browser won't have the correct port and you would
>end up with a 404 error, no?
>
>Remember that in a redirect, the server tells the browser where to go,
>and thus it has to supply the correct URL including the port. In a
>forward, all the action takes place on the server, so the browser
>doesn't really know that a forward took place.
>
>If I'm wrong here, someone let me know!
>
>- Robert
>
>-----Original Message-----
>From: Bill Clinton [mailto:bclinton@snipermail.com] 
>Sent: Tuesday, February 26, 2002 1:23 PM
>To: Struts Users Mailing List
>Subject: Re: How can I get rid of the port on redirects.
>
>But, isn't there a spot to intercept it and screen out the port before 
>it is handed off to the browser?  Struts has to be forming that URL 
>somewhere, I just can't find it.
>
>Robert wrote:
>
>>If it's a redirect, I don't think you can, since the redirect URL is
>>given to the browser, as opposed to a forward. Maybe you can with
>>frames, but frames isn't exactly an 'elegant' solution.
>>
>>- Robert
>>
>>-----Original Message-----
>>From: Bill Clinton [mailto:bclinton@snipermail.com] 
>>Sent: Tuesday, February 26, 2002 1:03 PM
>>To: Struts Users Mailing List
>>Subject: How can I get rid of the port on redirects.
>>
>>Hello,
>>
>>I am running on port 8060, but the outside world sees my my application
>>
>
>>through a proxy run on port 80.  When I set a forward to an action and 
>>use the redirect=true flag, the port "8060" gets tagged on to the 
>>redirect and it times out since this port is not open on the proxy.  I 
>>am trying to look for somewhere in the struts source code where I can 
>>strip out the refernce to this port on redirects.  Can someone please 
>>show me where I would need to modify the source?  I am unable to find
>>it.
>>
>>Bill
>>
>>
>>--
>>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>
>
>>
>>.
>>
>
>
>
>--
>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>
>
>
>.
>



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


RE: How can I get rid of the port on redirects.

Posted by Robert <rm...@bull-enterprises.com>.
You could probably do that, but if you take out the port BEFORE doing
the redirect, then the browser won't have the correct port and you would
end up with a 404 error, no?

Remember that in a redirect, the server tells the browser where to go,
and thus it has to supply the correct URL including the port. In a
forward, all the action takes place on the server, so the browser
doesn't really know that a forward took place.

If I'm wrong here, someone let me know!

- Robert

-----Original Message-----
From: Bill Clinton [mailto:bclinton@snipermail.com] 
Sent: Tuesday, February 26, 2002 1:23 PM
To: Struts Users Mailing List
Subject: Re: How can I get rid of the port on redirects.

But, isn't there a spot to intercept it and screen out the port before 
it is handed off to the browser?  Struts has to be forming that URL 
somewhere, I just can't find it.

Robert wrote:

>If it's a redirect, I don't think you can, since the redirect URL is
>given to the browser, as opposed to a forward. Maybe you can with
>frames, but frames isn't exactly an 'elegant' solution.
>
>- Robert
>
>-----Original Message-----
>From: Bill Clinton [mailto:bclinton@snipermail.com] 
>Sent: Tuesday, February 26, 2002 1:03 PM
>To: Struts Users Mailing List
>Subject: How can I get rid of the port on redirects.
>
>Hello,
>
>I am running on port 8060, but the outside world sees my my application

>through a proxy run on port 80.  When I set a forward to an action and 
>use the redirect=true flag, the port "8060" gets tagged on to the 
>redirect and it times out since this port is not open on the proxy.  I 
>am trying to look for somewhere in the struts source code where I can 
>strip out the refernce to this port on redirects.  Can someone please 
>show me where I would need to modify the source?  I am unable to find
>it.
>
>Bill
>
>
>--
>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>
>
>
>.
>



--
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: How can I get rid of the port on redirects.

Posted by Bill Clinton <bc...@snipermail.com>.
But, isn't there a spot to intercept it and screen out the port before 
it is handed off to the browser?  Struts has to be forming that URL 
somewhere, I just can't find it.

Robert wrote:

>If it's a redirect, I don't think you can, since the redirect URL is
>given to the browser, as opposed to a forward. Maybe you can with
>frames, but frames isn't exactly an 'elegant' solution.
>
>- Robert
>
>-----Original Message-----
>From: Bill Clinton [mailto:bclinton@snipermail.com] 
>Sent: Tuesday, February 26, 2002 1:03 PM
>To: Struts Users Mailing List
>Subject: How can I get rid of the port on redirects.
>
>Hello,
>
>I am running on port 8060, but the outside world sees my my application 
>through a proxy run on port 80.  When I set a forward to an action and 
>use the redirect=true flag, the port "8060" gets tagged on to the 
>redirect and it times out since this port is not open on the proxy.  I 
>am trying to look for somewhere in the struts source code where I can 
>strip out the refernce to this port on redirects.  Can someone please 
>show me where I would need to modify the source?  I am unable to find
>it.
>
>Bill
>
>
>--
>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>
>
>
>.
>



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


RE: How can I get rid of the port on redirects.

Posted by Robert <rm...@bull-enterprises.com>.
If it's a redirect, I don't think you can, since the redirect URL is
given to the browser, as opposed to a forward. Maybe you can with
frames, but frames isn't exactly an 'elegant' solution.

- Robert

-----Original Message-----
From: Bill Clinton [mailto:bclinton@snipermail.com] 
Sent: Tuesday, February 26, 2002 1:03 PM
To: Struts Users Mailing List
Subject: How can I get rid of the port on redirects.

Hello,

I am running on port 8060, but the outside world sees my my application 
through a proxy run on port 80.  When I set a forward to an action and 
use the redirect=true flag, the port "8060" gets tagged on to the 
redirect and it times out since this port is not open on the proxy.  I 
am trying to look for somewhere in the struts source code where I can 
strip out the refernce to this port on redirects.  Can someone please 
show me where I would need to modify the source?  I am unable to find
it.

Bill


--
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>