@Override public String getMTI() throws ISOException { return delegate.getMTI(); }
/** * @return true if message is Retransmission * @exception ISOException on MTI not set */ public boolean isRetransmission() throws ISOException { return getMTI().charAt(3) == '1'; } /**
/** * @return true if message "seems to be" a request * @exception ISOException on MTI not set */ public boolean isRequest() throws ISOException { return Character.getNumericValue(getMTI().charAt (2))%2 == 0; } /**
public String getKey (ISOMsg m) throws ISOException { StringBuilder sb = new StringBuilder (out); sb.append ('.'); sb.append (mapMTI(m.getMTI())); if (headerIsKey && m.getHeader()!=null) { sb.append ('.'); String[] k = mtiKey.getOrDefault(m.getMTI().substring(0,2), key); for (String f : k) { String v = m.getString(f); if ("11".equals(f)) { String vt = v.trim(); int l = m.getMTI().charAt(0) == '2' ? 12 : 6; if (vt.length() < l) v = ISOUtil.zeropad(vt, l);
/** * sets an appropiate response MTI. * * i.e. 0100 becomes 0110<br> * i.e. 0201 becomes 0210<br> * i.e. 1201 becomes 1210<br> * @exception ISOException on MTI not set or it is not a request */ public void setResponseMTI() throws ISOException { if (!isRequest()) throw new ISOException ("not a request - can't set response MTI"); String mti = getMTI(); char c1 = mti.charAt(3); char c2 = '0'; switch (c1) { case '0' : case '1' : c2='0';break; case '2' : case '3' : c2='2';break; case '4' : case '5' : c2='4';break; } set (new ISOField (0, mti.substring(0,2) +(Character.getNumericValue(getMTI().charAt (2))+1) + c2 ) ); } /**
/** * sets an appropiate retransmission MTI<br> * @exception ISOException on MTI not set or it is not a request */ public void setRetransmissionMTI() throws ISOException { if (!isRequest()) throw new ISOException ("not a request"); set (new ISOField (0, getMTI().substring(0,3) + "1")); } protected void writeHeader (ObjectOutput out) throws IOException {
@Test public void testSerializeDeserializeThenCompare() throws Exception { ISOMsg msg = new ISOMsg(); msg.setMTI("0800"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(buffer); out.writeObject(msg); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); ISOMsg dest = (ISOMsg) in.readObject(); in.close(); assertEquals("obj != deserialize(serialize(obj))", msg.getMTI(), dest.getMTI()); }
public boolean process (ISOSource source, ISOMsg m) { try{ String mti = m.getMTI (); if (!whitelist.contains(mti) && !whitelist.contains("*")) mti = "unsupported";
private MUX nextAvailableWithOverrideMUX(ISOMsg m, long maxWait) { try{ if(originalChannelField != null && !"".equals(originalChannelField)){ String channelName = m.getString(originalChannelField); if(channelName != null && !"".equals(channelName) && overrideMTI(m.getMTI())){ ChannelAdaptor channel = (ChannelAdaptor)NameRegistrar.get (channelName); for (MUX mx : mux) { if(channel != null && ((QMUX)mx).getInQueue().equals(channel.getOutQueue())){ if(isUsable(mx)) return mx; } } } } return nextAvailableMUX(msgno.incrementAndGet(), maxWait); }catch(Exception e){ getLog().warn(e); } return null; } private MUX splitByDivisorMUX(ISOMsg m, long maxWait) {
String mti = m.getMTI (); if (!whitelist.contains(mti) && !whitelist.contains("*")) // not in whitelist return false; // let another request handle it
@Test public void testGetMTI() throws Throwable { String result = new ISOMsg("testISOMsgMti").getMTI(); assertEquals("result", "testISOMsgMti", result); }
@Test public void testUnpack() throws Exception { String path = "build/resources/test/org/jpos/iso/packagers/"; GenericPackager genericPackager = new GenericPackager(new FileInputStream(path + "ISO93TLVPackager.xml")); ISOMsg msg = new ISOMsg(); InputStream input = new BufferedInputStream(new FileInputStream(path + "ISO93TLVPackager.bin")); try { genericPackager.unpack(msg, input); } finally { input.close(); } assertEquals("1100", msg.getMTI()); assertEquals("48TagA1", ((ISOField) ((ISOMsg) msg.getComponent(48)).getComponent(1)).getValue()); }
public ISOComponent validate(ISOComponent m) throws org.jpos.iso.ISOException { if ( msgTypes.contains ( ((ISOMsg)m).getMTI() ) ){ LogEvent evt = new LogEvent( this, "validate" ); try { super.validate ( m ); ISOMsg msg = (ISOMsg)m; int[] validFields = { 4,5,7,48 }; if ( !msg.hasFields( validFields ) ){ ISOVError e = new ISOVError( "Fields " + makeStrFromArray( validFields ) + " must appear in msg.", "001" ); if ( msg instanceof ISOVMsg ) ((ISOVMsg)msg).addISOVError( e ); else msg = new ISOVMsg( msg, e ); if ( breakOnError ) throw new ISOVException ( "Error on msg. " , msg ); } return msg; } finally { Logger.log( evt ); } } else return m; }
@Test public void testGetMTI1() throws Throwable { ISOMsg iSOMsg = new ISOMsg("testISOMsgMti"); iSOMsg.setFieldNumber(-2); String result = iSOMsg.getMTI(); assertEquals("result", "testISOMsgMti", result); }
@Test public void testSimpleSerialization() throws Exception { ISOMsg msg = new ISOMsg(); msg.setMTI("0800"); byte[] objekt = writeExternalFormToBytes(msg); Object p = readExternalFormFromBytes(objekt); assertEquals(ISOMsg.class, p.getClass()); assertEquals("0800", ((ISOMsg) p).getMTI()); }
@Test public void testUnpackStream() throws IOException, ISOException { String input = "<isomsg><!-- org.jpos.iso.packager.XMLPackager --><header>686561646572</header><field id=\"0\" value=\"0800\"/>" + "<field id=\"7\" value=\"7654321\"/><field id=\"11\" value=\"12345678\"/>" + "<field id=\"12\" value=\"20110224112759\"/><field id=\"24\" value=\"\"/></isomsg>"; isoMsg.setHeader("header".getBytes()); isoMsg.setMTI("0800"); isoMsg.set(7, "7654321"); isoMsg.set(11, "12345678"); isoMsg.set(12, "20110224112759"); isoMsg.set(24, "831"); ISOMsg result = xMLPackager.createISOMsg(); xMLPackager.unpack(result, new ByteArrayInputStream(input.getBytes())); assertThat(result.getHeader(), is("header".getBytes())); assertThat(result.getMTI(), is("0800")); assertThat(result.getString(7), is("7654321")); assertThat(result.getString(11), is("12345678")); assertThat(result.getString(12), is("20110224112759")); assertThat(result.getString(24), is("")); }
@Test public void testUnpackBytes() throws IOException, ISOException { String input = "<isomsg><!-- org.jpos.iso.packager.XMLPackager --><header>686561646572</header><field id=\"0\" value=\"0800\"/>" + "<field id=\"7\" value=\"7654321\"/><field id=\"11\" value=\"12345678\"/>" + "<field id=\"12\" value=\"20110224112759\"/><field id=\"24\" value=\"831\"/></isomsg>"; isoMsg.setHeader("header".getBytes()); isoMsg.setMTI("0800"); isoMsg.set(7, "7654321"); isoMsg.set(11, "12345678"); isoMsg.set(12, "20110224112759"); isoMsg.set(24, ""); ISOMsg result = xMLPackager.createISOMsg(); int consumedBytes = xMLPackager.unpack(result, input.getBytes()); assertThat(consumedBytes, is(247)); assertThat(result.getHeader(), is("header".getBytes())); assertThat(result.getMTI(), is("0800")); assertThat(result.getString(7), is("7654321")); assertThat(result.getString(11), is("12345678")); assertThat(result.getString(12), is("20110224112759")); assertThat(result.getString(24), is("831")); }
@Test public void testGetMTIThrowsISOException() throws Throwable { ISOMsg iSOMsg = new ISOMsg("testISOMsgMti"); iSOMsg.move(100, 0); try { iSOMsg.getMTI(); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getMessage()", "MTI not available", ex.getMessage()); assertNull("ex.nested", ex.nested); } }
@Test public void testGetMTIThrowsISOException1() throws Throwable { ISOMsg iSOMsg = new ISOMsg("testISOMsgMti"); iSOMsg.setFieldNumber(0); try { iSOMsg.getMTI(); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getMessage()", "can't getMTI on inner message", ex.getMessage()); assertNull("ex.nested", ex.nested); } }
@Test public void testUnpack() throws ISOException { ISOMsg m1 = new ISOMsg(); m1.setPackager(p); m1.unpack(PACKED); assertEquals("0800", m1.getMTI()); assertEquals("000000", m1.getString(3)); assertEquals("000001", m1.getString(11)); assertEquals("29110001", m1.getString(41)); assertArrayEquals(ISOUtil.hex2byte("55AA1122"), m1.getBytes(55)); assertEquals("Test 127.2", m1.getString("127.2")); assertEquals("Test 127.3", m1.getString("127.3")); assertEquals("Test 127.4", m1.getString("127.4")); assertEquals("Test 127.5.1", m1.getString("127.5.1")); } }