Solved

Applets r/w via HTTPS protocol

Posted on 1998-11-24
13
453 Views
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="http://www.server.com/cgi-bin/some.pl";
    URL u=new URL(s);
    URLConnection c = u.openConnection();
    c.setDoOutput(true);
    DataInputStream is =
       new DataInputStream(c.getInputStream());
    PrintStream outStream =
       new PrintStream(c.getOutputStream());
           
    String outstring="score="+myscore+"&myname="+name;
    outStream.println(outstring);    
                 
    String inputLine;
    while ((inputLine = is.readLine()) != null)
           {// lines processing here
           }
    is.close();
   }
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.

0
Comment
Question by:kollegov
  • 7
  • 6
13 Comments
 
LVL 5

Expert Comment

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

String s="https://www.server.com/cgi-bin/some.pl";
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.
0
 
LVL 10

Author Comment

by:kollegov
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

0
 
LVL 5

Expert Comment

by:fontaine
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 (http://jserv.javasoft.com). 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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:kollegov
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,
java.lang.NullPointerException
at sun.awt.windows.WToolkit.checkScrImage(Compiled Code)
at sun.awt.windows.WComponentPeer.checkImage(Compiled 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
im=getImage(getCodeBase(),"imname.gif");

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
\Netscape\Communicator\Program\Java\Classes
directory...

Any ideas?

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

0
 
LVL 5

Expert Comment

by:fontaine
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:

http://www.javaworld.com/javaworld/jw-06-1997/jw-06-plugins.html

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
images.
0
 
LVL 10

Author Comment

by:kollegov
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 :)
0
 
LVL 10

Author Comment

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


0
 
LVL 5

Accepted Solution

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

Author Comment

by:kollegov
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..
 
0
 
LVL 5

Expert Comment

by:fontaine
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.
0
 
LVL 10

Author Comment

by:kollegov
ID: 1228190
Opppsss, forgot to grade your answer, thanks for help.
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1228191
Woow! Thank you very much!
0
 
LVL 10

Author Comment

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


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
arguments to jar 5 39
ejb on wildfly 5 45
Java syntax, or is it Selenium 6 37
passing enum to a method 4 34
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

713 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