Solved

Applets r/w via HTTPS protocol

Posted on 1998-11-24
13
444 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

760 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

23 Experts available now in Live!

Get 1:1 Help Now