Search code examples
iso8583jpos

Send ISOMsg to ISOServer


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.


Solution

  • 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:");
    
        }
    
    }