Search in sources :

Example 6 with ISOChannel

use of org.jpos.iso.ISOChannel in project jPOS by jpos.

the class MacroFilterTest method testFilter.

@Test
public void testFilter() throws Throwable {
    MacroFilter macroFilter = new MacroFilter();
    ISOChannel channel = new GZIPChannel(new X92GenericPackager());
    LogEvent evt = new LogEvent("testMacroFilterTag", "\u0000\u0000");
    when(m.getMaxField()).thenReturn(0);
    ISOMsg result = macroFilter.filter(channel, m, evt);
    assertSame("result", m, result);
    verify(m).hasField(0);
}
Also used : ISOMsg(org.jpos.iso.ISOMsg) LogEvent(org.jpos.util.LogEvent) ISOChannel(org.jpos.iso.ISOChannel) GZIPChannel(org.jpos.iso.channel.GZIPChannel) X92GenericPackager(org.jpos.iso.packager.X92GenericPackager) Test(org.junit.Test)

Example 7 with ISOChannel

use of org.jpos.iso.ISOChannel in project jPOS by jpos.

the class ISOMeterFactory method create.

public JComponent create(UI ui, Element e) {
    ISOChannelPanel icp = null;
    try {
        Object obj = NameRegistrar.get(e.getAttributeValue("idref"));
        if (obj instanceof ISOChannel) {
            icp = new ISOChannelPanel((ISOChannel) obj, e.getText());
        } else if (obj instanceof Observable) {
            icp = new ISOChannelPanel(e.getText());
            ((Observable) obj).addObserver(icp);
        }
        ISOMeter meter = icp.getISOMeter();
        if ("false".equals(e.getAttributeValue("scroll")))
            meter.setScroll(false);
        String protect = e.getAttributeValue("protect");
        if (protect != null)
            icp.setProtectFields(ISOUtil.toIntArray(protect));
        String wipe = e.getAttributeValue("wipe");
        if (wipe != null)
            icp.setWipeFields(ISOUtil.toIntArray(wipe));
        String refresh = e.getAttributeValue("refresh");
        if (refresh != null)
            meter.setRefresh(Integer.parseInt(refresh));
    } catch (Exception ex) {
        ex.printStackTrace();
        return new JLabel(ex.getMessage());
    }
    return icp;
}
Also used : ISOMeter(org.jpos.iso.gui.ISOMeter) ISOChannelPanel(org.jpos.iso.gui.ISOChannelPanel) ISOChannel(org.jpos.iso.ISOChannel) Observable(java.util.Observable)

Example 8 with ISOChannel

use of org.jpos.iso.ISOChannel in project jPOS by jpos.

the class ChannelPool method connect.

public synchronized void connect() throws IOException {
    current = null;
    LogEvent evt = new LogEvent(this, "connect");
    evt.addMessage("pool-size=" + Integer.toString(pool.size()));
    for (int i = 0; i < pool.size(); i++) {
        try {
            evt.addMessage("pool-" + Integer.toString(i));
            ISOChannel c = (ISOChannel) pool.get(i);
            c.connect();
            if (c.isConnected()) {
                current = c;
                usable = true;
                break;
            }
        } catch (IOException e) {
            evt.addMessage(e);
        }
    }
    if (current == null)
        evt.addMessage("connect failed");
    Logger.log(evt);
    if (current == null) {
        throw new IOException("unable to connect");
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) IOException(java.io.IOException) ISOChannel(org.jpos.iso.ISOChannel)

Example 9 with ISOChannel

use of org.jpos.iso.ISOChannel in project jPOS by jpos.

the class ChannelPool method disconnect.

public synchronized void disconnect() throws IOException {
    current = null;
    LogEvent evt = new LogEvent(this, "disconnect");
    for (Object aPool : pool) {
        try {
            ISOChannel c = (ISOChannel) aPool;
            c.disconnect();
        } catch (IOException e) {
            evt.addMessage(e);
        }
    }
    Logger.log(evt);
}
Also used : LogEvent(org.jpos.util.LogEvent) IOException(java.io.IOException) ISOChannel(org.jpos.iso.ISOChannel)

Example 10 with ISOChannel

use of org.jpos.iso.ISOChannel in project jPOS by jpos.

the class ChannelAdaptorTest method stopCanWaitForWorkersEvenWhenSenderBlockedTryingToConnect.

@Test
public void stopCanWaitForWorkersEvenWhenSenderBlockedTryingToConnect() throws Exception {
    // Think a link where the other ends plays the client role. Eg a BaseChannel with a serverSocket.
    // So connect() calls socket.accept(). If no client connects accept() blocks forever.
    // Ensures disconnect() is called on stop() regardless of channel.isConnected() return value.
    ISOChannel channel = mock(ISOChannel.class);
    ThreadTrap trap = new ThreadTrap(SENDER_THREAD_NAME);
    when(channel.isConnected()).thenReturn(false);
    trap.catchVictim().when(channel).connect();
    trap.release().when(channel).disconnect();
    channelAdaptor = configureAndStart(new ChannelAdaptorWithoutQ2(channel));
    waitForSenderAndReceiverToStart();
    assertThat("Sender did not call connect()", trap.catchesVictim(), is(true));
    assertCallToStopCompletes(1);
}
Also used : ISOChannel(org.jpos.iso.ISOChannel) Test(org.junit.Test)

Aggregations

ISOChannel (org.jpos.iso.ISOChannel)15 Test (org.junit.Test)10 LogEvent (org.jpos.util.LogEvent)9 ISOMsg (org.jpos.iso.ISOMsg)7 PADChannel (org.jpos.iso.channel.PADChannel)3 IOException (java.io.IOException)2 ConfigurationException (org.jpos.core.ConfigurationException)2 ISOException (org.jpos.iso.ISOException)2 CSChannel (org.jpos.iso.channel.CSChannel)2 ServerSocket (java.net.ServerSocket)1 Observable (java.util.Observable)1 StringTokenizer (java.util.StringTokenizer)1 Configuration (org.jpos.core.Configuration)1 SimpleConfiguration (org.jpos.core.SimpleConfiguration)1 FactoryChannel (org.jpos.iso.FactoryChannel)1 FilteredChannel (org.jpos.iso.FilteredChannel)1 ISOClientSocketFactory (org.jpos.iso.ISOClientSocketFactory)1 ISOPackager (org.jpos.iso.ISOPackager)1 ISOVMsg (org.jpos.iso.ISOVMsg)1 GZIPChannel (org.jpos.iso.channel.GZIPChannel)1