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);
}
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);
}
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);
}
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;
}
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);
}
}
}
}
}
}
Aggregations