You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Erik Melkersson <er...@student.liu.se> on 2001/08/20 16:49:42 UTC

https, redirect

Hi!

I'm using Apache and tomcat version 4. Apache has ssl turned on and I 
use https.

I'm trying to make a redirect using HttpServletResponse.sendRedirect(...)

When I enter the absolute or relative url to the page it adds only http 
instead of https. This has been discussed before and the only real 
answer I've seen working is to hardcode the full url, like 
HttpServletResponse.sendRedirect("https://server/path/file")

But that doesnt work for me, I get a java.lang.IllegalArgumentException

When I try to enter something with https.


Thankful for any help!

/Erik Melkersson


-----------------------------------
Erik Melkersson
erime844@student.liu.se
http://www.edu.isy.liu.se/~erime844


Re: https, redirect

Posted by Erik Melkersson <er...@student.liu.se>.
Erik Melkersson wrote:
> Hi!
> 
> I'm using Apache and tomcat version 4. Apache has ssl turned on and I 
> use https.
> 
> I'm trying to make a redirect using HttpServletResponse.sendRedirect(...)
> 
> When I enter the absolute or relative url to the page it adds only http 
> instead of https. This has been discussed before and the only real 
> answer I've seen working is to hardcode the full url, like 
> HttpServletResponse.sendRedirect("https://server/path/file")
> 
> But that doesnt work for me, I get a java.lang.IllegalArgumentException
> 
> When I try to enter something with https.
> 
> 
> Thankful for any help!
> 
> /Erik Melkersson
> 
Some complementing info:

Code:

res.sendRedirect("https://" + req.getServerName() + ":" + 
req.getServerPort() + 
"/examples/servlet/nu.comonweb.coordinator.TestRedirect");


Result:

A Servlet Exception Has Occurred

java.lang.IllegalArgumentException: 
https://c2.com-onweb.com:443/examples/servlet/nu.comonweb.coordinator.TestRedirect
	at 
org.apache.catalina.connector.HttpResponseBase.toAbsolute(HttpResponseBase.java:690)
	at 
org.apache.catalina.connector.HttpResponseBase.sendRedirect(HttpResponseBase.java:1089)
	at 
org.apache.catalina.connector.HttpResponseFacade.sendRedirect(HttpResponseFacade.java:150)
	at nu.comonweb.coordinator.TestRedirect.handleRequest(TestRedirect.java:68)
	at nu.comonweb.coordinator.TestRedirect.doPost(TestRedirect.java:36)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
	at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
	at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
	at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at 
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2314)
	at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at 
org.apache.catalina.connector.warp.WarpRequestHandler.handle(WarpRequestHandler.java:208)
	at 
org.apache.catalina.connector.warp.WarpConnection.run(WarpConnection.java:194)
	at java.lang.Thread.run(Thread.java:484)






-----------------------------------
Erik Melkersson
erime844@student.liu.se
http://www.edu.isy.liu.se/~erime844


Re: https, redirect

Posted by Erik Melkersson <er...@student.liu.se>.
I made an ugly fix, but working, in the meantime. I Overwrite the 
Location header:

response.sendRedirect("file"); //file could be almost anything
response.setHeader("Location", "https://server/path/file"); //the real url

Thanks for the replies!

/Melker

Craig R. McClanahan wrote:
> 
> On Mon, 20 Aug 2001, Martin van den Bemt wrote:
> 
> 
>>I think you have to install the https protocol handler from the jsse
>>pacakage. Documentation is provided with jsse to get it working (I had
>>troubles with the non programming solution, the java.policy file, so if you
>>bump in to that, register it in your servlet....
>>
>>
> 
> The need to do this has (correctly) been posted as a bug in Tomcat 4.  The
> problem is that the implementation of sendRedirect is creating a new
> java.net.URL in order to convert relative URLs to absolute (as required by
> the servlet spec), and this won't work unless there are URLStreamHandlers
> in place for the "https" scheme.
> 
> Right now, Martin's workaround will fix the problem.  But we're going to
> change Tomcat 4 before final release so that you don't have to do it.
> 
> 
>>Mvgr,
>>Martin
>>
>>
> 
> Craig McClanahan
> 
> 
> 


-- 
-----------------------------------
Erik Melkersson
erime844@student.liu.se
http://www.edu.isy.liu.se/~erime844


RE: https, redirect

Posted by Martin van den Bemt <ma...@isallineed.org>.
Got lucky here.. I was assuming tc 3..

Mvgr,
Martin

> -----Original Message-----
> From: craigmcc@localhost [mailto:craigmcc@localhost]On Behalf Of Craig
> R. McClanahan
> Sent: Monday, August 20, 2001 5:26 PM
> To: tomcat-user@jakarta.apache.org
> Subject: RE: https, redirect
>
>
>
>
> On Mon, 20 Aug 2001, Martin van den Bemt wrote:
>
> > I think you have to install the https protocol handler from the jsse
> > pacakage. Documentation is provided with jsse to get it working (I had
> > troubles with the non programming solution, the java.policy
> file, so if you
> > bump in to that, register it in your servlet....
> >
>
> The need to do this has (correctly) been posted as a bug in Tomcat 4.  The
> problem is that the implementation of sendRedirect is creating a new
> java.net.URL in order to convert relative URLs to absolute (as required by
> the servlet spec), and this won't work unless there are URLStreamHandlers
> in place for the "https" scheme.
>
> Right now, Martin's workaround will fix the problem.  But we're going to
> change Tomcat 4 before final release so that you don't have to do it.
>
> > Mvgr,
> > Martin
> >
>
> Craig McClanahan
>
>


RE: https, redirect

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 20 Aug 2001, Martin van den Bemt wrote:

> I think you have to install the https protocol handler from the jsse
> pacakage. Documentation is provided with jsse to get it working (I had
> troubles with the non programming solution, the java.policy file, so if you
> bump in to that, register it in your servlet....
> 

The need to do this has (correctly) been posted as a bug in Tomcat 4.  The
problem is that the implementation of sendRedirect is creating a new
java.net.URL in order to convert relative URLs to absolute (as required by
the servlet spec), and this won't work unless there are URLStreamHandlers
in place for the "https" scheme.

Right now, Martin's workaround will fix the problem.  But we're going to
change Tomcat 4 before final release so that you don't have to do it.

> Mvgr,
> Martin
> 

Craig McClanahan


RE: https, redirect

Posted by Martin van den Bemt <ma...@isallineed.org>.
I think you have to install the https protocol handler from the jsse
pacakage. Documentation is provided with jsse to get it working (I had
troubles with the non programming solution, the java.policy file, so if you
bump in to that, register it in your servlet....

Mvgr,
Martin

> -----Original Message-----
> From: Erik Melkersson [mailto:erime844@student.liu.se]
> Sent: Monday, August 20, 2001 4:50 PM
> To: tomcat-user@jakarta.apache.org
> Subject: https, redirect
>
>
> Hi!
>
> I'm using Apache and tomcat version 4. Apache has ssl turned on and I
> use https.
>
> I'm trying to make a redirect using HttpServletResponse.sendRedirect(...)
>
> When I enter the absolute or relative url to the page it adds only http
> instead of https. This has been discussed before and the only real
> answer I've seen working is to hardcode the full url, like
> HttpServletResponse.sendRedirect("https://server/path/file")
>
> But that doesnt work for me, I get a java.lang.IllegalArgumentException
>
> When I try to enter something with https.
>
>
> Thankful for any help!
>
> /Erik Melkersson
>
>
> -----------------------------------
> Erik Melkersson
> erime844@student.liu.se
> http://www.edu.isy.liu.se/~erime844
>
>