Search in sources :

Example 11 with ISOChannel

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

the class DelayFilterTest method testFilter.

@Test
public void testFilter() throws Throwable {
    DelayFilter delayFilter = new DelayFilter(0);
    LogEvent evt = new LogEvent("testDelayFilterTag", "testString");
    ISOChannel channel = new CSChannel(new Base1SubFieldPackager(), new ServerSocket());
    ISOMsg result = delayFilter.filter(channel, m, evt);
    assertEquals("evt.payLoad.size()", 2, evt.getPayLoad().size());
    assertEquals("evt.payLoad.get(1)", "<delay-filter delay=\"0\"/>", evt.getPayLoad().get(1));
    assertSame("result", m, result);
}
Also used : Base1SubFieldPackager(org.jpos.iso.packager.Base1SubFieldPackager) ISOMsg(org.jpos.iso.ISOMsg) LogEvent(org.jpos.util.LogEvent) ServerSocket(java.net.ServerSocket) ISOChannel(org.jpos.iso.ISOChannel) CSChannel(org.jpos.iso.channel.CSChannel) Test(org.junit.Test)

Example 12 with ISOChannel

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

the class MacroFilterTest method testFilter3.

@Test
public void testFilter3() throws Throwable {
    MacroFilter macroFilter = new MacroFilter();
    ISOChannel channel = new PADChannel(new GenericSubFieldPackager());
    LogEvent evt = new LogEvent();
    when(m.getMaxField()).thenReturn(0);
    when(m.hasField(0)).thenReturn(false);
    ISOMsg result = macroFilter.filter(channel, m, evt);
    assertSame("result", m, result);
}
Also used : ISOMsg(org.jpos.iso.ISOMsg) LogEvent(org.jpos.util.LogEvent) PADChannel(org.jpos.iso.channel.PADChannel) GenericSubFieldPackager(org.jpos.iso.packager.GenericSubFieldPackager) ISOChannel(org.jpos.iso.ISOChannel) Test(org.junit.Test)

Example 13 with ISOChannel

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

the class StatefulFilterTest method testFilter2.

@Test
public void testFilter2() throws Throwable {
    int[] key = new int[0];
    StatefulFilter statefulFilter = new StatefulFilter();
    statefulFilter.setKey(key);
    ISOChannel iSOChannel = new PADChannel();
    LogEvent evt = new LogEvent("testStatefulFilterTag");
    ISOMsg m = mock(ISOMsg.class);
    given(m.getDirection()).willReturn(58);
    ISOMsg result = statefulFilter.filter(iSOChannel, m, evt);
    assertSame("result", m, result);
}
Also used : ISOMsg(org.jpos.iso.ISOMsg) LogEvent(org.jpos.util.LogEvent) PADChannel(org.jpos.iso.channel.PADChannel) ISOChannel(org.jpos.iso.ISOChannel) Test(org.junit.Test)

Example 14 with ISOChannel

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

the class OneShotChannelAdaptorMK2 method newChannel.

private ISOChannel newChannel(Element e, QFactory f) throws ConfigurationException {
    String channelName = e.getAttributeValue("class");
    if (channelName == null) {
        throw new ConfigurationException("class attribute missing from channel element.");
    }
    String packagerName = e.getAttributeValue("packager");
    ISOChannel channel = (ISOChannel) f.newInstance(channelName);
    ISOPackager packager;
    if (packagerName != null) {
        packager = (ISOPackager) f.newInstance(packagerName);
        channel.setPackager(packager);
        f.setConfiguration(packager, e);
    }
    QFactory.invoke(channel, "setHeader", e.getAttributeValue("header"));
    f.setLogger(channel, e);
    f.setConfiguration(channel, e);
    if (channel instanceof FilteredChannel) {
        addFilters((FilteredChannel) channel, e, f);
    }
    String socketFactoryString = getSocketFactory();
    if (socketFactoryString != null && channel instanceof FactoryChannel) {
        ISOClientSocketFactory sFac = (ISOClientSocketFactory) getFactory().newInstance(socketFactoryString);
        if (sFac != null && sFac instanceof LogSource) {
            ((LogSource) sFac).setLogger(log.getLogger(), getName() + ".socket-factory");
        }
        getFactory().setConfiguration(sFac, e);
        ((FactoryChannel) channel).setSocketFactory(sFac);
    }
    return channel;
}
Also used : ISOPackager(org.jpos.iso.ISOPackager) ConfigurationException(org.jpos.core.ConfigurationException) LogSource(org.jpos.util.LogSource) FilteredChannel(org.jpos.iso.FilteredChannel) ISOClientSocketFactory(org.jpos.iso.ISOClientSocketFactory) FactoryChannel(org.jpos.iso.FactoryChannel) ISOChannel(org.jpos.iso.ISOChannel)

Example 15 with ISOChannel

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

the class QServer method notify.

/*
     * This method will be invoked through the SpaceListener interface we registered once
     * we noticed we had an 'in' queue.
     */
@Override
public void notify(Object key, Object value) {
    Object obj = sp.inp(key);
    if (obj instanceof ISOMsg) {
        ISOMsg m = (ISOMsg) obj;
        if ("LAST".equals(sendMethod)) {
            try {
                ISOChannel c = server.getLastConnectedISOChannel();
                if (c == null) {
                    throw new ISOException("Server has no active connections");
                }
                if (!c.isConnected()) {
                    throw new ISOException("Client disconnected");
                }
                c.send(m);
            } catch (Exception e) {
                getLog().warn("notify", e);
            }
        } else if ("ALL".equals(sendMethod)) {
            String channelNames = getISOChannelNames();
            if (channelNames != null) {
                StringTokenizer tok = new StringTokenizer(channelNames, " ");
                while (tok.hasMoreTokens()) {
                    try {
                        ISOChannel c = server.getISOChannel(tok.nextToken());
                        if (c == null) {
                            throw new ISOException("Server has no active connections");
                        }
                        if (!c.isConnected()) {
                            throw new ISOException("Client disconnected");
                        }
                        c.send(m);
                    } catch (Exception e) {
                        getLog().warn("notify", e);
                    }
                }
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) ISOChannel(org.jpos.iso.ISOChannel) ConfigurationException(org.jpos.core.ConfigurationException) ISOException(org.jpos.iso.ISOException)

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