Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Am I Running Under HTTP or HTTPS? (http://www.velocityreviews.com/forums/t147520-am-i-running-under-http-or-https.html)

MattC 11-05-2005 03:37 PM

Am I Running Under HTTP or HTTPS?
 
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 11-05-2005 04:11 PM

Re: Am I Running Under HTTP or HTTPS?
 
> 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
> }


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.
--
Real Gagnon from Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to
* http://www.rgagnon.com/howto.html

Roedy Green 11-05-2005 04:40 PM

Re: Am I Running Under HTTP or HTTPS?
 
On 5 Nov 2005 07:37:35 -0800, "MattC" <matthew.n.connors@lmco.com>
wrote, quoted or indirectly quoted someone who said :

>String protocol = httpServletRequest.getProtocol();
>
>if (protocol.indexOf("HTTPS") > -1) {
> // protocol is HTTPS
>} else {
> // 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" ) )
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

MattC 11-07-2005 01:27 PM

Re: Am I Running Under HTTP or HTTPS?
 
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.


intertester 09-14-2012 06:40 PM

I tried isSecure().
But it returns true even if it is http. How did you resolve this?


All times are GMT. The time now is 04:37 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.