• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Getting error while displaying tif image in applet through browser.

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an applet which displays tif image using JAI api.
When I try to run applet as standalone program it work fine and display image but when I call this applet through jsp it doesnt work.
It gives error like

java.lang.NoClassDefFoundError: com/sun/media/jai/codec/SeekableStream
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


I have installed JAI api in JDK directory and I am using Netbeans IDE.

Applet tag in JSP file is as below
<applet code="com.bsic.pimg.MyApplet" archive="ImageViewer.jar">

ImageViewer.jar file contains class file for MyApplet.java.

So can you please tell me what is wrong ?

Thanks in advance.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Does ImageViewer.jar contain the JAI classes as well? If not, then you need to add the JAI jar file to the archive attribute.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have included jai_core.jar and jai_coded.jar in archive attribute.
When I run the jsp it was run without error.
In bottom of the browser it shows "Applet com.bsic.pimg.MyApplet started".
But it does not show tif image. Whole page comes blank.

so what can be the problem ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the Java Console to see if there are any error messages.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I right click on browser it does not give any opition for java console.
Even in my Netbeans ide there is no any error.
i am using mozilla firefox.
Also browser gets hanged after runnig application.

so how can i check java console ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java Conole can be accessed through the Java Plugin control panel. If you're on Windows, then there should be a small coffee cup icon in the tray on the lower right hand side of the screen that you can use as well.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it shows the error

java.security.AccessControlException: access denied (java.io.FilePermission D:\BsicRw\Tomcat5.2\webapps\PImgViewer\web\PolImages\002201001_111036_014.tif read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at java.security.AccessController.checkPermission(AccessController.java:427)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.FileInputStream.<init>(FileInputStream.java:100)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at com.bsic.pimg.MyApplet.init(MyApplet.java:52)
at sun.applet.AppletPanel.run(AppletPanel.java:380)
at java.lang.Thread.run(Thread.java:595)
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So it looks as if the applet isn't signed correctly. When starting the applet, do you get the little popup window that asks you to accept the certificate?
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no i have not got any such popup.
how can i signed the applet ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See HowCanAnAppletReadFilesOnTheLocalFileSystem
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it seems long process for signing applet and also require purchase of certificate.
I just want to show image by reading it from local directory.

Is there any other way to make it possible ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, signing an applet isn't particularly hard, and you can create the certificate yourself using the tools shipped with the JDK. There's no need to purchase anything.

You need to use "keytool" to create a key/certificate, and then "jarsigner" to use the certificate to sign the jar. Shouldn't take more than an hour to figure it out and then do it.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have follow the step as given in link SigningApplet

I have completed upto step 6.

Path for my html is D:\NetBeansProjects\ImageViewerWeb\web
From where I have to run html file TestImg.html

content of html is as
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h2>Hello World!</h2>
<applet code="com.bsic.pimg.MyApplet" archive="SImageViewer.jar,jai_codec.jar,jai_core.jar" width="400" height="600">
</applet>
</body>
</html>


Path for the following files is same as TestImg.html

CompanyCer.cer
compstore
dksstore
SImageViewer
Write.jp

content of the Write.jp file is as below

keystore "D:/NetBeansProjects/ImageViewerWeb/web/dksstore";

grant SignedBy "company" {
permission java.io.FilePermission
"D:/", "read";
};



I have executed following commands as applet developer

(1) keytool -genkey -alias signFiles -keystore compstore -keypass pass123 -dname "cn=dks" -storepass pass456

(2) jarsigner -keystore compstore -storepass pass456 -keypass pass123 -signedjar SImageViewer.jar ImageViewer.jar signFiles

(3) keytool -export -keystore compstore -storepass pass456 -alias signFiles -file CompanyCer.cer

After that as a client have exectued following command

(1) keytool -import -alias company -file CompanyCer.cer -keystore dksstore -storepass pass789

When I run following command

appletviewer -J-Djava.security.policy=Write.jp TestImg.html.html

getting the same error

java.security.AccessControlException: access denied (java.io.FilePermission D:\UnderTheSun.gif read)


So can you please guide me is there anything i have missed out in signing applet ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to alter any policy files. If the applet is signed, then that is redundant (it's an alternative method to grant permissions).

There's also no need for the "keytool -export" and "keytool -import" steps.

Note that all involved jar files need to be signed - that includes the JAI jar files.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have signed JAI jar files and tried to run html but it still gives the access denied error.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dear,

At last I have done it. Now I can see TIFF file in browser.

Thanks for giving your valuable time in response.

Thank you very much.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On my machine it runs perfectly.
When i try to run link from another machine it give popup with run button.
When I click run button image does not get displayed.

Should I have to do import and export step for that ?

how can I acces it from another machine ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When i try to run link from another machine it give popup with run button. When I click run button image does not get displayed.


Any error messages in the Java Console?

Should I have to do import and export step for that ?


No. Those steps are not needed for signing an applet.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I see another machine's console it gives FileNotFoundException for image path.

I have given image path in applet hardcoded of my local machine. So is applet trying to find that path on client's machine ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So is applet trying to find that path on client's machine ?


Of course. An applet can access files only on the local machine where it's running, not on some other machine. Should this particular image be used wherever the applets is run? If so, put it on the web server along with the other applet files, and access it as shown in the LoadAGif example.
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two applicatin in Netbeans.
One is ImageViewer which contains my applet which shows image.
Second is ImageViewerWeb which contains index.jsp to display image in browser
and packages jar file generated by ImageViewer.

I have tried putting image in two places
(1) In ImageViewer I have put image where applet is.
(2) In ImageViewerWeb I have put image where applet jar file resides.

for both cases it does not work when i access in another machine.

So where to place image ?

Is there any way to access server path through applet ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forget about NetBeans. You need to put all those files on a proper web server for another machine to be able to access them. What's the location of all the files involved? What are the error messages you're getting?
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
location of all jar files and jsp file is ImageViewerWeb/Web/

Getting exception as

java.io.FileNotFoundException: \ImageViewerWeb\002201001_111036_014.tif (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at com.bsic.pimg.MyApplet.init(MyApplet.java:136)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

my code for getting image path is

URL url = getCodeBase();
path = url.getPath()+"002201001_111036_014.tif";
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

URL url = getCodeBase();
path = url.getPath()+"002201001_111036_014.tif";


That's not how you load images in applets, particularly not from the remote server. You can get an InputStream from which to read the image using something like:

URL url = new URL(getCodeBase() + "/002201001_111036_014.tif");
InputStream is = url.openStream();
 
dhiren sangani
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Now I can view TIFF image successfully on client site also.
Below is the my modified code.

MediaTracker tr = new MediaTracker(this);

URL url = new URL("http://serveripadddress:port/applicationname/tiffilename");

ReadableByteChannel rBytChnl = Channels.newChannel( url.openStream() );
ByteBuffer buffer = ByteBuffer.allocate(4096*1024);
rBytChnl.read(buffer);

byte[] data = buffer.array();
SeekableStream stream = new ByteArraySeekableStream(data);
String[] names = ImageCodec.getDecoderNames(stream);
ImageDecoder dec = ImageCodec.createImageDecoder(names[0], stream, null);
RenderedImage im = dec.decodeAsRenderedImage();
Image image = PlanarImage.wrapRenderedImage(im).getAsBufferedImage();

img = image.getScaledInstance(500, -1, Image.SCALE_SMOOTH);
System.out.println("image: " + path + "\n" + image);
tr.addImage(img,0);


Thanks a lot for your quick response.
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic