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.
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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 :)
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
printing a file in reverse order is easy in recursion rather than in iteration 3 57
servlet doXXX methods 3 49
runtime exception 2 28
Java string replace 11 48
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

810 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