NullPointerException triggered by FSDChannel's send method

113 views
Skip to first unread message

sirealki...@gmail.com

unread,
Jul 27, 2016, 8:29:12 AM7/27/16
to jPOS Users
Hi guys;

i am trying to use FSDMsg to send commands to thales Simulator hsm 0.9.6
i saw the some useful article in andy orrock blog and i checked the jpos user list here too
there is alot of related issues but none of'em have a solution for me :(

this is my xml files:


-------hsm-base.xml-------------

<?xml version="1.0" encoding="UTF-8"?> 
<schema> 
 <field id="command" type="A" length="2" key="true" /> 
</schema>


--------hsm-resp-base.xml----------

<?xml version="1.0" encoding="UTF-8"?> 
<schema> 
    <field id="header"   type="N" length="4" /> 
  <field id="response" type="A" length="2" key="true" /> 
  <field id="error"    type="A" length="2" /> 
</schema>

---------hsm-EC.xml--------------

<?xml
version="1.0" encoding="UTF-8"?>
<schema id='EC'>
<field id="key-type" type="N" length="3" />
<field id="key-scheme" type="A" length="1" />
<field id="component" type="A" length="32" />
</schema>

---------hsm-resp-ED.xml--------

<?xml version="1.0" encoding="UTF-8"?> 
<schema id='ED'> 
   <field id="encrypted-Component" type="A" length="33" /> 
   <field id="key-check-value" type="A" length="6" /> 
</schema> 




----------here is the code where i set up the connection-------------

public int prepare(long id, Serializable ctx) {
FSDChannel channel = new FSDChannel(); 
       Logger logger=new Logger(); 
       logger.addListener(new SimpleLogListener(System.out)); 
   channel.setHost("127.0.0.1"); 
   channel.setPort(9998); 
     channel.setPackager(new DummyPackager()); 
     try {
channel.connect();
} catch (IOException e) {
e.printStackTrace();
}
    ThalesAdaptor thales=new ThalesAdaptor(); 
    FSDMsg msg=thales.encryptClearComponent(); 
   FSDISOMsg isomsg = new FSDISOMsg(msg); 
   msg.dump(System.out, "   "); 
try { 
         channel.send(isomsg); 
         channel.receive(); 
   } catch (IOException ex) { 
           ex.printStackTrace();
   } catch (ISOException ex) { 
    ex.printStackTrace(); 
   } 
return 0;
}


-----------ThalesAdaptor.java-------------

public class ThalesAdaptor {
 public FSDMsg encryptClearComponent() { 
          return (createRequest ("EC")); 
        } 

        private FSDMsg createRequest (String command) { 
              FSDMsg req = new FSDMsg("file:cfg/hsm-"); 
        if (command != null){ 
          req.set ("command", command); 
          req.set("key-type", "000");
          req.set("key-scheme", "U");
          req.set("component", "01020304050607080901020304050607");
        } 
        return req; 
       } 

        public FSDMsg command (FSDMsg request) { 

              FSDMsg resp = null; 
              try { 


                      resp = new FSDMsg ("file:cfg/hsm-resp-"); 

              } catch (Exception e) { 
              } 

              return resp; 
          } 


--------PROBLEM---------

i coudln't even send the msg, igot always an exception. This is the output


   <fsdmsg schema='file:cfg/hsm-base'>
     command: 'EC'
     key-type: '000'
     key-scheme: 'U'
     component: '01020304050607080901020304050607'
   </fsdmsg>
org.jpos.iso.ISOException: java.lang.NullPointerException (java.lang.NullPointerException)
        at org.jpos.iso.FSDISOMsg.pack(FSDISOMsg.java:44)
        at org.jpos.iso.BaseChannel.send(BaseChannel.java:588)
        at org.jpos.iso.channel.FSDChannel.send(FSDChannel.java:61)
        at com.usef.TestServer.FinancialTransactionQueryRemoteHost.prepare(FinancialTransactionQueryRemot
eHost.java:72)
        at org.jpos.transaction.TransactionManager.prepare(TransactionManager.java:484)
        at org.jpos.transaction.TransactionManager.prepare(TransactionManager.java:540)
        at org.jpos.transaction.TransactionManager.run(TransactionManager.java:262)
        at java.lang.Thread.run(Thread.java:745)
Nested:java.lang.NullPointerException
        at java.lang.String.getBytes(String.java:940)
        at org.jpos.util.FSDMsg.packToBytes(FSDMsg.java:243)
        at org.jpos.iso.FSDISOMsg.pack(FSDISOMsg.java:42)
        at org.jpos.iso.BaseChannel.send(BaseChannel.java:588)
        at org.jpos.iso.channel.FSDChannel.send(FSDChannel.java:61)
        at com.usef.TestServer.FinancialTransactionQueryRemoteHost.prepare(FinancialTransactionQueryRemot
eHost.java:72)


please help out

thanks in advance.

chhil

unread,
Jul 27, 2016, 10:44:32 AM7/27/16
to jpos-...@googlegroups.com
Could not reproduce your error. Had a netcat server listening on port 9998 , it received the message.
My temp folder had your 2 files
C:\Temp\thales\cfg\hsm-base.xml
C:\Temp\thales\cfg\hsm-EC.xml

I am at jpos 1.9.something.
import java.io.IOException;

import org.jdom.JDOMException;
import org.jpos.iso.FSDISOMsg;
import org.jpos.iso.ISOException;
import org.jpos.iso.channel.FSDChannel;
import org.jpos.iso.packager.DummyPackager;
import org.jpos.util.FSDMsg;
import org.jpos.util.Logger;
import org.jpos.util.SimpleLogListener;

public class ThalesAdaptor {

