@Test public void testBytesMessageToAdaptrisMessage_StreamFailure_CheckedJMSException() throws Exception { BytesMessage jmsMsg = Mockito.mock(BytesMessage.class); Session session = Mockito.mock(Session.class); doThrow(new JMSException(testName.getMethodName())).when(jmsMsg).readByte(); when(session.createBytesMessage()).thenReturn(jmsMsg); BytesMessageTranslator trans = new BytesMessageTranslator() { @Override long streamThreshold() { return TEXT.length() - 1; } }; try { start(trans, session); try { AdaptrisMessage msg = trans.translate(jmsMsg); fail(); } catch (JMSException expected) { } } finally { stop(trans); } }
public Message translate(AdaptrisMessage msg) throws JMSException { BytesMessage jmsMsg = session.createBytesMessage(); if (msg.getSize() > streamThreshold()) { try (InputStream in = msg.getInputStream(); BytesMessageOutputStream out = new BytesMessageOutputStream(jmsMsg)) { StreamUtil.copyAndClose(in, out); } catch (IOException e) { throw JmsUtils.wrapJMSException(e); } } else { jmsMsg.writeBytes(msg.getPayload()); } return helper.moveMetadata(msg, jmsMsg); }
BytesMessageTranslator extends MessageTypeTranslatorImp { public Message translate(AdaptrisMessage msg) throws JMSException { BytesMessage jmsMsg = session.createBytesMessage(); if (msg.getSize() > streamThreshold()) { try (InputStream in = msg.getInputStream(); BytesMessageOutputStream out = new BytesMessageOutputStream(jmsMsg)) { StreamUtil.copyAndClose(in, out); } catch (IOException e) { throw JmsUtils.wrapJMSException(e); } } else { jmsMsg.writeBytes(msg.getPayload()); } return helper.moveMetadata(msg, jmsMsg); } }
BytesMessageTranslator extends MessageTypeTranslatorImp { public Message translate(AdaptrisMessage msg) throws JMSException { BytesMessage jmsMsg = session.createBytesMessage(); if (msg.getSize() > streamThreshold()) { try (InputStream in = msg.getInputStream(); BytesMessageOutputStream out = new BytesMessageOutputStream(jmsMsg)) { StreamUtil.copyAndClose(in, out); } catch (IOException e) { throw JmsUtils.wrapJMSException(e); } } else { jmsMsg.writeBytes(msg.getPayload()); } return helper.moveMetadata(msg, jmsMsg); }  }
BytesMessageTranslator extends MessageTypeTranslatorImp { public Message translate(AdaptrisMessage msg) throws JMSException { BytesMessage jmsMsg = session.createBytesMessage(); if (msg.getSize() > streamThreshold()) { try (InputStream in = msg.getInputStream(); BytesMessageOutputStream out = new BytesMessageOutputStream(jmsMsg)) { StreamUtil.copyAndClose(in, out); } catch (IOException e) { throw JmsUtils.wrapJMSException(e); } } else { jmsMsg.writeBytes(msg.getPayload()); } return helper.moveMetadata(msg, jmsMsg); }  Message translate(AdaptrisMessage msg); AdaptrisMessage translate(Message msg); }
BytesMessageTranslator extends MessageTypeTranslatorImp { public Message translate(AdaptrisMessage msg) throws JMSException { BytesMessage jmsMsg = session.createBytesMessage(); if (msg.getSize() > streamThreshold()) { try (InputStream in = msg.getInputStream(); BytesMessageOutputStream out = new BytesMessageOutputStream(jmsMsg)) { StreamUtil.copyAndClose(in, out); } catch (IOException e) { throw JmsUtils.wrapJMSException(e); } } else { jmsMsg.writeBytes(msg.getPayload()); } return helper.moveMetadata(msg, jmsMsg); }  Message translate(AdaptrisMessage msg); AdaptrisMessage translate(Message msg);  }