aspose file tools*
The moose likes Applets and the fly likes Cannot run Apache HttpClient in applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Cannot run Apache HttpClient in applet" Watch "Cannot run Apache HttpClient in applet" New topic
Author

Cannot run Apache HttpClient in applet

Hare Shiva
Greenhorn

Joined: Jul 08, 2012
Posts: 12
i am constructing an applet that upload multiple files and sends it to servlet for storage..Following is my applet code






I am using netbeans and in applet viewer it works fine.But when i use it in jsp page,it gives me following errors

/**************************************************/

Java Plug-in 1.6.0_25
Using JRE version 1.6.0_25-b06 Java HotSpot(TM) Client VM
User home directory = C:\Users\Computer
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
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.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 20 more
Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient

/******************************************************************************/

i added jar file of applet in my web project.Please guys help me..if there is any other way to upload images than please post be the codes.Its urgent.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

You do have to specify the applet's classpath (via the "archive" attribute of the <applet> tag, I think). Presumably you set up the classpath in Netbeans, now you have to do that for your HTML as well.
Hare Shiva
Greenhorn

Joined: Jul 08, 2012
Posts: 12
Paul Clapham wrote:You do have to specify the applet's classpath (via the "archive" attribute of the <applet> tag, I think). Presumably you set up the classpath in Netbeans, now you have to do that for your HTML as well.


in jsp portion i wrote this code


i m using netbeans so i build that applet project and pasted it in my web page.Other applet project i did worked in the same way.Do you know any other method of sending image.If then please post codes.I m beginner in java and i really need to complete it soon.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Hare Shiva wrote:in jsp portion i wrote this code


i m using netbeans so i build that applet project and pasted it in my web page.Other applet project i did worked in the same way.Do you know any other method of sending image.If then please post codes.I m beginner in java and i really need to complete it soon.


And now we can all see that the "archive" attribute does not mention the jar which contains Apache HttpClient. So fix that. Make sure that the jar is in your web application, preferably in the same folder as the apptesting.jar, so that it can be downloaded to the client.

And no, we don't post code here. Read our FAQ entry DoYourOwnHomework which explains why we don't do that.
Hare Shiva
Greenhorn

Joined: Jul 08, 2012
Posts: 12
Paul Clapham wrote:
Hare Shiva wrote:in jsp portion i wrote this code


i m using netbeans so i build that applet project and pasted it in my web page.Other applet project i did worked in the same way.Do you know any other method of sending image.If then please post codes.I m beginner in java and i really need to complete it soon.


And now we can all see that the "archive" attribute does not mention the jar which contains Apache HttpClient. So fix that. Make sure that the jar is in your web application, preferably in the same folder as the apptesting.jar, so that it can be downloaded to the client.

And no, we don't post code here. Read our FAQ entry DoYourOwnHomework which explains why we don't do that.



Thanks a lot for your help.Now my applet runs in the browser but it cannot connect to servlet as it did when running in applet viewer.My servlet is in Project test, in "servlet" package.So can i use servlet url as"http://localhost:8080//test//Uploader".Please be patient with me. I am new to java and i am a student.
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
Are you the same person that asked this question on SO?


Andrew Thompson
http://pscode.org/
Hare Shiva
Greenhorn

Joined: Jul 08, 2012
Posts: 12
Andrew Thompson wrote:Are you the same person that asked this question on SO?


Yes.If you have any suggestion then please help me.How can my applet connect to servlet.The applet works fine in applet viewer and send files to servlet.But cannot send file to servlet when used in browser.I printed test statements in servlet but neither of them shows so it means applet couldnot connect to that servlet.Should i do anything else.i using netbeans and i did following steps

1.Created a applet as separate project.
2.Build it and pasted in location of my jsp pages.
3.All jar files used by the applet have been written in archive.

What else should be done.Please help.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

I suppose it might help if you stopped using the invalid URL "http://localhost:8080//test//Uploader" and corrected it to "http://localhost:8080/test/Uploader", but I suspect that isn't your problem.

However I don't know what your problem is. You didn't say whether any exceptions were being thrown -- so tell us that. And you said your servlet wasn't being run, but you didn't say whether the applet was even connecting to the servlet -- so tell us that. It's no use telling us what should have happened -- tell us what actually happened instead.
Hare Shiva
Greenhorn

Joined: Jul 08, 2012
Posts: 12
Paul Clapham wrote:I suppose it might help if you stopped using the invalid URL "http://localhost:8080//test//Uploader" and corrected it to "http://localhost:8080/test/Uploader", but I suspect that isn't your problem.

However I don't know what your problem is. You didn't say whether any exceptions were being thrown -- so tell us that. And you said your servlet wasn't being run, but you didn't say whether the applet was even connecting to the servlet -- so tell us that. It's no use telling us what should have happened -- tell us what actually happened instead.


