Tuesday, November 16, 2010

A funk

Hello again. Haven’t updated this rag of mine in a while. I suppose I got too lazy to update it. I’ve been forgetting to do some important things, so if I was supposed to call or something, don’t get mad, ok? I’ve major things on my mind, & the decided lack of rest isn’t getting me anywhere, especially since I’ve amped up on sleep.

I was going to rant about just how much my life sucks, but then I realized it might be worse (remembering that my neighbours had a fire — the fact that 60000 young people in Lagos alone sat for an employment test when an anonymous source says the agency holding the test will only hire 2000 persons in each state — a claim that my boss says is improbable since the agency only has about 5000 staff nationwide now — according to him, anyway — also helped). Unfortunately, it doesn’t remove the feeling. I went out today with Mr Baby this evening, saw something, and the old feelings rushed to the surface. The feeling of not being where I think I should be was really strong. Pushed it down like I do all other such feelings, though, and went on into the store I was visiting.

For crying out loud, I can’t even write a blog post properly. Geh. Whatever. at least Mr Baby’s getting big.

In other news that probably doesn’t really concern or affect anyone, I like Zoundry Raven’s interface, but after trying it out for real, I’m sticking with Windows Live Writer.

On to different things. I’ve been playing around with ISO8583 and jPOS for some stuff at work, and a problem that has raised its head consistently is how to communicate with a HSM. So far, lacking a true-blue HSM to work with, I’ve been trying to get my code working with this simulator with not a lot of success. Even after wandering the web and the jPOS mailing list (as well as Andy Orrock’s blog), it seemed I was doomed to fail. Yesterday, I decided to stop looking for ready-made answers and devote time to the problem. After looking at the jPOS API documentation on FSDMsg, I was able to come up with some code that — while it doesn't exactly mirror Andy Orrock's code — works. Without further ado, it's reproduced for your viewing pleasure below (syntax highlighting via Highlight, as I've not yet got around to finding a code display widget that works on Blogger).


package testbed;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.jdom.JDOMException;
import org.jpos.iso.channel.FSDChannel;
import org.jpos.iso.packager.DummyPackager;
import org.jpos.iso.FSDISOMsg;
import org.jpos.iso.ISOException;
import org.jpos.util.FSDMsg;
import org.jpos.util.Logger;
import org.jpos.util.SimpleLogListener;

public class TestBed {

  public static void main(String[] args) throws FileNotFoundException, IOException{
    FSDChannel channel = new FSDChannel();
    channel.setPackager(new DummyPackager());

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

    channel.setLogger(logger, "regular");

    FSDMsg message = new FSDMsg("file:hsm-");
    message.set("command", "NC");

    FSDISOMsg wrapper = new FSDISOMsg(message);
    wrapper.setHeader(new byte[] {0, 0, 0, 0});

    try {
        byte [] buffer = new byte[1024];

        FSDMsg response = new FSDMsg("file:hsm-resp-", "ND");


        System.out.println("Firmware number is: " + response.get("firmware-number"));
    catch (ISOException ex) {
    catch (IOException ex) {
    catch (JDOMException ex) {


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


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


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



The code above seems to work fine…till you really look at what it does. For some reason, jPOS isn’t picking up hsm-resp-base.xml at all. Here's an updated hsm-resp-ND.xml

<?xml version="1.0" encoding="UTF-8"?>
<schema id='ND'>
    <!--this is the 2-byte message length header-->
    <field id="messagelength" type="A" length="2" />
    <!--this is the 4-byte header you need to prepend the actual data with,
            byte[] header = new byte [] { 0, 0, 0, 0 }; // or whatever header you decide, useful for tagging requests
    <field id="header" type="A" length="4" />
    <!--this is the response id. in this case, it'll always be ND-->
    <field id="command" type="A" length="2" />
    <!--this is the response code-->
    <field id="response" type="N" length="2" />
    <!--this is the LMK check value-->
    <field id="lmk-check-value" type="A" length="16" />
    <!--this is the firmware number-->
    <field id="firmware-number" type="A" length="9" />

No comments: