Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Am I Running Under HTTP or HTTPS?

Thread view: 
MattC - 05 Nov 2005 16:37 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.