I get no exception when running from applet viewer.Applet that is in separate netbeans project can send file to servlet that is in another web project.But the same don't happen when running applet from web page.I dont think there is any problem with code because if there were any than it shouldnot have worked in applet viewer too,isnt it? And yes i corrected my url but still there is the same problem.I dont know how to see exception when applet runs in web browser.My applet shows up in browser and i can even select file but than nothing happens . The file is not sent to servlet and it shows no error too.How do i check what exception occur because netbeans shows none when applet is running in browser? I am exploring other possibilities of sending file through applet because i need it soon for my academic project.If you could look upon check this code please to find any error i would be very thankful.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Hare Shiva wrote:I dont know how to see exception when applet runs in web browser.


You'll see a "Java" icon in your taskbar (I'm correct in assuming you're using Windows, right?). Double-click that and look in the Java console, that's where System.out and System.err go, along with errors which you don't catch.

I'm not looking at your code because if something works in Setup A but not in Setup B then it's probably something to do with the configuration and not the code.
Hare Shiva
Greenhorn

Joined: Jul 08, 2012
Posts: 12
Paul Clapham wrote:
Hare Shiva wrote:I dont know how to see exception when applet runs in web browser.


You'll see a "Java" icon in your taskbar (I'm correct in assuming you're using Windows, right?). Double-click that and look in the Java console, that's where System.out and System.err go, along with errors which you don't catch.

I'm not looking at your code because if something works in Setup A but not in Setup B then it's probably something to do with the configuration and not the code.


Yes it did give exception.


Java Plug-in 1.6.0_25
Using JRE version 1.6.0_25-b06 Java HotSpot(TM) Client VM
User home directory = C:\Users\Computer
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


Check
Absolute path is C:\Users\Computer\Documents\31_free_buttons_psd_file_452.JPG
java.security.AccessControlException: access denied (java.io.FilePermission C:\Users\Computer\Documents\31_free_buttons_psd_file_452.JPG read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.length(Unknown Source)
at sun.awt.shell.ShellFolder.length(Unknown Source)
at org.apache.http.entity.mime.content.FileBody.getContentLength(FileBody.java:114)
at org.apache.http.entity.mime.MultipartEntity.isRepeatable(MultipartEntity.java:138)
at org.apache.http.entity.mime.MultipartEntity.isChunked(MultipartEntity.java:146)
at org.apache.http.entity.HttpEntityWrapper.isChunked(HttpEntityWrapper.java:76)
at org.apache.http.protocol.RequestContent.process(RequestContent.java:106)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:515)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at testing.Upload.executeMultiPartRequest(Upload.java:191)
at testing.Upload.UploadActionPerformed(Upload.java:221)
at testing.Upload.access$100(Upload.java:38)
at testing.Upload$2.actionPerformed(Upload.java:102)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


What should i do? I signed my applet by
1.goint to webstart
2.enable web start
3.self signed by generated key

there is another option for signing but i dont know know how to use it.
Hare Shiva
Greenhorn

Joined: Jul 08, 2012
Posts: 12
Paul Clapham wrote:
Hare Shiva wrote:I dont know how to see exception when applet runs in web browser.


You'll see a "Java" icon in your taskbar (I'm correct in assuming you're using Windows, right?). Double-click that and look in the Java console, that's where System.out and System.err go, along with errors which you don't catch.

I'm not looking at your code because if something works in Setup A but not in Setup B then it's probably something to do with the configuration and not the code.


Yes it did give exception.


Java Plug-in 1.6.0_25
Using JRE version 1.6.0_25-b06 Java HotSpot(TM) Client VM
User home directory = C:\Users\Computer
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


Check
Absolute path is C:\Users\Computer\Documents\31_free_buttons_psd_file_452.JPG
java.security.AccessControlException: access denied (java.io.FilePermission C:\Users\Computer\Documents\31_free_buttons_psd_file_452.JPG read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.length(Unknown Source)
at sun.awt.shell.ShellFolder.length(Unknown Source)
at org.apache.http.entity.mime.content.FileBody.getContentLength(FileBody.java:114)
at org.apache.http.entity.mime.MultipartEntity.isRepeatable(MultipartEntity.java:138)
at org.apache.http.entity.mime.MultipartEntity.isChunked(MultipartEntity.java:146)
at org.apache.http.entity.HttpEntityWrapper.isChunked(HttpEntityWrapper.java:76)
at org.apache.http.protocol.RequestContent.process(RequestContent.java:106)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:109)
at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:176)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:515)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at testing.Upload.executeMultiPartRequest(Upload.java:191)
at testing.Upload.UploadActionPerformed(Upload.java:221)
at testing.Upload.access$100(Upload.java:38)
at testing.Upload$2.actionPerformed(Upload.java:102)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


What should i do? I signed my applet by
1.goint to webstart
2.enable web start
3.self signed by generated key

there is another option for signing but i dont know know how to use it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Oh yes, that's right, you would have to sign the applet.

Here's a link to a tutorial about signed applets, follow the part about "keytool" and "jarsigner"... How to sign a Java applet.

If that's what you already did, then make sure your HTML <applet> tag is pointing at the signed version of your applet's jar and not the old, unsigned, version.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot run Apache HttpClient in applet