    public static void main(String[] args)

    {
        String command = "EC";
        FSDMsg req = new FSDMsg("file:///C:/Temp/thales/cfg/hsm-");

        req.set("command", command);
        req.set("key-type", "000");
        req.set("key-scheme", "U");
        req.set("component", "01020304050607080901020304050607");

        try {
            System.out.println(req.pack());
            FSDISOMsg msg = new FSDISOMsg(req);

            FSDChannel channel = new FSDChannel();
            Logger logger = new Logger();
            logger.addListener(new SimpleLogListener(System.out));

            channel.setHost("127.0.0.1");
            channel.setPort(9998);
            channel.setPackager(new DummyPackager());
            channel.connect();
            channel.send(msg);

        }
        catch (JDOMException | IOException | ISOException ex) {
            // TODO Auto-generated catch block
            ex.printStackTrace();
        }

    }

}

-chhil

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/4cad1e57-5188-49ce-a1ba-47454b634fe4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sirealki...@gmail.com

unread,
Jul 27, 2016, 11:26:50 AM7/27/16
to jPOS Users
Thanl you so much Chhil for your time.


>Could not reproduce your error.
thats weird, i tried with your code i get the same exception

i tried changing the version of jpos (i was using 2.0.6) to  1.9.2 but in vain.
by the way i'm using maven to build my jpos server.

i used Q2 because i'll need with Qmux and other stuff.

this is my code.


public class Program  {

static void start() {
Q2 q2 = new Q2();
q2.start();
}

public static void main(String[] args) {
start();
ISOUtil.sleep(2000);
Luncher();
}
private static void Luncher(){
FSDChannel channel = new FSDChannel(); 
   Logger logger=new Logger(); 
   logger.addListener(new SimpleLogListener(System.out)); 
   channel.setHost("127.0.0.1"); 
   channel.setPort(9998); 
     channel.setPackager(new DummyPackager()); 
     try {
channel.connect();
     } catch (IOException e) {
e.printStackTrace();
     }
     
    ThalesAdaptor thales=new ThalesAdaptor(); 
    FSDMsg msg=thales.encryptClearComponent(); 
   FSDISOMsg isomsg = new FSDISOMsg(msg); 
   msg.dump(System.out, "   "); 
   try {
System.out.println("THE PACKED MSG: "+ msg.pack());
} catch (Exception e) {
e.printStackTrace();

chhil

unread,
Jul 27, 2016, 12:16:33 PM7/27/16
to jpos-...@googlegroups.com
Q2 is the right approach. I just doing a simple test case without the baggage.

I could reproduce your error with 2.0.x build of jpos. (My custom code is a mix and match and it was not getting the error).

If you attach the source code for jpos it becomes easier.

It was throwing an error because the charset was null.

It gets set when you configure your channel deploy file with the schema property pointing to the file location.

I worked through it using the configuration object below. It should work for you now.
package jashdajsdg;

import java.io.IOException;

import org.jpos.core.SimpleConfiguration;
import org.jpos.iso.FSDISOMsg;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOUtil;
import org.jpos.iso.channel.FSDChannel;
import org.jpos.iso.packager.DummyPackager;
import org.jpos.util.FSDMsg;
import org.jpos.util.Logger;
import org.jpos.util.SimpleLogListener;

public class ThalesAdaptor {

    public static void main(String[] args)

    {
        String command = "EC";
        FSDMsg req = new FSDMsg("file:///C:/Temp/thales/cfg/hsm-");

        req.set("command", command);
        req.set("key-type", "000");
        req.set("key-scheme", "U");
        req.set("component", "01020304050607080901020304050607");

        req.setCharset(ISOUtil.CHARSET);
        try {
            // System.out.println(req.pack());
            FSDISOMsg msg = new FSDISOMsg(req);

            FSDChannel channel = new FSDChannel();
            SimpleConfiguration cfg = new SimpleConfiguration();
            cfg.put("schema", "file:///C:/Temp/thales/cfg/hsm-");
            channel.setConfiguration(cfg);

            Logger logger = new Logger();
            logger.addListener(new SimpleLogListener(System.out));

            channel.setHost("127.0.0.1");
            channel.setPort(9998);
            channel.setPackager(new DummyPackager());
            channel.connect();

            channel.send(msg);

        }
        catch (IOException | ISOException ex) {
            // TODO Auto-generated catch block
            ex.printStackTrace();
        }

    }

}

Hairi

unread,
Jul 28, 2016, 3:13:35 AM7/28/16
to jpos-...@googlegroups.com

5 Years ago I wrote a thales adaptor for thales racal based on jpos FSDMsg

 

Its @ http://m-sinergi.com/wp/hthales-docs/   Is that applicable in your use case ?

sirealki...@gmail.com

unread,
Jul 28, 2016, 4:34:54 AM7/28/16
to jPOS Users
Thank you so much Chhil for your help that works for me just good. thx again.

Hairi thank you for your response. i saw your HThalesAdaptor amaizing work, helped me a lot.

Thank you guys so much.

chhil

unread,
Jul 28, 2016, 6:10:39 AM7/28/16
to jpos-...@googlegroups.com
You are welcome.

You shouldn't go the route of instantiating Q2, do it the standard jpos way of deploying using deploy files. T
he jpos jar is an executable jar and set to run Q2.java, which will look for standard deploy folder to instantiate and run components.
Half your code of creating channel setting ip port will go away. Similarly for muxes and other jpos components.
A word of caution, mux needs a key to match request response pairs, you will be out of luck there if the HSM 
does not use a header. If there is a header you can configure the mux to match on that as the HSM echoes back the header sent
 in the request and you will have a rolling value in there for every request.

-chhil


--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages