/** * not available on Leaf - always throw ISOException * @exception ISOException */ public byte[] pack() throws ISOException { throw new ISOException ("Not available on Leaf"); } /**
private static String hexOffset (int i) { i = i>>4 << 4; int w = i > 0xFFFF ? 8 : 4; try { return zeropad (Integer.toString (i, 16), w); } catch (ISOException e) { // should not happen return e.getMessage(); } }
@Override public void handleUnpackError(ISOComponent isoComponent, byte[] msg, ISOException e) { StringBuilder sb = new StringBuilder("Error unpacking message:\n"); sb.append(e.toString()).append("\n"); sb.append("Raw data:\n").append(new String(msg)).append("\n"); LogEvent logEvent = new LogEvent(this, "unpack-error"); logEvent.addMessage(sb.toString()); logEvent.addMessage(e); Logger.log(logEvent); } }
public void dump (PrintStream p, String indent) { String inner = indent + " "; p.println (indent + "<"+getTagName()+">"); p.println (inner + getMessage()); if (nested != null) { if (nested instanceof ISOException) ((ISOException)nested).dump (p, inner); else { p.println (inner + "<nested-exception>"); p.print (inner); nested.printStackTrace (p); p.println (inner + "</nested-exception>"); } } p.print (inner); printStackTrace (p); p.println (indent + "</"+getTagName()+">"); } public String toString() {
@Ignore("test fails - GenericValidatingPackager to be deprecated") @Test public void testConstructorThrowsISOException1() throws Throwable { try { new GenericValidatingPackager(new ByteArrayInputStream("x".getBytes())); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getMessage()", "org.xml.sax.SAXParseException: Content is not allowed in prolog.", ex.getMessage()); assertEquals("ex.getNested().getMessage()", "Content is not allowed in prolog.", ex.getNested().getMessage()); } }
@Test public void testConstructorThrowsISOException1() throws Throwable { try { new GenericPackager(new ByteArrayInputStream("".getBytes())); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getNested().getClass()", SAXParseException.class, ex.getNested().getClass()); assertEquals("ex.getNested().getMessage()", "Premature end of file.", ex.getNested().getMessage()); } }
/** * Packager Configuration. * * <ul> * <li>packager-config * <li>packager-logger * <li>packager-realm * </ul> * * @param cfg Configuration */ public void setConfiguration (Configuration cfg) throws ConfigurationException { filename = cfg.get("packager-config", null); if (filename == null) throw new ConfigurationException("packager-config property cannot be null"); try { String loggerName = cfg.get("packager-logger"); if (loggerName != null) setLogger(Logger.getLogger (loggerName), cfg.get ("packager-realm")); readFile(filename); } catch (ISOException e) { throw new ConfigurationException(e.getMessage(), e.fillInStackTrace()); } }
@Test public void testConstructorThrowsISOException() throws Throwable { try { new LogPackager(); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertMatch("ex.getMessage()", ".*java.lang.ClassNotFoundException: org.apache.crimson.parser.XMLReaderImpl", ex.getMessage()); assertNull("ex.getNested()", ex.getNested()); } } }
@Test public void testConstructorThrowsISOException() throws Throwable { byte[] bytes = new byte[1]; try { new X92GenericPackager(new ByteArrayInputStream(bytes)); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getNested().getClass()", SAXParseException.class, ex.getNested().getClass()); assertEquals("ex.getNested().getMessage()", "Content is not allowed in prolog.", ex.getNested().getMessage()); } }
/** * valid on Leafs only. * @return object representing the field value * @exception ISOException */ public Object getValue() throws ISOException { throw new ISOException ("N/A in Composite"); } /**
@Test public void testPackThrowsISOException1() throws Throwable { try { new CTCSubElementPackager().pack(null); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getMessage()", "null:null", ex.getMessage()); assertNull("ex.getNested().getMessage()", ex.getNested().getMessage()); } }
public void readExternal (ObjectInput in) throws IOException, ClassNotFoundException { fieldNumber = in.readShort (); try { setValue(in.readUTF()); } catch (ISOException e) { throw new IOException (e.getMessage()); } }
@Test public void testReadFileThrowsISOException() throws Throwable { try { new GenericSubFieldPackager().readFile(new ByteArrayInputStream("".getBytes())); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getNested().getClass()", SAXParseException.class, ex.getNested().getClass()); assertEquals("ex.getNested().getMessage()", "Premature end of file.", ex.getNested().getMessage()); } }
@Override public void handlePackError(ISOComponent m, ISOException e) { StringBuilder sb = new StringBuilder("Error packing message:\n"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); m.dump(ps, ""); sb.append(e.toString()).append("\n"); sb.append("Message dump:\n").append(new String(baos.toByteArray())).append("\n"); LogEvent logEvent = new LogEvent(this, "pack-error"); logEvent.addMessage(sb.toString()); logEvent.addMessage(e); Logger.log(logEvent); }
/** * not available on Leaf - always throw ISOException * @exception ISOException */ public byte[] pack() throws ISOException { throw new ISOException ("Not available on Leaf"); } /**
@Test public void testPackThrowsISOException2() throws Throwable { try { new EuroSubFieldPackager().pack(null); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getMessage()", "java.lang.NullPointerException", ex.getMessage()); assertNull("ex.getNested().getMessage()", ex.getNested().getMessage()); } }
@Test public void testUnpack() { try { iSOAmount.unpack(new byte[1]); fail("ISOException Expected"); } catch (ISOException isoe) { assertThat(isoe.getMessage(), is("Not available")); } }
@Test public void testConstructorThrowsISOException() throws Throwable { try { new GenericPackager("testGenericPackagerFilename"); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getNested().getClass()", FileNotFoundException.class, ex.getNested().getClass()); } }
JComponent createISOMsgDumpPanel() { JPanel p = new JPanel(); JTextArea t = new JTextArea(3,20); p.setLayout(new BorderLayout()); p.setBackground(Color.white); p.setBorder(BorderFactory.createLoweredBevelBorder()); p.add(new JLabel("Dump", SwingConstants.LEFT), BorderLayout.NORTH); t.setFont(new Font ("Helvetica", Font.PLAIN, 8)); t.setLineWrap(true); try { StringBuilder buf = new StringBuilder(); if (m.getHeader() != null) { buf.append("--[Header]--\n"); buf.append(ISOUtil.hexString(m.getHeader())); buf.append("\n--[Msg]--\n"); } byte[] b = m.pack(); buf.append (ISOUtil.hexString(b)); t.setText(buf.toString()); } catch (ISOException e) { t.setText(e.toString()); t.setForeground(Color.red); } p.add(t, BorderLayout.CENTER); return p; } }
/** * Don't call setValue on an ISOMsg. You'll sure get * an ISOException. It's intended to be used on Leafs * @param obj * @throws org.jpos.iso.ISOException * @see ISOField * @see ISOException */ @Override public void setValue(Object obj) throws ISOException { throw new ISOException ("setValue N/A in ISOMsg"); }