working with HSM

1,074 views
Skip to first unread message

pmug...@gmail.com

unread,
Jul 27, 2009, 2:31:14 AM7/27/09
to jPOS Users
Hi guys,

I am working with HSM simulator 0.8.1 for Thales. I have followed Andy
Orock tutorials on working with HSM and created four xml files, 1.
hsm-base.xml, 2.hsm-NC.xml, 3. hsm-resp-base.xml, 4. hsm-resp-ND.xml
and then written the following code to send and receive response from
HSM

FSDChannel channel = new FSDChannel();
channel.setHost("127.0.0.1");
channel.setPort(9998);
channel.setPackager(new DummyPackager());
channel.connect();
ThalesAdaptor thales=new ThalesAdaptor();
FSDMsg msg=thales.diagnostics();

FSDISOMsg isomsg = new FSDISOMsg(msg);
isomsg.setHeader(new byte[]{1,2,3,4});
msg.dump(System.out, " ");

try {
channel.send(isomsg);
ISOMsg m=channel.receive();
} catch (IOException ex) {
ex.printStackTrace();

} catch (ISOException ex) {
ex.printStackTrace();
}
}


and ThalesAdaptor contain the following code:

public FSDMsg diagnostics () {
return (createRequest ("NC"));
}

private FSDMsg createRequest (String command) {
FSDMsg req = new FSDMsg("file:src\\iris\\hsm-");
if (command != null)

req.set ("command", command);
return req;
}


The problem is my request is being sent to HSM and I can see that even
the HSM log as

Request: NC
Parsing header and code of message NC...
Searching for implementor of NC...
Found implementor
ThalesSim.Core.HostCommands.Runtime.HSMDiagnostics_NC,
instantiating...
Calling AcceptMessage()...
Calling ConstructResponse()...
Calling ConstructResponseAfterOperationComplete()...
Attaching header/response code to response...
Sending: ND007B44AC1DDEE2A94B0007-E000
Calling Terminate()...
Implementor to Nothing
Client disconnected.


But in my application log am getting an exception as :

<fsdmsg schema='file:src\iris\hsm-base'>
command: 'NC'
</fsdmsg>
org.jpos.iso.ISOException: java.lang.NullPointerException
(java.lang.NullPointerException)
at org.jpos.iso.FSDISOMsg.unpack(FSDISOMsg.java:54)
at org.jpos.iso.BaseChannel.unpack(BaseChannel.java:849)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:620)
at iris.SendToHSM.main(SendToHSM.java:29)
Nested:java.lang.NullPointerException
at java.lang.StringBuffer.<init>(Unknown Source)
at org.jpos.util.FSDMsg.getSchema(FSDMsg.java:445)
at org.jpos.util.FSDMsg.unpack(FSDMsg.java:130)
at org.jpos.util.FSDMsg.unpack(FSDMsg.java:147)
at org.jpos.iso.FSDISOMsg.unpack(FSDISOMsg.java:51)
at org.jpos.iso.BaseChannel.unpack(BaseChannel.java:849)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:620)
at iris.SendToHSM.main(SendToHSM.java:29)
Nested:java.lang.NullPointerException
at java.lang.StringBuffer.<init>(Unknown Source)
at org.jpos.util.FSDMsg.getSchema(FSDMsg.java:445)
at org.jpos.util.FSDMsg.unpack(FSDMsg.java:130)
at org.jpos.util.FSDMsg.unpack(FSDMsg.java:147)
at org.jpos.iso.FSDISOMsg.unpack(FSDISOMsg.java:51)
at org.jpos.iso.BaseChannel.unpack(BaseChannel.java:849)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:620)
at iris.SendToHSM.main(SendToHSM.java:29)

Please guys where could the problem be?

Mark Salter

unread,
Jul 27, 2009, 3:25:45 AM7/27/09
to jpos-...@googlegroups.com
pmug...@gmail.com wrote:
> Hi guys,
>
> I am working with HSM simulator 0.8.1 for Thales. I have followed Andy
> Orock tutorials on working with HSM and created four xml files, 1.
> hsm-base.xml, 2.hsm-NC.xml, 3. hsm-resp-base.xml, 4. hsm-resp-ND.xml

