3

I have to send ISO8583 messages to an ISOServer using jPOS. I was able to communicate with a QServer from a client-simulator sending messages and getting responses. Now, I have to implement a java project (client) that sends those messages to that same server.

I have a QServer listening on port 10000 and an ISOMsg object in the main class of my project. How can I send this message to the server (localhost:10000) ?

Thank you in advance.

Davide Tamburrino
  • 581
  • 1
  • 5
  • 11

1 Answers1

4

The best thing you can do is not to use a main class at all, but use the Client Simulator replacing the client simulator deploy descriptor by one that uses a QBean written by you.Chapters 7.4 - 7.6 of the programmers guide. Walk you through the process of creating one, you just need to change the code to get the MUX (you can use the ClientSimulator code as a base to do that) and use it to make a request as the client simulator does.

Here you have an example QBean that sends a request at the start face and prints the response.

package stack.examples;

import org.jpos.iso.ISOMsg;
import org.jpos.iso.MUX;
import org.jpos.iso.packager.ISO87APackager;
import org.jpos.q2.QBeanSupport;
import org.jpos.q2.iso.QMUX;
public class SendMessageQBean extends  QBeanSupport{

    @Override
    protected void startService() throws Exception {
        super.startService();
        ISOMsg request = new ISOMsg();

        request.setMTI("0200");

        request.set(2, "16");

        request.set(2, "5421287475388412");

        request.set(3, "000000");

        request.set(4, "400.0");

        request.set(7, "0716070815");

        request.set(11, "844515");

        MUX mux = QMUX.getMUX(cfg.get("dest-mux", "clientsimulator-mux"));
        log.info("sending request", request);
        ISOMsg response = mux.request(request, cfg.getInt("timeout", 5000));

        log.info("received response", response);
    }

}

Hope this point you in the right direction.

Also if you really want to write a main for understanding the basic concepts here you have a minimalist code (without muxes, logger, etc).

package stack.examples;

import java.io.IOException;

import org.jpos.iso.ISOChannel;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOPackager;
import org.jpos.iso.channel.XMLChannel;
import org.jpos.iso.packager.XMLPackager;

public class JposClient {

    public static void main(String[] args) throws ISOException, IOException {
        ISOPackager packager = new XMLPackager();
        ISOChannel channel = new XMLChannel("localhost", 10000,packager);
        channel.connect();
        ISOMsg request = new ISOMsg();

        request.setMTI("0200");

        request.set(2, "16");

        request.set(2, "5421287475388412");

        request.set(3, "000000");

        request.set(4, "400.0");

        request.set(7, "0716070815");

        request.set(11, "844515");

        channel.send(request);

        ISOMsg response = channel.receive();

        response.dump(System.out, "response:");

    }

}
Andrés Alcarraz
  • 1,570
  • 1
  • 12
  • 21
  • Thanks for your response. The client-simulator takes the echo_s file as request, where do I specify to use the QBean instead of echo_s? – Davide Tamburrino Jun 06 '17 at 10:24
  • Hi, you need to write your own QBean, the one I wrote is an example code ready to go. Then replace the xml descriptor of the client simulator by one that points to the class you wrote. You need to read the programmers guide referenced in my post in order to understand the concepts I'm mentioning. There's no quick answer/shortcut here, from you question I thought that you wanted to write java code to send the iso message, that's because I wrote an example QBean that creates an iso message and sends it to the server. I guessed that because you were talking about writing a main. – Andrés Alcarraz Jun 06 '17 at 15:44
  • HI @DavideTamburrino I added an example main to the answer – Andrés Alcarraz Jun 06 '17 at 16:11
  • Hi @Andrés Alcarraz, I was able to work around it so I have a server listening to a client which sends ISOMsgs by calling the channel.send(msg) method...everything seems to work fine, thank you for supporting – Davide Tamburrino Jun 07 '17 at 13:49
  • @DavideTamburrino, depending on how you will connect to your server in the real world problem you may need a more complex setup, including a multiplexor and smart logging. If you will have multiple concurrent requests it's better to have one channel permanently connected and use a mux to associate responses to requests, than creating a channel connecting and receiving the response for each request. In this scenario I strongly suggest you to use Q2 to handle that, you can start Q2 from your own application as stated in chapter 7.2 of the programmer's guide. Glad to be of help. – Andrés Alcarraz Jun 07 '17 at 15:02