Java applet can't find JavaPOS configuration files
Asked Answered
V

3

2

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?

Vaccinate answered 3/4, 2012 at 16:17 Comment(1)
I have the same issue. It it related to trying to load sunrsasign.jar when trying to load the jpos.properties file but that jar is only included in earlier JDK. Any idea why it is trying to load this file?Saire
V
5

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.

Vaccinate answered 11/4, 2012 at 9:27 Comment(0)
P
1

you have 2 ways:

  1. ignore this error and set properties from the code(as mentioned before)

     System.setProperty("jpos.config.populatorFile", "jposxml.cfg");  
     System.setProperty("jpos.util.tracing.TurnOnNamedTracers", "JposServiceLoader,SimpleEntryRegistry,SimpleRegPopulator,XercesRegPopulator");  
     System.setProperty("jpos.util.tracing.TurnOnAllNamedTracers", "ON"); 
     System.setProperty("jpos.loader.serviceManagerClass", "jpos.loader.simple.SimpleServiceManager")
    
  2. extract you jposXXX.jar(usually XXX means version),
    add jpos.properties and jpos.xml files to the folder jposXXX/jpos/res/,
    convert folder jposXXX to jar file
    for example via command in terminaljar cvf jposXXX.jar jposXXX
    put jar file to app/libs/ folder
    add to your gradle dependencies line

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    enjoy

Pals answered 6/1, 2022 at 15:56 Comment(0)
T
0

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.

Telemotor answered 30/11, 2017 at 12:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.