Where does your code set the schema for responses as "hsm-resp-" ?

It looks like 'command' is a key field - forming part of the name of
lower level schema?

You need to make the leap over to hsm-resp- for the response handling?

Perhaps receiving an FSDMsg (with a base schema of
"file:src\\iris\\hsm-resp-") instead of an ISOMsg with a DummyPackager
(from Channel) will help?

--
Mark

pmug...@gmail.com

unread,
Jul 27, 2009, 3:53:37 AM7/27/09
to jPOS Users
Hi Mark,

I have added the following code:
FSDMsg received = new FSDMsg("file:src\\iris\\hsm-
resp-");
FSDISOMsg isomsgs = new FSDISOMsg(received);
channel.send(isomsg);
isomsgs=(FSDISOMsg) channel.receive();

But Am still getting the same exception. When I remove the last line
with channel.receive() method I don't get any response.
Could be casting ISOMsg to FSDISOMsg brings the error?

On Jul 27, 10:25 am, Mark Salter <marksal...@talktalk.net> wrote:

Mark Salter

unread,
Jul 27, 2009, 4:08:23 AM7/27/09
to jpos-...@googlegroups.com
pmug...@gmail.com wrote:
>
> I have added the following code:
> FSDMsg received = new FSDMsg("file:src\\iris\\hsm-
> resp-");
> FSDISOMsg isomsgs = new FSDISOMsg(received);
> channel.send(isomsg);
> isomsgs=(FSDISOMsg) channel.receive();
>
> But Am still getting the same exception.

Can you change the names of the response schema to remove the -resp part?

That way, the requests and responses are part of the same schema, split
by the command value?

Are hsm-base.xml and hsm-resp-base.xml essentially the same?

> When I remove the last line
> with channel.receive() method I don't get any response.

Yes, because then you are not receiving anything back.

> Could be casting ISOMsg to FSDISOMsg brings the error?

I doubt it?

Andy will be up in a few hours, I'm sure he will know how best to do
this - I have not done it you see.

--
Mark

Peter Olingo

unread,
Jul 27, 2009, 6:46:04 AM7/27/09
to jpos-...@googlegroups.com
I have tried the what u have told me but am still getting the same error.

Mark Salter

unread,
Jul 27, 2009, 7:01:53 AM7/27/09
to jpos-...@googlegroups.com
Peter Olingo wrote:
> I have tried the what u have told me but am still getting the same error.
>
>
So you now have 3 xml files:-

1. hsm-base.xml, 2.hsm-NC.xml, 3. hsm-ND.xml

?

I guess the problem is making sure the unpack knows which schema to use...


... we need an expert on Channel/(ISO)FSDMsg receiving...

... I don't have time to work it out 8(.


--
Mark

Alejandro Revilla

unread,
Jul 27, 2009, 8:05:27 AM7/27/09
to jpos-...@googlegroups.com
I don't have time either, but the problem has to be related to FSDMsg not finding the appropriate schema.

Andy Orrock

unread,
Jul 27, 2009, 9:00:56 AM7/27/09
to jpos-...@googlegroups.com
I think Mark's comments are on the right track here where he says:  "You need to make the leap over to hsm-resp- for the response handling?"

I think that's the issue here.  Looking back at the post I referenced, I see I didn't mention that part of the code.  It looks like this:

    public FSDMsg command (FSDMsg request) {
        LogEvent evt  = trace ? getLog().createTrace () : null;
        FSDMsg resp = null;
        try {
            if (trace)
                evt.addMessage (request);
            String s = command (request.pack(), evt);
            if (s != null) {
                resp = new FSDMsg ("file:cfg/hsm-resp-");
                resp.unpack (s.getBytes());
                if (trace)
                    evt.addMessage (resp);
            } else {
                if (trace)
                    evt.addMessage ("TIMEOUT");
            }
        } catch (Exception e) {
            if (trace)
                evt.addMessage (e);
            else
                getLog().error (e);
        } finally {
            if (trace)
                Logger.log (evt);
        }
        return resp;
    }

Andy Orrock

Andy Orrock

unread,
Jul 27, 2009, 9:19:56 AM7/27/09
to jpos-...@googlegroups.com
I just updated the blog post to include this additional piece of information.

See:

http://www.andyorrock.com/2007/04/implementing_a_.html

Andy Orrock

pmug...@gmail.com

unread,
Jul 27, 2009, 9:34:45 AM7/27/09
to jPOS Users
Hi Andy,

Thanks for the reply. I havve implemented the code in my scenerio but
my error of null exception persists when I add the line channel.receive
() or when I implement the code I don't need channel.receive();
> > finding the appropriate schema.- Hide quoted text -
>
> - Show quoted text -

Andy Orrock

unread,
Jul 27, 2009, 10:40:44 AM7/27/09
to jpos-...@googlegroups.com
Are you accomodating for the proper channel manager work on the response?

    private int getMessageLength(DataInputStream serverIn) throws IOException {
        byte[] b = new byte[2];
        serverIn.readFully(b,0,2);
        return (int) (
            ((((int)b[0])&0xFF) << 8) |
            (((int)b[1])&0xFF));
    }

Two-byte header, lengths in Hex....length of the length not included.  See:

http://screencast.com/t/1jcknBU8

Andy

------------------------------------------------

pmug...@gmail.com

unread,
Jul 28, 2009, 2:14:53 AM7/28/09
to jPOS Users

Hi Andy. Thank for the message. I am debugging when receiving the
message I am getting the length as -1. Where could the error be....

This is my snippet of the code:

SendToHSM.java:

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

channel.setHost("127.0.0.1");
channel.setPort(9998);
ISOPackager pack=new DummyPackager();
String accno;

channel.setPackager(pack);
channel.connect();
pack.setLogger(logger, "");
ThalesAdaptor thales=new ThalesAdaptor();
FSDMsg msg=thales.diagnostics();

FSDISOMsg isomsg = new FSDISOMsg(msg);
isomsg.setHeader(new byte[]{1,2,3,4});


try {
channel.send(isomsg);
channel.receive();


} catch (IOException ex) {
ex.printStackTrace();
//Logger.getLogger(Main.class.getName()).log
(Level.SEVERE, null,
//ex);
} catch (ISOException ex) {
ex.printStackTrace();
//Logger.getLogger(Main.class.getName()).log
(Level.SEVERE, null,
//ex);
}

ThalesAdaptor.java:

public FSDMsg diagnostics () {
return (createRequest ("NC"));
}

private FSDMsg createRequest (String command) {
FSDMsg req = new FSDMsg("file:src\\iris\\hsm-");
if (command != null)

req.set ("command", command);
return req;
}

public FSDMsg command (FSDMsg request) {
LogEvent evt =new LogEvent();
FSDMsg resp = null;;
try {
if (trace)
evt.addMessage (request);
;

resp = new FSDMsg ("file:cfg/hsm-resp-");
resp.unpack (request.packToBytes());
if (trace)
evt.addMessage (resp);

} catch (Exception e) {
e.printStackTrace();
} finally {

}
return resp;
}

I am using eclipse to build and compile the project.



On Jul 27, 5:40 pm, Andy Orrock <aaorr...@gmail.com> wrote:
> Are you accomodating for the proper channel manager work on the response?
>
>     private int getMessageLength(DataInputStream serverIn) throws
> IOException {
>         byte[] b = new byte[2];
>         serverIn.readFully(b,0,2);
>         return (int) (
>             ((((int)b[0])&0xFF) << 8) |
>             (((int)b[1])&0xFF));
>     }
>
> Two-byte header, lengths in Hex....length of the length not included.  See:
>
> http://screencast.com/t/1jcknBU8
>
> Andy
>
> ------------------------------------------------
>

pmug...@gmail.com

unread,
Jul 28, 2009, 2:50:46 AM7/28/09
to jPOS Users
When Dump the response from HSM Simulator I get as:

<fsdmsg schema='nullbase'>
</fsdmsg>

Andy Orrock

unread,
Jul 28, 2009, 8:28:22 AM7/28/09
to jpos-...@googlegroups.com
"Where could the error be...."

A full trace would really help.

Maybe I'm missing it, but:  where are you accommodating for the 2-byte Hexadecimal length that precedes the message?

    private byte[] receive (DataInputStream serverIn) throws IOException {
        int len = getMessageLength(serverIn);
        byte[] response = new byte[len];
        serverIn.readFully (response, 0, response.length);
        return response;
    }

(where getMessageLength is what I showed you yesterday...did you do anything with that?).

Andy

pmug...@gmail.com

unread,
Jul 28, 2009, 8:41:38 AM7/28/09
to jPOS Users
I have Implemented the method receive and getMessageLength in my
NACCChannel. Could this be an error?
And in my HSM simulator am getting an exception at first. Could that
be an error?
i.e
Compiling HSMDiagnostics_NC.vb...
No LMK storage file specified, creating new keys
Searching for host command implementors...
Starting up the TCP listening thread...
Startup complete
Client from ERROR: Couldn't get IP address thru reflection is
connected
Client: ERROR: Couldn't get IP address thru reflection
Request: NC
Parsing header and code of message NC...
Searching for implementor of NC...
Found implementor
ThalesSim.Core.HostCommands.Runtime.HSMDiagnostics_NC,
instantiating...
Calling AcceptMessage()...
Calling ConstructResponse()...
Calling ConstructResponseAfterOperationComplete()...
Attaching header/response code to response...
Sending: ND007B44AC1DDEE2A94B0007-E000
Exception while processing message
System.IO.IOException: Unable to write data to the transport
connection: An existing connection was forcibly closed by the remote
host. ---> System.Net.Sockets.SocketException: An existing connection
was forcibly closed by the remote host
at System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset,
Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object
state)
at System.Net.Sockets.NetworkStream.BeginWrite(Byte[] buffer, Int32
offset, Int32 size, AsyncCallback callback, Object state)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.BeginWrite(Byte[] buffer, Int32
offset, Int32 size, AsyncCallback callback, Object state)
at ThalesSim.Core.TCP.WorkerClient.send(String sendData) in C:
\Documents and Settings\Peter\Desktop\thalessim.src.0.8.0\ThalesCore
\TCP\WorkerClient.vb:line 220
at ThalesSim.Core.ThalesMain.WCMessageArrived(WorkerClient sender,
Byte[]& b, Int32 len) in C:\Documents and Settings\Peter\Desktop
\thalessim.src.0.8.0\ThalesCore\ThalesMain.vb:line 405
Disconnecting client.
Calling Terminate()...
Implementor to Nothing
Client disconnected.
Client from ERROR: Couldn't get IP address thru reflection is
connected
Client: ERROR: Couldn't get IP address thru reflection
Request: NC
Parsing header and code of message NC...
Searching for implementor of NC...
Found implementor
ThalesSim.Core.HostCommands.Runtime.HSMDiagnostics_NC,
instantiating...
Calling AcceptMessage()...
Calling ConstructResponse()...
Calling ConstructResponseAfterOperationComplete()...
Attaching header/response code to response...
Sending: ND007B44AC1DDEE2A94B0007-E000
Calling Terminate()...
Implementor to Nothing
Client disconnected.

About the trace I have set the logger but am not getting anything in
my trace. I dumped the what I send and what I received and this is my
trace of the dump:
<fsdmsg schema='file:src\iris\hsm-base'>
command: 'NC'
</fsdmsg>
<fsdmsg schema='nullbase'>
</fsdmsg>

On Jul 28, 3:28 pm, Andy Orrock <aaorr...@gmail.com> wrote:
> "Where could the error be...."
>
> A full trace would really help.
>
> Maybe I'm missing it, but:  where are you accommodating for the 2-byte
> Hexadecimal length that precedes the message?
>
>     private byte[] receive (DataInputStream serverIn) throws IOException {
>         int len = getMessageLength(serverIn);
>         byte[] response = new byte[len];
>         serverIn.readFully (response, 0, response.length);
>         return response;
>     }
>
> (where getMessageLength is what I showed you yesterday...did you do anything
> with that?).
>
> Andy
>

Andy Orrock

unread,
Jul 28, 2009, 9:09:37 AM7/28/09
to jpos-...@googlegroups.com
Okay, good.  But the fact that your program thinks that the length is -1 says something is off.

You appear to be setting a four-byte header, which is a good practice for the Thales.  Are you accommodating for that header on all 4 legs?  (in/out on your program, in/out on your simulator).  And on the response, you handle length _then_ header, right?

You've set up hsm-base, hsm-resp-base, hsm-NC and hsm-ND as depicted in my blog post?

Andy

pmug...@gmail.com

unread,
Jul 28, 2009, 9:23:30 AM7/28/09
to jPOS Users
Can I set header in Xml configuration files so that it is accomodated
on both sides?

On Jul 28, 4:09 pm, Andy Orrock <aaorr...@gmail.com> wrote:
> Okay, good.  But the fact that your program thinks that the length is -1
> says something is off.
>
> You appear to be setting a four-byte header, which is a good practice for
> the Thales.  Are you accommodating for that header on all 4 legs?  (in/out
> on your program, in/out on your simulator).  And on the response, you handle
> length _then_ header, right?
>
> You've set up hsm-base, hsm-resp-base, hsm-NC and hsm-ND as depicted in my
> blog post?
>
> Andy
>
> ...
>
> read more »

Andy Orrock

unread,
Jul 28, 2009, 9:41:33 AM7/28/09
to jpos-...@googlegroups.com
Sure.  We handle headers in code, but you could instead accommodate in XML by having hsm-base.xml like this:

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

...and hsm-resp-base.xml like this:

<?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>

Andy

pmug...@gmail.com

unread,
Jul 28, 2009, 10:06:17 AM7/28/09
to jPOS Users
I have changed to my xml files as above and add a line req.set
("header", "1234"); in ThalesAdaptor but
I am still getting -1 as message length when am receiving the
message from simulator.

On Jul 28, 4:41 pm, Andy Orrock <aaorr...@gmail.com> wrote:
> Sure.  We handle headers in code, but you could instead accommodate in XML
> by having hsm-base.xml like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <schema>
>  <field id="header"  type="N" length="4" />
>  <field id="command" type="A" length="2" key="true" />
> </schema>
>
> ...and hsm-resp-base.xml like this:
>
> <?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>
>
> Andy
>
> ...
>
> read more »

pmug...@gmail.com

unread,
Jul 28, 2009, 10:09:21 AM7/28/09
to jPOS Users
Looking at my HSM simulator am getting the reply.

On Jul 28, 4:41 pm, Andy Orrock <aaorr...@gmail.com> wrote:
> Sure.  We handle headers in code, but you could instead accommodate in XML
> by having hsm-base.xml like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <schema>
>  <field id="header"  type="N" length="4" />
>  <field id="command" type="A" length="2" key="true" />
> </schema>
>
> ...and hsm-resp-base.xml like this:
>
> <?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>
>
> Andy
>
> ...
>
> read more »

Mark Salter

unread,
Jul 28, 2009, 12:09:42 PM7/28/09
to jpos-...@googlegroups.com
pmug...@gmail.com wrote:
> Looking at my HSM simulator am getting the reply.

May I suggest that it is time to try and describe your current environment?

This should include changes you have made to the jPos source. Remember
that we cannot see those and they may well be breaking the flow. Also
include the components (Channels, MUX etc).

If you can describe each part of your solution and the jPos components
(Schema/Packager, Channel (with headers) etc), we may be able to 'feel'
what might be busted.

If you have not changed too much, perhaps a diff of your changes here
might help us see what you are doing wrong?

We should remember that jPos as it stands works for others, so something
is 'now' incorrect in your setup.

Can you also indicate if you have control of the 'hsm simulator'? If
you do are you matching the channels, the packagers/schema and the
header handling at both ends?

--
Mark

pmug...@gmail.com

unread,
Jul 29, 2009, 3:55:10 AM7/29/09
to jPOS Users
Hi guys...
Things were working somehow by yesterday but today the am getting my
first error....I have even reimplemented the code as told by Andy but
all in vain.
I have even reinvented my code to look like this:
The Adaptor code is :

private FSDMsg createRequest (String command) {
FSDMsg req = new FSDMsg ("file:src/iris/hsm-");
if (command != null)
req.set ("command", command);
return req;
}

public FSDMsg diagnostics () throws MalformedURLException,
JDOMException, IOException, ISOException {
return command (createRequest ("NC"));
}

public FSDMsg command (FSDMsg request) throws
MalformedURLException, JDOMException, IOException, ISOException {
FSDMsg resp = null;
String s = request.pack();
if(s!=null){
resp = new FSDMsg ("file:src/iris/hsm-resp-");
resp.unpack(s.getBytes());
}
else
resp.dump(System.out, "");

return resp;
}


and my main class is :
FSDChannel channel=new FSDChannel();
ISOPackager pack=new DummyPackager();
channel.setHost("127.0.0.1", 9998);
channel.setPackager(pack);
HSMAdaptor adaptor=new HSMAdaptor();
FSDMsg msg=adaptor.diagnostics();
FSDISOMsg isomsg=new FSDISOMsg(msg);
isomsg.setHeader(new byte[]{1,2,3,4});
channel.connect();
channel.send(isomsg);
channel.receive();


and I am including infact five not four files i.e hsm-base,hsm-resp-
base, hsm-NC, hsm-resp-NC, hsm-resp-ND files. Am just working on a
simple class to check if I can send and receive from my thales HSM
simulator.

In my FSDChannel I added the following two methods:

protected int getMessageLength() throws IOException, ISOException {
int len = super.getMessageLength();
LogEvent evt = new LogEvent (this, "fsd-channel-debug");
evt.addMessage ("received message length: " + len);
Logger.log (evt);
return len;
}
protected int getMessageLength(DataInputStream serverIn) throws
IOException {
byte[] b = new byte[2];
serverIn.readFully(b,0,2);
return (int) (
((((int)b[0])&0xFF) << 8) |
(((int)b[1])&0xFF));
}

When I send I get the null reponse..

Do I need to make adjustment also in my basechannel?

I am not give up..

On Jul 28, 7:09 pm, Mark Salter <marksal...@talktalk.net> wrote:

Mark Salter

unread,
Jul 29, 2009, 4:35:28 AM7/29/09
to jpos-...@googlegroups.com
pmug...@gmail.com wrote:
> Hi guys...
> Things were working somehow by yesterday but today the am getting my
> first error..
You must get some control around your source changes, at the moment you
seem to be your own worst enemy.

What error are you getting - we need to know.

Looking through the code...

>...I have even reimplemented the code as told by Andy but
> all in vain.
> I have even reinvented my code to look like this:
> The Adaptor code is :
>
> private FSDMsg createRequest (String command) {
> FSDMsg req = new FSDMsg ("file:src/iris/hsm-");
> if (command != null)
> req.set ("command", command);
> return req;
> }
>
> public FSDMsg diagnostics () throws MalformedURLException,
> JDOMException, IOException, ISOException {
> return command (createRequest ("NC"));
> }
>
> public FSDMsg command (FSDMsg request) throws
> MalformedURLException, JDOMException, IOException, ISOException {
> FSDMsg resp = null;
> String s = request.pack();
> if(s!=null){

So at this point you have a byte[] containing your request (which is not
null), but you do nothing with it in the way of sending it across a network?

> resp = new FSDMsg ("file:src/iris/hsm-resp-");
> resp.unpack(s.getBytes());

.. but then you unpack your request byte[] as your response!

> }
> else
> resp.dump(System.out, "");
>
> return resp;
> }
>
>
> and my main class is :
> FSDChannel channel=new FSDChannel();
> ISOPackager pack=new DummyPackager();
> channel.setHost("127.0.0.1", 9998);
> channel.setPackager(pack);
> HSMAdaptor adaptor=new HSMAdaptor();
> FSDMsg msg=adaptor.diagnostics();

The above instruction probably fails with an unpack error because you
are attempting to unpack your request as a response!


> FSDISOMsg isomsg=new FSDISOMsg(msg);
> isomsg.setHeader(new byte[]{1,2,3,4});
> channel.connect();
> channel.send(isomsg);

Now you send the 'request/response' from *outside* of the HSMAdaptor...
> channel.receive();
Then you try and receive something, but don't do anything with it!?

Please note that adaptor.diagnostics() should probably send a diagnostic
request to the HSM and return the response?


>
>
> and I am including infact five not four files i.e hsm-base,hsm-resp-
> base, hsm-NC, hsm-resp-NC, hsm-resp-ND files. Am just working on a
> simple class to check if I can send and receive from my thales HSM
> simulator.
>
> In my FSDChannel I added the following two methods:
>
> protected int getMessageLength() throws IOException, ISOException {
> int len = super.getMessageLength();
> LogEvent evt = new LogEvent (this, "fsd-channel-debug");
> evt.addMessage ("received message length: " + len);
> Logger.log (evt);
> return len;
> }
> protected int getMessageLength(DataInputStream serverIn) throws
> IOException {
> byte[] b = new byte[2];
> serverIn.readFully(b,0,2);
> return (int) (
> ((((int)b[0])&0xFF) << 8) |
> (((int)b[1])&0xFF));
> }
>
> When I send I get the null reponse..

When you send what?

Where are you getting a 'null' 'response'? Remember your
channel.receive line is throwing anything it gets away, I suspect you
are not getting that far.

>
> Do I need to make adjustment also in my basechannel?

You need to understand what it is you are trying to do and how you might
do it.

You seemed totally confused and your code is poorly written - perhaps
just because you are confused and don't understand things. Is java a
language you use often?

>
> I am not give up..

We can tell, but currently you have a mess.

It is a *lot* easier than you are making this - honestly.

Your HSM adaptor - if anything like Andy's will have a socket that it
would use to send a request and receive the response through.

I think it might be worth starting over, untangling what you have would
be a nightmare - especially remotely and via email

Read carefully through Andy's blog, search this mailing list, understand
what you need to do and then set out to do it.

I don't think we can help you in this aspect unless someone does your
work for you...

... perhaps that is an option you need now to consider?

--
Mark

Andy Orrock

unread,
Jul 29, 2009, 7:57:04 AM7/29/09
to jpos-...@googlegroups.com
Why on earth would you require a hsm-resp-NC model?  You thinking you need that piece is a telltale sign of what Mark has pointed out here in your code: you've bollixed-up requests and responses, pulling your original requests and trying to process them as your response. 

Andy Orrock

----------------------------------

pmug...@gmail.com

unread,
Jul 29, 2009, 9:41:40 AM7/29/09
to jPOS Users
I have followed my debug...and even dumped the what am received from
hsm as:
0000 01 02 03 04 4E 44 30 30 37 42 34 34 41 43 31
44 ....ND007B44AC1D
0010 44 45 45 32 41 39 34 42 30 30 30 37 2D 45 30 30 DEE2A94B0007-
E00
0020 30 0
and I have realised that the error is at unpack (is, getSchema
(baseSchema)); in FSDISOMsg class i.e am getting the base schema as
null;
I am sure if I can get some value in baseSchema this thing is going to
work. How can I dot that?

On Jul 29, 2:57 pm, Andy Orrock <aaorr...@gmail.com> wrote:
> Why on earth would you require a hsm-resp-NC model?  You thinking you need
> that piece is a telltale sign of what Mark has pointed out here in your
> code: you've bollixed-up requests and responses, pulling your original
> requests and trying to process them as your response.
>
> Andy Orrock
>
> ----------------------------------
>
> On Wed, Jul 29, 2009 at 3:35 AM, Mark Salter <marksal...@talktalk.net>wrote:

Andy Orrock

unread,
Jul 29, 2009, 10:01:21 AM7/29/09
to jpos-...@googlegroups.com
"and I have realised that the error is at unpack (is, getSchema
(baseSchema)); in FSDISOMsg class i.e am getting the base schema as
null;"

You told us previously that you're interpreting the length as "-1".  Is that still happening?  If so, that's a problem.

Please show us your schemas. The four relevant ones.  Also -  I remain concerned as to why you felt compelled to build an hsm-resp-NC model.

Andy

pmug...@gmail.com

unread,
Jul 29, 2009, 10:10:47 AM7/29/09
to jPOS Users
I have four files.....
hsm-base.xml

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

hsm-NC.xml

<?xml version="1.0" encoding="UTF-8"?>
<schema id='NC'>
</schema>

hsm-resp.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-resp-ND.xml

<?xml version="1.0" encoding="UTF-8"?>
<schema id='ND'>
<field id="lmk-check-value" type="A" length="16" />
<field id="firmware-number" type="A" length="9" />
</schema>

I implemented the method protected int getMessageLength
(DataInputStream serverIn) in baseChannel.java returning -1 as it is
return value;

My adaptor is as:

public FSDMsg diagnostics () {
return (createRequest ("NC"));
}

private FSDMsg createRequest (String command) {
FSDMsg req = new FSDMsg("file:src\\iris\\hsm-");
if (command != null){
req.set("header", "1234");
req.set ("command", command);
}
return req;
}

public FSDMsg command (FSDMsg request) {

FSDMsg resp = null;
try {


resp = new FSDMsg ("file:src\\iris\\hsm-resp-");

} catch (Exception e) {
}

return resp;
}

and my HSM implementation snippet code is:

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

channel.setHost("127.0.0.1");
channel.setPort(9998);
ISOPackager pack=new DummyPackager();
String accno;

channel.setPackager(pack);
channel.connect();
pack.setLogger(logger, "");
ThalesAdaptor thales=new ThalesAdaptor();
FSDMsg msg=thales.diagnostics();

FSDISOMsg isomsg = new FSDISOMsg(msg);

msg.dump(System.out, " ");

Mark Salter

unread,
Jul 30, 2009, 2:05:43 AM7/30/09
to jpos-...@googlegroups.com
pmug...@gmail.com wrote:
> I have four files.....
> hsm-base.xml
[snip]

> ThalesAdaptor thales=new ThalesAdaptor();
> FSDMsg msg=thales.diagnostics();
>
> FSDISOMsg isomsg = new FSDISOMsg(msg);
>
> msg.dump(System.out, " ");
>
> try {
> channel.send(isomsg);
Now you are sending an NC command - your HSM sees it?

What happens?

>
> channel.receive();

But you are still not trying to do anything with any response that comes
back. The processing of the inbound message will fail because you are
still have no way of letting the Channel know that the bytes arriving
back need to be unpacked using the response schema.

Where did you get the base source for your 'ThalesAdaptor' from; or can
you show us the entire item?

--
Mark

pmug...@gmail.com

unread,
Jul 30, 2009, 2:32:09 AM7/30/09
to jPOS Users
Mark ,Andy Thanks very much. I was able to set up communication with
HSM. I implemented my own receive method on the base channel to
process the incoming bytes and it was able to work. Thanks very
much.....It is very simple......You guys are great.

On Jul 30, 9:05 am, Mark Salter <marksal...@talktalk.net> wrote:

Andy Orrock

unread,
Jul 30, 2009, 7:43:27 AM7/30/09
to jpos-...@googlegroups.com
That's great news, Peter!  Thanks very much for the update. 

Andy
Reply all
Reply to author
Forward
0 new messages