473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q) Accessing secure websites from a Java application

I am trying to create a Java application that reads a list of URLs
from a file and stores their contents on the local file system. I
have succeeded in accessing normal websites, but I am unable to access
the secured websites (using the HTTPS protocol) using this approach.

I would greatly appreciate if someone could suggest a way out. I have
looked at the HttpsURLConnect ion class, but unfortunately this class
is abstract.

[My apolgies to readers of comp.lang.java and comp.sources.d since
this posting may appear to be a repost of my previous posting
(although it is not) --- Bhat]

My source code follows:

/////////////////// Source code begin /////////////////////

// This program reads a list of URLs to access and store on the local
// file system from a file. The name of the file is passed as the
// first command line argument. Each URL is on a separate line.
// Lines beginning with the '#' character are treated as blanks and
// are skipped.
//
import java.io.*;
import java.net.*;
import java.security.* ;
class WebsiteLoader
{
public static char replaceChar = '~';

public static void main(String argv[]) throws IOException
{
// The following two lines were suggested by the following
website:
// http://www.javaworld.com/javaworld/j...javatip96.html
// They help in suppressing the java.net.Malfor medURLException
System.setPrope rty("java.proto col.handler.pkg s",
"com.sun.net.ss l.internal.www. protocol");
Security.addPro vider(new com.sun.net.ssl .internal.ssl.P rovider());

BufferedReader br;
String origName;

if(argv.length != 0)
{
br = new BufferedReader( new FileReader(argv[0]));

// Read URLs from the file. Skip blank lines and lines
beginning
// with the '#' character.
for(;;)
{
origName = br.readLine();
if(origName == null)
break;

origName = origName.trim() ;

if(origName.len gth() == 0)
continue;

if(origName.cha rAt(0) == '#')
continue;

URL url = new URL(origName);
if(url == null)
continue;

BufferedReader bufRdr = new BufferedReader( new
InputStreamRead er(url.openStre am()));

// The name of the file to which the website contents are
written
// is derived from the URL by substituting the following
characters
// with some "non-offending" character:
// \,/,:,*,?,",<,>,|

String modName = origName;
modName = modName.replace ('\\', replaceChar);
modName = modName.replace ('/', replaceChar);
modName = modName.replace (':', replaceChar);
modName = modName.replace ('*', replaceChar);
modName = modName.replace ('?', replaceChar);
modName = modName.replace ('"', replaceChar);
modName = modName.replace ('<', replaceChar);
modName = modName.replace ('>', replaceChar);
modName = modName.replace ('|', replaceChar);

FileWriter fWriter = new FileWriter(modN ame);
System.out.prin tln("Writing contents of " + origName + " to "
+
"the following file: " + modName);
for(;;)
{
String thisLine = bufRdr.readLine ();
if(thisLine == null)
break;

fWriter.write(t hisLine);
}
}
}
}
}

/////////////////// Source code end //////////////////////
Jul 17 '05 #1
2 3592
See http://sunsolve.sun.com/pub-cgi/retr...salert%2F57436

The error is because the Class 3 and Class 2 root certificates installed in
your version of Java have expired. It says you can either download the
latest JRE or JDK or you can download certificates from verisign and install
them.

I tried your code and the following is the status of a list of URLs before I
updated the certificate. I am using JDK 1.4.1_02-b06 by the way. This list
is taken from the Javaworld article you referenced.

https://www.verisign.com/ failed
https://happiness.dhs.org/ failed
https://www.microsoft.com worked
https://www.sun.com failed (IIRC)
https://www.ftc.gov failed

Interestingly, those that failed did not all have the same exception thrown.

I updated the cert's as detailed in the sunsolve article and now all of the
URLs worked except dhs.org, which is because it uses a self-signed
certifcate (not using a Verisign or similar root certificate).

"Generic Usenet Account" wrote:
I am trying to create a Java application that reads a list of URLs
from a file and stores their contents on the local file system. I
have succeeded in accessing normal websites, but I am unable to access
the secured websites (using the HTTPS protocol) using this approach.

I would greatly appreciate if someone could suggest a way out. I have
looked at the HttpsURLConnect ion class, but unfortunately this class
is abstract.

[My apolgies to readers of comp.lang.java and comp.sources.d since
this posting may appear to be a repost of my previous posting
(although it is not) --- Bhat]

My source code follows:

/////////////////// Source code begin /////////////////////

