MultiPayloadStreamInputParameter extends PayloadStreamInputParameter implements DataInputParameter<InputStream> { @Override public InputStream extract(InterlokMessage m) throws InterlokException { if (m instanceof MultiPayloadAdaptrisMessage) { return extract(m.resolve(getPayloadId()), (MultiPayloadAdaptrisMessage)m); } throw new InterlokException("Cannot extract payload from message type " + m.getClass().getName() + " as it does not support multiple payloads."); }  String getPayloadId(); void setPayloadId(String payloadId); @Override InputStream extract(InterlokMessage m); InputStream extract(String id, MultiPayloadAdaptrisMessage m);  }
@Test public void testExtract() throws Exception { MultiPayloadStreamInputParameter parameter = new MultiPayloadStreamInputParameter(); parameter.setPayloadId(ID); MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage)new MultiPayloadMessageFactory().newMessage(ID, PAYLOAD); try (InputStream stream = parameter.extract(message)) { for (byte b : PAYLOAD) { assertEquals(b, stream.read()); } } try (InputStream stream = parameter.extract(ID, message)) { for (byte b : PAYLOAD) { assertEquals(b, stream.read()); } } try (InputStream stream = parameter.extract(null, message)) { for (byte b : PAYLOAD) { assertEquals(b, stream.read()); } } }
@Test public void testWrongMessageType() { try { MultiPayloadStreamInputParameter parameter = new MultiPayloadStreamInputParameter(); AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage(PAYLOAD); parameter.extract(message); fail(); } catch (Exception e) { } }