File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Logging events in Applet to server using log4j? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Logging events in Applet to server using log4j?" Watch "Logging events in Applet to server using log4j?" New topic
Author

Logging events in Applet to server using log4j?

Ritesh Pareek
Ranch Hand

Joined: Nov 04, 2008
Posts: 50
Hi all,

I want to use log4j for my applet application. I did, but throwing exception while writing log file.



java.lang.ExceptionInInitializerError
at org.apache.log4j.Logger.getLogger(Logger.java:118)
at common.VoiceApplet.<init>(VoiceApplet.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
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.security.AccessControlException: access denied (java.io.FilePermission logs\log.txt write)
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.checkWrite(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:164)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:257)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:133)
at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:97)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:689)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)
... 11 more
Exception: java.lang.ExceptionInInitializerError

I googaled and got solution

1.
This isn't really a log4j question, because it is because your applet is running in the browser sandbox, and has no permission to create a Socket to any other host other than the host it was launched from.

You'll need to configure the applet to run out of the sandbox; effectively granting it access to connect to hosts other than the web server it was launched from before this will work.


2.
I think you need to write a policy fie for it which grants security permission to the java files,I faced this problem in RMI implementation.


Can any one explain how to implement above solutions

Thanks

Ritesh Pareek
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41108
    
  45
Both of the quotes are somewhat misleading. The first, because your logging code doesn't use sockets but files. Access to the local file system is indeed restricted for security reasons, but it's possible to use sockets to connect to the server where the applet was served from WITHOUT leaving the sandbox.

The second, because granting the applet access to the local file system would allow your code to run, but it doesn't help with logging to the server.

So, you need to find a way to transfer the logging information to the server, and have it logged there. The org.apache.log4j.net package supports this, in the shape of the SocketAppender (on the client) and SocketNode (on the server) classes.

Implemented this way, it should not be necessary to alter the local security policy, or to sign the applet.


Ping & DNS - my free Android networking tools app
Ritesh Pareek
Ranch Hand

Joined: Nov 04, 2008
Posts: 50
Hi Dittmer,


Thanks for one more valuable reply , actually i made a temporary solution, i just added a space at the bottom of my applet window and start printing log in to that window at run time, i don't have permission to access to server that's why i done it in this way.

Thanks for reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logging events in Applet to server using log4j?
 
Similar Threads
log4j:ERROR setFile(null,true) call failed
Wasce error - Server IBM WASCE v2.1 Server at localhost failed to start.
log4j:ERROR setFile(null,true) call failed.
Writing to a topic on remote system
SimpleSocketServer error