// This program reads a list of URLs to access and store on the local
// file system from a file. The name of the file is passed as the
// first command line argument. Each URL is on a separate line.
// Lines beginning with the '#' character are treated as blanks and
// are skipped.
//
import java.io.*;
import java.net.*;
import java.security.* ;
class WebsiteLoader
{
public static char replaceChar = '~';

public static void main(String argv[]) throws IOException
{
// The following two lines were suggested by the following
website:
// http://www.javaworld.com/javaworld/j...javatip96.html
// They help in suppressing the java.net.Malfor medURLException
System.setPrope rty("java.proto col.handler.pkg s",
"com.sun.net.ss l.internal.www. protocol");
Security.addPro vider(new com.sun.net.ssl .internal.ssl.P rovider());

BufferedReader br;
String origName;

if(argv.length != 0)
{
br = new BufferedReader( new FileReader(argv[0]));

// Read URLs from the file. Skip blank lines and lines
beginning
// with the '#' character.
for(;;)
{
origName = br.readLine();
if(origName == null)
break;

origName = origName.trim() ;

if(origName.len gth() == 0)
continue;

if(origName.cha rAt(0) == '#')
continue;

URL url = new URL(origName);
if(url == null)
continue;

BufferedReader bufRdr = new BufferedReader( new
InputStreamRead er(url.openStre am()));

// The name of the file to which the website contents are
written
// is derived from the URL by substituting the following
characters
// with some "non-offending" character:
// \,/,:,*,?,",<,>,|

String modName = origName;
modName = modName.replace ('\\', replaceChar);
modName = modName.replace ('/', replaceChar);
modName = modName.replace (':', replaceChar);
modName = modName.replace ('*', replaceChar);
modName = modName.replace ('?', replaceChar);
modName = modName.replace ('"', replaceChar);
modName = modName.replace ('<', replaceChar);
modName = modName.replace ('>', replaceChar);
modName = modName.replace ('|', replaceChar);

FileWriter fWriter = new FileWriter(modN ame);
System.out.prin tln("Writing contents of " + origName + " to "
+
"the following file: " + modName);
for(;;)
{
String thisLine = bufRdr.readLine ();
if(thisLine == null)
break;

fWriter.write(t hisLine);
}
}
}
}
}

/////////////////// Source code end //////////////////////

Jul 17 '05 #2
HttpClient should solve your problem:
http://jakarta.apache.org/commons/ht.../sslguide.html

"Tom N" <to*@nospam.a u> wrote in message news:<sC******* ************@ne ws-server.bigpond. net.au>...
See http://sunsolve.sun.com/pub-cgi/retr...salert%2F57436

The error is because the Class 3 and Class 2 root certificates installed in
your version of Java have expired. It says you can either download the
latest JRE or JDK or you can download certificates from verisign and install
them.

I tried your code and the following is the status of a list of URLs before I
updated the certificate. I am using JDK 1.4.1_02-b06 by the way. This list
is taken from the Javaworld article you referenced.

https://www.verisign.com/ failed
https://happiness.dhs.org/ failed
https://www.microsoft.com worked
https://www.sun.com failed (IIRC)
https://www.ftc.gov failed

Interestingly, those that failed did not all have the same exception thrown.

I updated the cert's as detailed in the sunsolve article and now all of the
URLs worked except dhs.org, which is because it uses a self-signed
certifcate (not using a Verisign or similar root certificate).

"Generic Usenet Account" wrote:
I am trying to create a Java application that reads a list of URLs
from a file and stores their contents on the local file system. I
have succeeded in accessing normal websites, but I am unable to access
the secured websites (using the HTTPS protocol) using this approach.

I would greatly appreciate if someone could suggest a way out. I have
looked at the HttpsURLConnect ion class, but unfortunately this class
is abstract.

[My apolgies to readers of comp.lang.java and comp.sources.d since
this posting may appear to be a repost of my previous posting
(although it is not) --- Bhat]

My source code follows:

/////////////////// Source code begin /////////////////////

