Question

I've created an applet that uses JavaPOS to communicate with a payment terminal on the user's local system.

When run from within the Eclipse IDE, the applet works fine, but not when run in a browser. In a browser, the applet can't seem to find the jpos/res/jpos.properties and jposxml.cfg files.

When the following statements are executed in the applet (in the start() method, not init()):

JposEntryRegistry registry = JposServiceLoader.getManager().getEntryRegistry();
registry.load();

this is the output I see in the Java console window:

jpos/res/jpos.properties file not found
jpos/res/jpos.properties file not found
jpos/res/jpos.properties file not found

And no entries are loaded in the JposEntry registry.

I've tried the following to get the applet to "see" the two files:

  1. jpos/res/jpos.properties is already present in one of the jars referenced by the applet. Nevertheless, I've added this file to the applet's main jar. I've also tried adding it to the directory on the server containing the jars (with the correct relative path). None of this works.

  2. I can work around the inability of jpos.properties to be found by setting System properties with the appropriate values, like this:

    System.setProperty("jpos.loader.serviceManagerClass", "jpos.loader.simple.SimpleServiceManager");
    System.setProperty("jpos.config.populatorFile", "jposxml.cfg");
    System.setProperty("jpos.util.tracing.TurnOnNamedTracers", "JposServiceLoader,SimpleEntryRegistry,SimpleRegPopulator,XercesRegPopulator");
    System.setProperty("jpos.util.tracing.TurnOnAllNamedTracers", "ON");
    

    However, the applet still can't find jposxml.cfg. This file is present in the root of the applet's main jar file. I've tried putting on the server in the same directory as the jars. I've also tried creating a separate jar file containing only jposxml.cfg, but that doesn't work either. I get the following output in the Java console window:

    [AbstractRegPopulator]getPopulatorFileIS(): populatorFileName=jposxml.cfg
    [JposServiceLoader]manager.getEntryRegistry().load() OK
    [AbstractRegPopulator]getPopulatorFileIS(): populatorFileName=jposxml.cfg
    

    But the list of JposEntries is empty. As a result the applet can't communicate with the payment terminal.

The applet is loaded via a JNLP file (and all required jars via a JNLP extension). Both JNLP files have security set to <all-permissions/>. All jars are signed with the same certificate. The same code works perfectly in Eclipse. Any ideas on what the problem is?

Was it helpful?

Solution

This is for the reference of anyone facing a similar problem.

I couldn't get the JavaPOS code to see the jpos.properties file, but loading the values into System properties as described above works, so I'll stick with that for now.

To have JavaPOS load jpos.xml or jposxml.cfg from a URL, you need to set the property jpos.config.populatorFileURL and not jpos.config.populatorFile. This can be set either in jpos.properties, or failing that, as a System property.

OTHER TIPS

Faced same problem.

JposServiceLoader uses classpath to look for the root of path.

For example, if local classpath for application is

C:/myapp/target/classes

then jpos.properties should be by path

C:/myapp/target/classes/jpos/res/jpos.properties

P.S. Maybe it is not a best way to place jpos files, but at least it is something you can start with solving this issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top