Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2007, 03:47 PM
Member
 
Join Date: Apr 2007
Posts: 3
vicky is on a distinguished road
How to implement secure connection(HTTPs) in client side
Hello All,

I need sample code for implementing Secure connection(https) in client side.


Thanks in advance,
Vicky
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-21-2007, 04:14 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Hello Vicky,

Welcome to Java Forums.

I removed the clone of this post on "Advanced Java" forum. You do not need to/should not post same post on multiple forums. Please post your question to only the most appropriate one next time.

And related to your question. I found this code. Let us know if it works or not.

Code:
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.net.*; import java.security.Security; import java.util.Properties; public class UseHttps { public static void main(String argv[]) { Class factoryClass = null; URLStreamHandlerFactory factory = null; String socksServer = ""; String socksPort = ""; String usage = "Usage: java UseHttps URL-to-be-read socksServerName(optional) socksPortNumber(optional)"; if ((argv == null) || (argv.length == 0)) { System.out.println(usage); return; } String prefix = "https://"; // Build the complete URL, including the protocol String fullURL = prefix.concat(argv[0]); if (argv.length > 3) { System.out.println(usage); return; } if (argv.length >= 2) { socksServer = argv[1]; if (argv.length == 3) { socksPort = argv[2]; } } System.out.println("Computed URL is " + fullURL); // Now either we can rely on the user to have added us to // the security.provider list in java.security, or we can // dynamically add ourselves here. We'll set it up here. Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); Properties properties = System.getProperties(); String handlers = System.getProperty("java.protocol.handler.pkgs"); if (handlers == null) { // nothing specified yet (expected case) properties.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); } else { // something already there, put ourselves out front properties.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol|".concat(handlers)); } if (!socksServer.equals("")) { // Must do the setup to get to the socks host // Could check first to see if the user already specified it on the invocation line if (System.getProperty("socksProxyHost") == null) { properties.put("socksProxyHost", socksServer); } if (!socksPort.equals("")) { if (System.getProperty("socksProxyPort") == null) { properties.put("socksProxyPort", socksPort); } } } System.setProperties(properties); // put the updated properties back in System try { URL page = new URL(fullURL); // Process the URL far enough to find the right handler URLConnection urlc = page.openConnection(); urlc.setUseCaches(false); // Don't look at possibly cached data System.out.println("Content-type = " + urlc.getContentType()); // See what's here System.out.println("Content-length = " + urlc.getContentLength()); // See how much of it there is // Read it all and print it out BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream())); String buffer = ""; while (buffer != null) { try { System.out.println(buffer); buffer = br.readLine(); } catch (IOException ioe) { ioe.printStackTrace(); break; } } } catch (MalformedURLException mue) { System.out.println(fullURL + " is not a URL that can be resolved"); } catch (IOException ie) { ie.printStackTrace(); } } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-23-2007, 08:10 AM
Member
 
Join Date: Apr 2007
Posts: 3
vicky is on a distinguished road
Hi Levent,
Thanks for your reply.
I am getting exception "javax.net.ssl.SSLHandshakeException : unknown certificate".I am not getting how to resolve this problem.


Thanks,
Vicky
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-24-2007, 11:14 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Hi Vicky,

There are lots of pages shown when you search "javax.net.ssl.SSLHandshakeException: unknown certificate". Here is one which might help, i guess:

javax.net.ssl.SSLHandshakeException: unknown certificate
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-18-2007, 03:33 PM
Member
 
Join Date: Jul 2007
Posts: 17
sathish_2111 is on a distinguished road
Is it possible to avoid certificate validation in client side ?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 07-18-2007, 03:58 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Quote:
Is it possible to avoid certificate validation in client side ?
I guess you can accept all certificates by default by playing options in your browser.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 07-18-2007, 04:15 PM
Member
 
Join Date: Jul 2007
Posts: 17
sathish_2111 is on a distinguished road
I am not using browser. I am try to access the https connection using java client code.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy a .swf file from server side to client using signed applet Imoracle Java Applets 0 01-28-2008 01:39 PM
jsp program for client side printer to print these 2 strings on 3/3 for453 JavaServer Pages (JSP) and JSTL 0 08-07-2007 05:42 PM
using Java to access a secure webpage, Exception occurred: Connection timed out toby Enterprise JavaBeans 1 08-07-2007 07:03 AM
i want how to make aprint client side printer to print these 2 strings on 3/3 inch pa for453 Networking 0 08-06-2007 07:54 PM
how To Use Https Connection For Communication fred Advanced Java 2 08-01-2007 05:59 PM


All times are GMT +3. The time now is 03:46 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org