// This program reads a list of URLs to access and store on the local
// file system from a file. The name of the file is passed as the
// first command line argument. Each URL is on a separate line.
// Lines beginning with the '#' character are treated as blanks and
// are skipped.
//
import java.io.*;
import java.net.*;
import java.security.* ;
class WebsiteLoader
{
public static char replaceChar = '~';

public static void main(String argv[]) throws IOException
{
// The following two lines were suggested by the following
website:
// http://www.javaworld.com/javaworld/j...javatip96.html
// They help in suppressing the java.net.Malfor medURLException
System.setPrope rty("java.proto col.handler.pkg s",
"com.sun.net.ss l.internal.www. protocol");
Security.addPro vider(new com.sun.net.ssl .internal.ssl.P rovider());

BufferedReader br;
String origName;

if(argv.length != 0)
{
br = new BufferedReader( new FileReader(argv[0]));

// Read URLs from the file. Skip blank lines and lines
beginning
// with the '#' character.
for(;;)
{
origName = br.readLine();
if(origName == null)
break;

origName = origName.trim() ;

if(origName.len gth() == 0)
continue;

if(origName.cha rAt(0) == '#')
continue;

URL url = new URL(origName);
if(url == null)
continue;

BufferedReader bufRdr = new BufferedReader( new
InputStreamRead er(url.openStre am()));

// The name of the file to which the website contents are
written
// is derived from the URL by substituting the following
characters
// with some "non-offending" character:
// \,/,:,*,?,",<,>,|

String modName = origName;
modName = modName.replace ('\\', replaceChar);
modName = modName.replace ('/', replaceChar);
modName = modName.replace (':', replaceChar);
modName = modName.replace ('*', replaceChar);
modName = modName.replace ('?', replaceChar);
modName = modName.replace ('"', replaceChar);
modName = modName.replace ('<', replaceChar);
modName = modName.replace ('>', replaceChar);
modName = modName.replace ('|', replaceChar);

FileWriter fWriter = new FileWriter(modN ame);
System.out.prin tln("Writing contents of " + origName + " to "
+
"the following file: " + modName);
for(;;)
{
String thisLine = bufRdr.readLine ();
if(thisLine == null)
break;

fWriter.write(t hisLine);
}
}
}
}
}

/////////////////// Source code end //////////////////////

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3080
by: Achim Kühn | last post by:
I´m planning to write a windows application using the .net framework. is there any way to secure the application so the user can´t easily disassemble and manipulate the application?
5
14716
by: Hassan Naqvi | last post by:
Hi, Basically, I am Java developer. In past I have played with Oracle using Java (JDBC). But this is the time to play with IBM DB2 using Java (JDBC). So kindly help this DB2 newbie. I have a file of 32 MB, named as "fdbk5.0". This is actually a database created in DB2 and containing records. I am interested in viewing the *structure of this database, i.e. table names, column names and finally all the records. How I can do this? Which...
4
1609
by: reezaali | last post by:
Hi All, I wanted to set up my websites like this c:\websites\intranettemplate c:\websites\app1 c:\websites\app2 Basically I wanted to have the master pages defined in the template folder and all other apps would "reference" this folder to get the
5
3064
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet explorer would do in this case. The headers I am getting are: Headers {Content-Disposition: attachment; filename="dynamic_file.mdb" Connection: close Cache-Control: private Content-Type: application/octet-stream
2
2524
by: gurnandank | last post by:
Hi, I have a web application which uses SSL on one the folders. When I developed application the set up was webroot and under that folder called 'secure'. My ISP has provided a folder called 'secure' on the server which has shared SSL and is sitting outside of the web root, hence the set up called 'secure' and then at the same level a folder called web root. Now, I have two issues:
7
6053
by: Tlange | last post by:
We need to interface from VB.NET to a third party product. They provide an API that was written in Java and is distributed as a JAR file. What are the options for accessing the objects/methods/etc. in a JAR file from VB.NET?
6
5455
by: Siddharth | last post by:
Hi all, I have been trying to access a web service over HHTPS but have not been successful. The client has provided us with a pfx file that is password protected. I successfully exported the certificate to .cer format. My code is using WSE to access the web service. I basically load the certificate from the personal store and attach it to the web service proxy object. However, I keep getting the error: "The underlying connection was...
3
5006
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : >************************************************************************ > <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _ > Public Function HelloWorld() As > <System.Xml.Serialization.SoapElementAttribute("return")> String
0
2792
by: TeenaRoz | last post by:
Hi, Can some one help me in finding out why this exception occurs when ever I try to load a particular JSP page? Oct 29, 2008 4:23:54 AM org.apache.catalina.loader.WebappClassLoader loadClass INFO: Illegal access: this web application instance has been stopped already (the eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and...
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.