start working with jpos

3.4k views Asked by At

I am creating a new payment application. What I have is a client application that user selects price, enter its authentication information and then client creates and iso 8583 message and send this data to a bank server.

According to my researches, I can use jPOS for emulating bank server. Actually I need a server for getting the iso messages and response to them but I do not know how can I use jPOS for this propose.

I searched for this in the internet but could not find any resource that answer we clearly. My main question is that whether I need to create an application using jPOS for implementing my requirements or only installing the jPOS on the server is enough for testing my client app?

1

There are 1 answers

2
Mubashar On BEST ANSWER

Well, read jpos library documentation its draft version is available on the web you can find it here

Specific to your question about JPOS Server better to implement your own server. JPos provides class ISOServer e.g. following beans initiates a ISO Server in applicationContext.xml file

<bean id="paymentServer" class="org.jpos.iso.ISOServer">
    <constructor-arg>
        <value>13000</value>
    </constructor-arg>
    <constructor-arg ref="paymentChannel" />
    <constructor-arg ref="paymentServerThreadPool" />
</bean>

<bean id="paymentChannel" class="org.jpos.iso.channel.ASCIIChannel">
    <constructor-arg ref="paymentPackager" />
</bean>

<bean id="paymentPackager" class="com.sample.payment.packager.PaymentPackager"/>

<bean id="paymentServerThreadPool" class="org.jpos.util.ThreadPool">
    <constructor-arg>
        <value>1</value>
    </constructor-arg>
    <constructor-arg>
        <value>100</value>
    </constructor-arg>
    <constructor-arg>
        <value>PaymentServer</value>
    </constructor-arg>
</bean>

<bean id="paymentProcessor" class="com.sample.processors.PaymentProcessor"  init-method="init"/>

Following class to implement packager

public class PaymentPackager extends ISOBasePackager {

    protected ISOFieldPackager fld[] = {
            /* 0000 */ new IFB_NUMERIC  (  4, "Message Type Indicator", false), 
            /* 0001 */ new IFB_BITMAP   ( 16, "Bitmap"),    
            /* 0002 */ new IFB_LLLCHAR  (999, "Primary Account number"),    
            /* 0003 */ new IFB_NUMERIC  (  6, "Processing Code", true),
            /* 0004 */ new IFB_NUMERIC  ( 12, "Amount, Transaction", true),
            //.....
            /* 0063 */ new IFB_LLLCHAR  (999, "Reserved for national use"),
            /* 0064 */ new IFB_BINARY   ( 20, "Message authentication code field"),
            //.....     
            /* 0125 */ new IF_UNUSED    (),
            /* 0126 */ new IF_UNUSED    (),
            /* 0127 */ new IF_UNUSED    (),
            /* 0128 */ new IFB_BINARY   ( 20, "Message authentication code field"),
    };

    public PaymentPackager() {
        super();
        setFieldPackager(fld);      
    }

}

In application entry point class you can get the bean and use like following to attach the channel listener

paymentServer.addISORequestListener(paymentProcessor);

following is the sample listener

public class PaymentProcessor implements ISORequestListener {

    private static Logger log = LoggerFactory.getLogger(PaymentProcessor.class);

    public void init() {

        //do init
    }

    public boolean process (ISOSource source, ISOMsg m){

        log.debug(">PaymentProcessor.process");

        ISOMsg request = (ISOMsg) m.clone();
        ISOMsg response = new ISOMsg();

        //...
        //build your response
        //...

        source.send(response);
        return true;
    }
}

NOTE: I have not implemented it yet but jpos provides new way to implement server and client using Q2 you can see documentation of QServer class to implement server, I'll try to share sample as soon as I could.

Happy coding :)