I have a servlet application. Based on a user request the application
will generate an email that contains a URL to one of the applications
screens. This application must run in a variety of environments.
My question is how do I dynamically determine if the URL should use
HTTP or HTTPS? The only solution I can think of is to do something like
this:
String protocol = httpServletRequest.getProtocol();
if (protocol.indexOf("HTTPS") > -1) {
// protocol is HTTPS
} else {
// protocol is HTTP
}
Will this work? Is this the best way to accomplish this?
Thanks,
Real Gagnon - 05 Nov 2005 17:11 GMT
> My question is how do I dynamically determine if the URL should use
> HTTP or HTTPS? The only solution I can think of is to do something like
[quoted text clipped - 7 lines]
> // protocol is HTTP
> }
Use the servlet request's isSecure() or getAuthType() methods.
Or you can check these HTTP headers : CERT_KEYSIZE , CERT_KEYSIZE,
HTTPS_KEYSIZE
This will check if the current connection is secured or not.
To check if the client can handle a secured connection, check this HowTo
at http://www.rgagnon.com/jsdetails/js-0088.html
Bye.

Signature
Real Gagnon from Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to
* http://www.rgagnon.com/howto.html
MattC - 07 Nov 2005 13:27 GMT
Ah yes, isSecure() that's the ticket.
I had a sence that there was a cleaner solution I just wasn't sure what
is was. - Thanks.
Roedy Green - 05 Nov 2005 17:40 GMT
>String protocol = httpServletRequest.getProtocol();
>
[quoted text clipped - 3 lines]
> // protocol is HTTP
>}
I think is this more likely to work:
if ( protocol.equalsIgnoreCase( "https" ) )
Possibly the protocol is always presented as lower case, in which case
you could say
if ( protocol.equals( "https" ) )

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.