== LoopbackChannel

Loopback channel bounces all received messages using a blocking queue. It can
be used for simulation purposes. When using in combination with a suitable
ISOFilter, you can modify the outgoing or incoming (bounced) message so it 
can easily simulate a response.

[source,java]
----
package loopback;

import java.io.IOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOFilter;
import org.jpos.iso.ISOChannel;
import org.jpos.iso.ISOException;
import org.jpos.iso.channel.LoopbackChannel;
import org.jpos.util.LogEvent;

public class Test implements ISOFilter {
    public static void main (String[] args) {
        try {
            new Test().run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void run () throws ISOException, IOException {
        LoopbackChannel channel = new LoopbackChannel ();
        channel.addIncomingFilter (this);
        ISOMsg request  = createRequest();
        request.dump (System.out, "request>  ");
        channel.send (request);
        ISOMsg response = channel.receive();
        response.dump (System.out, "response> ");
    }

    private ISOMsg createRequest () throws ISOException {
        ISOMsg m = new ISOMsg ("0800");
        m.set (11, "000001");
        m.set (41, "29110001");
        m.set (70, "301");
        return m;
    }
    public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) {
        try {
            m.setResponseMTI ();
            m.set (39, "00");
        } catch (ISOException e) {
            e.printStackTrace();
        }
        return m;
    }
}
  
----

The previous program produces the following output: 

----
request>  <isomsg>
request>    <field id="0" value="0800"/>
request>    <field id="11" value="000001"/>
request>    <field id="41" value="29110001"/>
request>    <field id="70" value="301"/>
request>  </isomsg>
response> <isomsg direction="incoming">
response>   <field id="0" value="0810"/>
response>   <field id="11" value="000001"/>
response>   <field id="39" value="00"/>
response>   <field id="41" value="29110001"/>
response>   <field id="70" value="301"/>
response> </isomsg>
----

[TIP]
====
For a better way to simulate a remote host, you can have a look at the 
*serversimulator* module in the jPOS-EE distribution.
====

