I am new to JPOS, I need to connect to a TCP/IP connection to send different iso messages like 0800, 0200, but to connect to the server it tells me that the TCP/IP connection type must be Dedicated and Full-Duplex (asynchronous) and will establish a single TCP session.
to explain better, I have developed some java classes for iso messages, which send the message and receive the response. But since I have developed it to send the message, I always have to connect to the socket and after I receive the response, I disconnect. That class I have in java is called from a REST api that has the message data. From my java class I would instantiate it by jpos-2.1.8.jar. But the company where I connect tells me that a transactional connection scheme is not allowed where for each Transaction it connects, sends a request, receives a response and disconnects. It tells me that it must be a TCP/IP connection type, it must be Dedicated and Full-Duplex (asynchronous) and it will establish a single TCP Session.
This is one of the java classes that I have developed
public Map<String, Object> msj0200(String parm1,String parm2, String parm3, String parm4,String parm5, String parm6,String parm7,String parm8) throws ISOException, Throwable {
Create Packager based on XML that contain DE type
GenericPackager packager = new GenericPackager("PackISO.xml");
NACChannel c = new NACChannel();
c.setHost("161.107.88.248");
c.setPort(5000);
c.setTimeout(10000);
c.setPackager(packager);
// Create ISO Message
ISOMsg isoMsg = new ISOMsg();
isoMsg.setHeader("ISO099002002".getBytes());
isoMsg.setMTI("0200");
isoMsg.set(7, parm1);
isoMsg.set(11, parm2);
isoMsg.set(48, parm3);
isoMsg.set(70, parm4);
isoMsg.set(22, parm5);
isoMsg.set(33, parm6);
isoMsg.set(45, parm7);
isoMsg.set(49, parm8);
isoMsg.setPackager(packager);
///I connected
c.connect();
///I send the message
c.send(isoMsg);
///I get the answer del socket
ISOMsg response = c.receive();
//Here I have the logic to return the response to the rest api
///and then i disconnect
c.disconnect();
To make the explanation more graphic, I now have the development
What I understand you must create the jPOS Gateway to be able to send the messages with a permanent session and full duplex.
and excuse me how I tell you I'm new to this tpc/ip and Jpos. I hope you can understand my problem. thanks in advance
You just need to follow the excellent first two jPOS tutorials.
The first one, implementing a jPOS Gateway, will guide you through the steps to write a simple jPOS gateway.
The second, customizing your Gateway, will tell you how to add your own code to the application.
If you need to provide an API to interact with another network, the third one will guide you on how to do that.
It's really easy, you don't have to do almost anything to write a Full duplex, asynchronous, single session TCP connection. Most jPOS (and ISO8583 in general) implementations are like that, so jPOS provides support for that out of the box. You just need to use a MUX, a Channel, and most probably a transaction manager, and those tutorials will show you how.
Given what the OP has added as additional information, and also context from this question, I'm assuming he is deveolping (*) his API with Spring.
You can add a component to start
Q2
with Spring like this:Source: https://gist.github.com/ar/86a4a24384d029c35f784079007393b0
In the
deploy
directory, just put your channel and your multiplexer, following example taken from jPOS gateway tutorial, customized with values provided in your code:10_channel.xml
:20_mux.xml
:Then in your code you just need to:
Of course, you will need to add the logic to catch all potential errors.
(*) Tag
primavera
is spanish for spring.