Applets r/w via HTTPS protocol

Posted on 1998-11-24
Last Modified: 2012-06-21
Can non-signed applet do HTTPS read/write to URL as it can do with HTTP protocol.

1. same site where from it was loaded in browsers
2. on developing stage I need to load applet from local file
and connect to server via HTTPs

That's what I have:
try{String s="";
    URL u=new URL(s);
    URLConnection c = u.openConnection();
    DataInputStream is =
       new DataInputStream(c.getInputStream());
    PrintStream outStream =
       new PrintStream(c.getOutputStream());
    String outstring="score="+myscore+"&myname="+name;
    String inputLine;
    while ((inputLine = is.readLine()) != null)
           {// lines processing here
catch(Exception e)
   {System.out.println(e); ret=-1;}

What I need? Same but with HTTPS protocol.

Example code is greatly appreciated
Code should work at least in NN4, MIE4 and JDK1.1x appletviewer

Points is subject to be significantly increased for good clear and working example.

Question by:kollegov
  • 7
  • 6

Expert Comment

ID: 1228180
Simply specify that you are using the https protocol when you format the URL:

String s="";
URL u=new URL(s);

(of course, the server has to support HTTPS...)

This should work with both Netscape 4 and Explorer 4. This will not work with the appleviewer
as the JDK does not provide support for the https protocol. If you have a try with the
appletviewer, you will have a MalformedURLException. For testing in the appletviewer,
you can use http, and https for the "real life" test when you think all is OK: this has
indeed no real impact for the programming.

I let you test this. Tell me if you are happy with this answer.
LVL 10

Author Comment

ID: 1228181
Not quite happy :(
I already tried https:// in appletviewer and got IOException
unknown protocol https.
The problem is that .pl script is running on other server
and ONLY at secure port. So debugging is quite difficult
if I can't run it in appletviewer.
Uploading each time applet to server involves thier system
administrator, and due to 12 hours time difference it's
not easy to do fast. :(
Is there any way to enable connection to third side HTTPS URL
if I load applet in NN4 or MIE4 from local file?
Just for debugging stage of development


Expert Comment

ID: 1228182
As I said, as there is no support for https in the JDK, https URLs are not understood
and if you try to use one you have a MalformedURLException. I see two options:

- Add https support. This supposes to have an https protocol handler in the CLASSPATH.
  One way to get a free https protocol handler is to load the trial version of the
  Java Web Server with SSL support ( The implementation
  of the https protocol handler is indeed available in the jws.jar archive under the
  "lib" sub-directory.

  Once that you have https support, you will also have to solve the security problem that
  comes from the fact that you are not loading the classes from the server but from
  the local disk. If I remember well, if the applet classes are available locally, via the
  CLASSPATH or installed in the classes directory of the browser, they are trusted
  (and hence, no signing would be required). Ensure your classes are available in the     CLASSPATH before having a try with the browser. If you want to install the classes
  directly in the browser, here is the path to the directory for Netscape Communicator
  on a PC (path for the default installation of NC):

  c:\Program Files\Netscape\Communicator\Program\Java\Classes

- Ask the admin for the Perl script and install it on your local server. If you don't have
  an https server by hand, the Java Web Server can again be helpful. In this case,
  you are removing the uploading problem that prevents you from easily testing
  your development.
LVL 10

Author Comment

ID: 1228183
Hmmm, I just try to move
all files to
c:\Program Files\Netscape\Communicator\Program\Java\Classes

class, .html and 3 images applet use

Very surprizing result,
at Code)
at Code)

Looks like image couldn't be find.
I doublecheck, all 3 are there!

Meanwhile the same set of files works fine if placed in any
other directory (at least while it don't connect to https port)

To get images I use

In applet tag no CODEBASE attribute set, so it should point
to DOCUMENT directory by default.. And
document itself, class and images are in the same

Any ideas?

BTW the result is same, when I place only .class file in
this directory and left HTML and images at original location


Expert Comment

ID: 1228184
You could maybe have a look at this article. It explains how to install an applet at the
client-side, as I suggested:

Could you verify that a: URL url = new URL(getCodeBase(), "imname.gif");
does not throw an exception?

You could also try using getResource() or getResourceAsStream() to load the
LVL 10

Author Comment

ID: 1228185
After reading this article, you mentioned, looks like I find way (in theory) how to avoid this problems
in case I put applet (only applet) in NN/classes directory
and all other resources (html and image)
I'll put on server, they are static and don't require to be modified , I'll have local class loaded instead of
one from server, and this shouldn't cause security exceptions
when I connect to remote server form the applet...

Looks like this should work :)
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

LVL 10

Author Comment

ID: 1228186
Sorry for delay, I solved the puzzle, Thanks for help.
Fontanie you are welcome to post the answer..


Accepted Solution

fontaine earned 250 total points
ID: 1228187
OK, I lock the question. What option have you used, finally?
LVL 10

Author Comment

ID: 1228188
Actually, none, just closed my eyes and write bug-free
solution from first attempt. I tested all what I can locally
emulating connection by reading from file and connection to
my local unsecure server with simplified stub of the script
and than changed to reading/writing using HTTPS..

Expert Comment

ID: 1228189
That was actually what I was proposing in my first comment for testing in the appletviewer.
The only problems I can see if you use http for the development and https for the
publication are the following:

- https connections are much slower than http ones (-> use https when strictly needed,
  http for normal communications);
- users behind a firewall could expect connection problems if the config does not allow
  the use of the https protocol.
LVL 10

Author Comment

ID: 1228190
Opppsss, forgot to grade your answer, thanks for help.

Expert Comment

ID: 1228191
Woow! Thank you very much!
LVL 10

Author Comment

ID: 1228192
No problems. Just was interesting to solve one more puzzle.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now