• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTPS over JSSE  RSS feed

Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to post this here.. This is not strictly JSP/Servlet but hope to get an answer here (failed to get one anywhere else)
I need to download a file over an https connection.. How do I go about this ?
This code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.security.* ;
import javax.net.* ;
public class GetFile {
public static void main(String[] arguments) {
if (arguments.length == 1) {
PageFrame page = new PageFrame(arguments[0]);
} else
System.out.println("Usage: java GetFile url");
class PageFrame extends JFrame {
JTextArea box = new JTextArea("Getting data ...");
URL page;
public PageFrame(String address) {
setSize(600, 300);
JScrollPane pane = new JScrollPane(box);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");

Class clsFactory = Class.forName("com.sun.net.ssl.internal.ssl.Provider");
if( (null != clsFactory) && (null == Security.getProvider("SunJSSE")) )
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
catch( ClassNotFoundException cfe )
// throw new Exception("Unable to load the JSSE SSL stream handler." + "Check classpath." + cfe.toString());
System.out.println("Exception 1") ;

catch (Exception e) {}

try {
page = new URL(address);
} catch (MalformedURLException e) {
System.out.println("Bad URL: " + address);
void getData(URL url) {
URLConnection conn = null;
InputStreamReader in;
BufferedReader data;
String line;
StringBuffer buf = new StringBuffer();
try {
conn = this.page.openConnection();
box.setText("Connection opened ...");
in = new InputStreamReader(conn.getInputStream());
data = new BufferedReader(in);
box.setText("Reading data ...");
while ((line = data.readLine()) != null)
buf.append(line + "\n");
} catch (IOException e) {
System.out.println("IO Error:" + e.getMessage());

gives me
C:\Program Files\JCreator\MyProjects\Mak>java GetFile https://localhost:8443/tes
Exception in thread "main" java.lang.NoClassDefFoundError: javax/net/SocketFacto
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at com.sun.net.ssl.HttpsURLConnection.<clinit>([DashoPro-V1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.Handler.openConnection([D
at java.net.URL.openConnection(Unknown Source)
at PageFrame.getData(GetFile.java:66)
at PageFrame.<init>(GetFile.java:53)
at GetFile.main(GetFile.java:12)

It works for http.. https fails.. can anyone help me please ? Its very urgent.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!