[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

Applets r/w via HTTPS protocol

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
kollegov
Asked:
kollegov
  • 7
  • 6
1 Solution
 
fontaineCommented:
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
 
kollegovAuthor Commented:
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
 
fontaineCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kollegovAuthor Commented:
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
 
fontaineCommented:
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
 
kollegovAuthor Commented:
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
 
kollegovAuthor Commented:
Sorry for delay, I solved the puzzle, Thanks for help.
Fontanie you are welcome to post the answer..


0
 
fontaineCommented:
OK, I lock the question. What option have you used, finally?
0
 
kollegovAuthor Commented:
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
 
fontaineCommented:
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
 
kollegovAuthor Commented:
Opppsss, forgot to grade your answer, thanks for help.
0
 
fontaineCommented:
Woow! Thank you very much!
0
 
kollegovAuthor Commented:
No problems. Just was interesting to solve one more puzzle.


0

Featured Post

Technology Partners: 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!

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now