• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't deploy an applet using <applet> tag (open HTTP connection failed)

 
Ranch Hand
Posts: 65
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
So, I've got a working applet (checked that using applet viewer), but having real troubles to deploy it. We've got a JSF project, and an applet is being called from a <ui:composition/>. The class file is packaged in a jar archive. Here is the code I use:

And the exception that I got:


I tried using fully qualified name for my class in the code attribute. I also tried to add .class to a class name. Neither did work. I just don't really understand the "open HTTP connection failed" exception. When I tried to deploy simple applets on my local machine I used to get FileNotFoundException, which is more obvious. So, the problem is that I need to specify URL for my *.jar file. Still very confused about how to do this.
Any help would be highly appreciated.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do indeed need to provide the full-qualified class name.

Where is the hello.jar file located? It must be URL/directory as the page that contains the applet tag. You can take a look at the access log files to see of it is being accessed, and also all the alternate locations where the client JVM tries to download it.
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your quick reply, Lester.

Lester Burnham wrote:Where is the hello.jar file located?


Well I included it in build path (I'm using Eclipse). And just in case, I put another copy into the same directory from where the applet is being invoked.

It must be URL/directory as the page that contains the applet tag


I just don't know how to give a URL to a jar. When I tried to use codebase attribute to specify an archive location, but it was just appended to http://localhost/umms-web/. So, do I need to deploy a jar, as a war archive to, sort of, bind it to specific URL? Because, I understand that searching for it on a filesystem doesn't make any sense.

You can take a look at the access log files


Hm.. Would you give me a hint, where are those located?
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well I included it in build path (I'm using Eclipse). And just in case, I put another copy into the same directory from where the applet is being invoked.


Eclipse is an IDE - it has no bearing on what happens at runtime. The jar file must in a publicly accessible directory on the web server.

I just don't know how to give a URL to a jar. When I tried to use codebase attribute to specify an archive location, but it was just appended to http://localhost/umms-web/. So, do I need to deploy a jar, as a war archive to, sort of, bind it to specific URL?


The name of the jar file (as given in the archive attribute) is appended to the base URL of the page request. For example, if the page is accessed via http://www.server.com/myApp/myDir/myPage.html, then the jar file must be http://www.server.com/myApp/myDir/hello.jar. You can change the directory by using the codebase attribute, but I'd advise to get it working without that first.

Would you give me a hint, where are those located?


Depends on your server. For Tomcat, they're in TOMCAT_HOME/logs/access.log or something like that, but you need to enable access logging in the server.xml file.
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lester Burnham wrote:
The name of the jar file (as given in the archive attribute) is appended to the base URL of the page request.


Well, in my case, it's the name of a class that gets appended to the base URL. We're using Glassfish as an Application Server. Seems like I have to deploy this jar as a web application to make it accessible by URL. Am I wrong?
 
Lester Burnham
Rancher
Posts: 1337
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well, in my case, it's the name of a class that gets appended to the base URL.


Yes, if the client JVM can't find the class in the jar file, then it will look for loose class files on the server. That's an indication that the jar file isn't found. Check the access log to see at which location the browser looks for that jar file, and compare that to its actual location.

Seems like I have to deploy this jar as a web application to make it accessible by URL. Am I wrong?


Yes, you're wrong. jar files used by applets are just static files as far as the server is concerned. If they're in a publicly accessible directory, then the browser JVM will find them, provided all the parameters of the applet tag are correct. See http://download.oracle.com/javase/1.4.2/docs/guide/misc/applet.html for details. It's probably easier to get a simple example applet -that uses a jar file- up and running outside of your current project; that will give you an idea of how it works.
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help. I actually tried everything you proposed to no avail, and just started to write this post. But before submitting I tried once again and it worked! I guess it has something to do with restarting browser or clearing cache, but anyway, I know what I'm doing know. Another thing which was kind of inconvenient is that I needed to add policy file. Moreover adding policy file to the jar at the same level with META-INF and the package with compiled classes didn't do the trick. So I was forced to add a .java.policy file to my ${user.home} directory, and now finally after 2 days of banging my head on a wall, I've got my applet shining and working! Thanks once again!
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So I was forced to add a .java.policy file to my ${user.home} directory


Oh, so the applet does something it wouldn't normally be allowed to do. If you have controlled user desktops (like in a company), this may be OK, but in my experience it's too much to ask an average user out there to deal with policy files. In that case, signing the applet works much better.
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lester Burnham wrote:In that case, signing the applet works much better.


Yeah, I guess I'll have to dig a bit deeper to learn about signing applets. Although I'm still confused, why including a policy file in a jar didn't work... But I'm sure that the applet's security policy is much more versatile than I think
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yeah, I guess I'll have to dig a bit deeper to learn about signing applets. Although I'm still confused, why including a policy file in a jar didn't work...


Because that would amount to the applet granting itself privileges. Also, policy files need to be present when the JVM starts up. If you want to learn more, start here: HowCanAnAppletReadFilesOnTheLocalFileSystem
 
Anton Shaikin
Ranch Hand
Posts: 65
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lester Burnham wrote:Because that would amount to the applet granting itself privileges.


Yes, now it looks obvious to me. Today I suffered really hard from the policy file that I created 2 days ago. I put it in my ${user.home} directory and granted all permissions to the jre. Then I tried to guess why our application deployed on glassfish was redirecting me to index.jsf instead of a login page. It turned out that the root of the problem was in that damn policy file (or in my misunderstanding of importance of this file?). Anyway, now I got the point - "need to grant your applet specific permissions? - sign it".
Thanks again for help!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic