Java 类javax.jms.StreamMessage 实例源码

项目:apex-malhar    文件:JMSObjectInputOperator.java   
/**
 * This implementation converts a TextMessage back to a String, a
 * ByteMessage back to a byte array, a MapMessage back to a Map,
 * and an ObjectMessage back to a Serializable object. Returns
 * the plain Message object in case of an unknown message type.
 *
 * @return payload
 * @throws javax.jms.JMSException
 */
@Override
public Object convert(Message message) throws JMSException
{
  if (message instanceof TextMessage) {
    return ((TextMessage)message).getText();
  } else if (message instanceof StreamMessage) {
    return ((StreamMessage)message).readString();
  } else if (message instanceof BytesMessage) {
    return extractByteArrayFromMessage((BytesMessage)message);
  } else if (message instanceof MapMessage) {
    return extractMapFromMessage((MapMessage)message);
  } else if (message instanceof ObjectMessage) {
    return extractSerializableFromMessage((ObjectMessage)message);
  } else {
    return message;
  }
}
项目:w4-bpmnplus-module-jms    文件:AbstractW4MessageListener.java   
/**
 * Handle received message. Please note that ByteMessage (without object
 * mapping) and StreamMessage are not managed by the listener.
 *
 * @param message Spring generic message representation of the JMS message.
 * @param session The JMS Session if needed.
 * @param jmsMessage the original JMS message if needed.
 * @return String Message to send back or null if none
 */
public String handle(Message<?> message, Session session, javax.jms.Message jmsMessage) {
  if (message.getPayload() instanceof byte[] || message.getPayload() instanceof StreamMessage) {
    throw new IllegalArgumentException("Message payload type cannot be processed by this listener (" + message.getPayload().getClass().getName() + ")");
  }

  logger.debug("Received message: {}", message.getPayload().toString());

  // Extract data
  Map<String, Object> dataEntries = mapPayloadToData(message.getPayload());

  // Process W4 action
  String returnedMessage = processW4Action(message.getHeaders(), dataEntries);

  return returnedMessage;
}
项目:activemq-artemis    文件:JmsContextTest.java   
@Test
public void testSendStreamMessage() throws JMSException, InterruptedException {
   JmsProducerCompletionListenerTest.CountingCompletionListener cl = new JmsProducerCompletionListenerTest.CountingCompletionListener(1);
   JMSProducer producer = context.createProducer();
   producer.setAsync(cl);
   StreamMessage msg = context.createStreamMessage();
   msg.setStringProperty("name", name.getMethodName());
   String bprop = "booleanProp";
   String iprop = "intProp";
   msg.setBooleanProperty(bprop, true);
   msg.setIntProperty(iprop, 42);
   msg.writeBoolean(true);
   msg.writeInt(67);
   producer.send(queue1, msg);
   JMSConsumer consumer = context.createConsumer(queue1);
   Message msg2 = consumer.receive(100);
   Assert.assertNotNull(msg2);
   Assert.assertTrue(cl.completionLatch.await(1, TimeUnit.SECONDS));
   StreamMessage sm = (StreamMessage) cl.lastMessage;
   Assert.assertEquals(true, sm.getBooleanProperty(bprop));
   Assert.assertEquals(42, sm.getIntProperty(iprop));
   Assert.assertEquals(true, sm.readBoolean());
   Assert.assertEquals(67, sm.readInt());
}
项目:activemq-artemis    文件:CompressedInteropTest.java   
private void sendCompressedStreamMessageUsingOpenWire() throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

   final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

   StreamMessage streamMessage = session.createStreamMessage();

   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 10);
   streamMessage.writeBytes(TEXT.getBytes());
   streamMessage.writeChar('A');
   streamMessage.writeDouble(55.3D);
   streamMessage.writeFloat(79.1F);
   streamMessage.writeInt(37);
   streamMessage.writeLong(56652L);
   streamMessage.writeObject(new String("VVVV"));
   streamMessage.writeShort((short) 333);
   streamMessage.writeString(TEXT);

   producer.send(streamMessage);
}
项目:activemq-artemis    文件:GeneralInteropTest.java   
private void sendStreamMessageUsingOpenWire(String queueName) throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

   System.out.println("destination: " + destination);
   final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

   StreamMessage streamMessage = session.createStreamMessage();
   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 2);
   streamMessage.writeBytes(new byte[]{6, 7});
   streamMessage.writeChar('b');
   streamMessage.writeDouble(6.5);
   streamMessage.writeFloat((float) 93.9);
   streamMessage.writeInt(7657);
   streamMessage.writeLong(239999L);
   streamMessage.writeShort((short) 34222);
   streamMessage.writeString("hello streammessage");

   producer.send(streamMessage);
}
项目:activemq-artemis    文件:JMSMessageTypesTest.java   
private void testStreamMessageSendReceive(Connection producerConnection, Connection consumerConnection) throws Throwable {
   Session session = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = session.createQueue(getQueueName());

   MessageProducer producer = session.createProducer(queue);
   for (int i = 0; i < NUM_MESSAGES; i++) {
      StreamMessage message = session.createStreamMessage();
      message.writeInt(i);
      message.writeBoolean(true);
      message.writeString("test");
      producer.send(message);
   }

   Session sessionConsumer = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue consumerQueue = sessionConsumer.createQueue(getQueueName());
   final MessageConsumer consumer = sessionConsumer.createConsumer(consumerQueue);

   for (int i = 0; i < NUM_MESSAGES; i++) {
      StreamMessage m = (StreamMessage) consumer.receive(5000);
      Assert.assertNotNull("Could not receive message count=" + i + " on consumer", m);

      Assert.assertEquals(i, m.readInt());
      Assert.assertEquals(true, m.readBoolean());
      Assert.assertEquals("test", m.readString());
   }
}
项目:activemq-artemis    文件:CompressionOverNetworkTest.java   
@Test
public void testStreamMessageCompression() throws Exception {

   MessageConsumer consumer1 = remoteSession.createConsumer(included);
   MessageProducer producer = localSession.createProducer(included);
   producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

   waitForConsumerRegistration(localBroker, 1, included);

   StreamMessage test = localSession.createStreamMessage();

   for (int i = 0; i < 100; ++i) {
      test.writeString("test string: " + i);
   }

   producer.send(test);
   Message msg = consumer1.receive(RECEIVE_TIMEOUT_MILLS);
   assertNotNull(msg);
   ActiveMQStreamMessage message = (ActiveMQStreamMessage) msg;
   assertTrue(message.isCompressed());

   for (int i = 0; i < 100; ++i) {
      assertEquals("test string: " + i, message.readString());
   }
}
项目:activemq-artemis    文件:MessageCompressionTest.java   
private void sendTestStreamMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
   ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(queue);
   StreamMessage streamMessage = session.createStreamMessage();

   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 10);
   streamMessage.writeBytes(TEXT.getBytes());
   streamMessage.writeChar('A');
   streamMessage.writeDouble(55.3D);
   streamMessage.writeFloat(79.1F);
   streamMessage.writeInt(37);
   streamMessage.writeLong(56652L);
   streamMessage.writeObject(new String("VVVV"));
   streamMessage.writeShort((short) 333);
   streamMessage.writeString(TEXT);

   producer.send(streamMessage);
   connection.close();
}
项目:activemq-artemis    文件:MessageTypeTest.java   
/**
 * Send a <code>StreamMessage</code> with 2 Java primitives in its body (a <code>
 * String</code> and a <code>double</code>).
 * <br />
 * Receive it and test that the values of the primitives of the body are correct
 */
@Test
public void testStreamMessage_2() {
   try {
      StreamMessage message = senderSession.createStreamMessage();
      message.writeString("pi");
      message.writeDouble(3.14159);
      sender.send(message);

      Message m = receiver.receive(TestConfig.TIMEOUT);
      Assert.assertTrue("The message should be an instance of StreamMessage.\n", m instanceof StreamMessage);
      StreamMessage msg = (StreamMessage) m;
      Assert.assertEquals("pi", msg.readString());
      Assert.assertEquals(3.14159, msg.readDouble(), 0);
   } catch (JMSException e) {
      fail(e);
   }
}
项目:activemq-artemis    文件:ForeignStreamMessageTest.java   
@Override
protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException {
   super.assertEquivalent(m, mode, redelivery);

   StreamMessage sm = (StreamMessage) m;

   ProxyAssertSupport.assertTrue(sm.readBoolean());

   byte[] bytes = new byte[5];
   sm.readBytes(bytes);
   String s = new String(bytes);
   ProxyAssertSupport.assertEquals("jboss", s);
   ProxyAssertSupport.assertEquals(-1, sm.readBytes(bytes));

   ProxyAssertSupport.assertEquals(sm.readChar(), 'c');
   ProxyAssertSupport.assertEquals(sm.readDouble(), 1.0D, 0.0D);
   ProxyAssertSupport.assertEquals(sm.readFloat(), 2.0F, 0.0F);
   ProxyAssertSupport.assertEquals(sm.readInt(), 3);
   ProxyAssertSupport.assertEquals(sm.readLong(), 4L);
   ProxyAssertSupport.assertEquals(sm.readObject(), "object");
   ProxyAssertSupport.assertEquals(sm.readShort(), (short) 5);
   ProxyAssertSupport.assertEquals(sm.readString(), "stringvalue");
}
项目:activemq-artemis    文件:StreamMessageTest.java   
@Override
protected void prepareMessage(final Message m) throws JMSException {
   super.prepareMessage(m);

   StreamMessage sm = (StreamMessage) m;

   sm.writeBoolean(true);
   sm.writeByte((byte) 3);
   sm.writeBytes(new byte[]{(byte) 4, (byte) 5, (byte) 6});
   sm.writeChar((char) 7);
   sm.writeDouble(8.0);
   sm.writeFloat(9.0f);
   sm.writeInt(10);
   sm.writeLong(11L);
   sm.writeObject("this is an object");
   sm.writeShort((short) 12);
   sm.writeString("this is a String");
}
项目:activemq-artemis    文件:StreamMessageTest.java   
@Override
protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException {
   super.assertEquivalent(m, mode, redelivery);

   StreamMessage sm = (StreamMessage) m;

   sm.reset();

   ProxyAssertSupport.assertEquals(true, sm.readBoolean());
   ProxyAssertSupport.assertEquals((byte) 3, sm.readByte());
   byte[] bytes = new byte[3];
   sm.readBytes(bytes);
   ProxyAssertSupport.assertEquals((byte) 4, bytes[0]);
   ProxyAssertSupport.assertEquals((byte) 5, bytes[1]);
   ProxyAssertSupport.assertEquals((byte) 6, bytes[2]);
   ProxyAssertSupport.assertEquals(-1, sm.readBytes(bytes));
   ProxyAssertSupport.assertEquals((char) 7, sm.readChar());
   ProxyAssertSupport.assertEquals(new Double(8.0), new Double(sm.readDouble()));
   ProxyAssertSupport.assertEquals(new Float(9.0), new Float(sm.readFloat()));
   ProxyAssertSupport.assertEquals(10, sm.readInt());
   ProxyAssertSupport.assertEquals(11L, sm.readLong());
   ProxyAssertSupport.assertEquals("this is an object", sm.readObject());
   ProxyAssertSupport.assertEquals((short) 12, sm.readShort());
   ProxyAssertSupport.assertEquals("this is a String", sm.readString());
}
项目:activemq-artemis    文件:ActiveMQRAMessageConsumer.java   
/**
 * Wrap message
 *
 * @param message The message to be wrapped
 * @return The wrapped message
 */
Message wrapMessage(final Message message) {
   if (ActiveMQRAMessageConsumer.trace) {
      ActiveMQRALogger.LOGGER.trace("wrapMessage(" + message + ")");
   }

   if (message instanceof BytesMessage) {
      return new ActiveMQRABytesMessage((BytesMessage) message, session);
   } else if (message instanceof MapMessage) {
      return new ActiveMQRAMapMessage((MapMessage) message, session);
   } else if (message instanceof ObjectMessage) {
      return new ActiveMQRAObjectMessage((ObjectMessage) message, session);
   } else if (message instanceof StreamMessage) {
      return new ActiveMQRAStreamMessage((StreamMessage) message, session);
   } else if (message instanceof TextMessage) {
      return new ActiveMQRATextMessage((TextMessage) message, session);
   }
   return new ActiveMQRAMessage(message, session);
}
项目:ffmq    文件:MessageTools.java   
private static AbstractMessage duplicateStreamMessage( StreamMessage srcMessage ) throws JMSException
{
    StreamMessageImpl copy = new StreamMessageImpl();
    copyHeaders(srcMessage,copy);

    srcMessage.reset();
    try
    {
        while (true)
            copy.writeObject(srcMessage.readObject());
    }
    catch (MessageEOFException e)
    {
        // Complete
    }

    return copy;
}
项目:andes    文件:MessageToStringTest.java   
private byte[] getBytes(Message receivedMessage, int testBytesLength) throws JMSException
{
    byte[] byteResults = new byte[testBytesLength];

    if (receivedMessage instanceof BytesMessage)
    {
        assertEquals(testBytesLength, ((BytesMessage) receivedMessage).readBytes(byteResults));
    }
    else if (receivedMessage instanceof StreamMessage)
    {
        assertEquals(testBytesLength, ((StreamMessage) receivedMessage).readBytes(byteResults));
    }
    else if (receivedMessage instanceof MapMessage)
    {
        byteResults = ((MapMessage) receivedMessage).getBytes(BYTE_TEST);
        assertEquals(testBytesLength, byteResults.length);
    }
    else if (receivedMessage instanceof TextMessage)
    {
        byteResults = ((TextMessage) receivedMessage).getText().getBytes();
        assertEquals(testBytesLength, byteResults.length);
    }


    return byteResults;
}
项目:andes    文件:AMQSession.java   
public StreamMessage createStreamMessage() throws JMSException
{
    // This method needs to be improved. Throwables only arrive here from the mina : exceptionRecived
    // calls through connection.closeAllSessions which is also called by the public connection.close()
    // with a null cause
    // When we are closing the Session due to a protocol session error we simply create a new AMQException
    // with the correct error code and text this is cleary WRONG as the instanceof check below will fail.
    // We need to determin here if the connection should be

    synchronized (getFailoverMutex())
    {
        checkNotClosed();

        JMSStreamMessage msg = new JMSStreamMessage(getMessageDelegateFactory());
        msg.setAMQSession(this);
        return msg;
    }
}
项目:carbon-business-messaging    文件:Utils.java   
/**
 * Determines the type of the JMS message
 *
 * @param message - input message
 * @return type of the message as a string
 */
public static String getMsgContentType(Message message) {

    String contentType = "";
    if (message instanceof TextMessage) {
        contentType = "Text";
    } else if (message instanceof ObjectMessage) {
        contentType = "Object";
    } else if (message instanceof MapMessage) {
        contentType = "Map";
    } else if (message instanceof StreamMessage) {
        contentType = "Stream";
    } else if (message instanceof BytesMessage) {
        contentType = "Byte";
    }

    return contentType;
}
项目:carbon-business-messaging    文件:Utils.java   
/**
 * A stream message can have java primitives plus objects, as its content. This method is used
 * for getting the valid message content from the stream.
 *
 * @param streamMessage - input message
 * @param sb            - a string builder to build the whole message content
 * @return - complete message content inside the stream message
 * @throws JMSException
 */
private static String getContentFromStreamMessage(StreamMessage streamMessage,
                                                  StringBuilder sb) throws JMSException {

    boolean eofReached = false;

    while (!eofReached) {

        try {
            Object obj = streamMessage.readObject();
            // obj could be null if the wire type is AbstractBytesTypedMessage.NULL_STRING_TYPE
            if (null != obj) {
                sb.append(obj.toString()).append(", ");
            }
        } catch (MessageEOFException ex) {
            eofReached = true;
        }
    }

    return StringEscapeUtils.escapeHtml(sb.toString());
}
项目:qpid-jms    文件:JmsProduceMessageTypesTest.java   
@Test(timeout = 60000)
public void testSendJMSStreamMessage() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    String payload = "TEST";

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    MessageProducer producer = session.createProducer(queue);
    StreamMessage message = session.createStreamMessage();
    message.writeString(payload);
    producer.send(message);
    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(1, proxy.getQueueSize());

    MessageConsumer consumer = session.createConsumer(queue);
    Message received = consumer.receive(5000);
    assertNotNull(received);
    assertTrue(received instanceof StreamMessage);
    StreamMessage stream = (StreamMessage) received;
    assertEquals(payload, stream.readString());
}
项目:hawtjms    文件:JmsProduceMessageTypesTest.java   
@Ignore
@Test(timeout = 60000)
public void testSendJMSStreamMessage() throws Exception {
    connection = createStompConnection();
    connection.start();

    String payload = "TEST";

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    MessageProducer producer = session.createProducer(queue);
    StreamMessage message = session.createStreamMessage();
    message.writeString(payload);
    producer.send(message);
    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(1, proxy.getQueueSize());

    MessageConsumer consumer = session.createConsumer(queue);
    Message received = consumer.receive(5000);
    assertNotNull(received);
    assertTrue(received instanceof StreamMessage);
    StreamMessage stream = (StreamMessage) received;
    assertEquals(payload, stream.readString());
}
项目:hawtjms    文件:JmsProduceMessageTypesTest.java   
@Test(timeout = 60000)
public void testSendJMSStreamMessage() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    String payload = "TEST";

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    MessageProducer producer = session.createProducer(queue);
    StreamMessage message = session.createStreamMessage();
    message.writeString(payload);
    producer.send(message);
    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(1, proxy.getQueueSize());

    MessageConsumer consumer = session.createConsumer(queue);
    Message received = consumer.receive(5000);
    assertNotNull(received);
    assertTrue(received instanceof StreamMessage);
    StreamMessage stream = (StreamMessage) received;
    assertEquals(payload, stream.readString());
}
项目:jadira    文件:FatalJmsExceptionMessageCreator.java   
private static byte[] extractByteArrayFromMessage(StreamMessage message) throws JMSException {

        ByteArrayOutputStream oStream = new ByteArrayOutputStream(BUFFER_CAPACITY_BYTES);

        byte[] buffer = new byte[BUFFER_CAPACITY_BYTES];

        int bufferCount = -1;

        while ((bufferCount = message.readBytes(buffer)) >= 0) {
            oStream.write(buffer, 0, bufferCount);
            if (bufferCount < BUFFER_CAPACITY_BYTES) {
                break;
            }
        }

        return oStream.toByteArray();
    }
项目:jlubricant    文件:VisitableMessage.java   
public R accept(MessageVisitor<R> messageVisitor) throws Exception {
    if(message instanceof BytesMessage){
        return messageVisitor.onBytesMessage((BytesMessage)message);
    }else if(message instanceof MapMessage){
        return messageVisitor.onMapMessage((MapMessage)message);
    }else if(message instanceof ObjectMessage){
        return messageVisitor.onObjectMessage((ObjectMessage)message);
    }else if(message instanceof StreamMessage){
        return messageVisitor.onStreamMessage((StreamMessage)message);
    }else if(message instanceof TextMessage){
        return messageVisitor.onTextMessage((TextMessage)message);
    }else{
        throw new UnsupportedOperationException("Unknown message of type " + message.getClass());
    }

}
项目:fixflow    文件:MessageSender.java   
public void process(Session session,Destination engine) throws Exception {
            MessageProducer producer = session.createProducer(engine);
            //通知客户端开始接受文件
            StreamMessage message = session.createStreamMessage();

            //开始发送文件
            byte[] content = new byte[4096];
            BufferedInputStream bins = new BufferedInputStream(ins);
            while (bins.read(content) > 0) {
                message = session.createStreamMessage();
//              message.clearBody();
                message.writeBytes(content);
                producer.send(message);
            }
            bins.close();
            ins.close();
        }
项目:pooled-jms    文件:JmsPoolJMSContext.java   
@Override
public StreamMessage createStreamMessage() {
    try {
        return getSession().createStreamMessage();
    } catch (JMSException jmse) {
        throw JMSExceptionSupport.createRuntimeException(jmse);
    }
}
项目:pooled-jms    文件:MockJMSContext.java   
@Override
public StreamMessage createStreamMessage() {
    try {
        return getSession().createStreamMessage();
    } catch (JMSException jmse) {
        throw JMSExceptionSupport.createRuntimeException(jmse);
    }
}
项目:spring-cloud-ribbon-extensions    文件:PreservesMessagePropertiesSessionAdapterTest.java   
@Test
public void createStreamMessage() throws Exception {
    StreamMessage message = mock(StreamMessage.class);
    keys.stream().forEach(x -> current().put(x, x));
    when(delegate.createStreamMessage()).thenReturn(message);
    propagator.createStreamMessage();
    verify(delegate).createStreamMessage();
    verify(message).setStringProperty("1", "1");
}
项目:org.ops4j.pax.transx    文件:JMSContextImpl.java   
@Override
public StreamMessage createStreamMessage() {
    try {
        return getSession().createStreamMessage();
    } catch (JMSException jmse) {
        throw Utils.convertToRuntimeException(jmse);
    }
}
项目:cli-java    文件:Utils.java   
/**
     * Write message binary body to provided file or default one in temp directory.
     *
     * @param filePath file to write data to
     * @param message  to be read and written to provided file
     */
    public static void writeBinaryContentToFile(String filePath, Message message, int msgCounter) {
        byte[] readByteArray;
        try {
            File writeBinaryFile;
            if (filePath == null || filePath.equals("")) {
                writeBinaryFile = File.createTempFile("recv_msg_", Long.toString(System.currentTimeMillis()));
            } else {
                writeBinaryFile = new File(filePath + "_" + msgCounter);
            }

            LOG.debug("Write binary content to file '" + writeBinaryFile.getPath() + "'.");
            if (message instanceof BytesMessage) {
                BytesMessage bm = (BytesMessage) message;
                readByteArray = new byte[(int) bm.getBodyLength()];
                bm.reset(); // added to be able to read message content
                bm.readBytes(readByteArray);
                try (FileOutputStream fos = new FileOutputStream(writeBinaryFile)) {
                    fos.write(readByteArray);
                    fos.close();
                }

            } else if (message instanceof StreamMessage) {
                LOG.debug("Writing StreamMessage to");
                StreamMessage sm = (StreamMessage) message;
//        sm.reset(); TODO haven't tested this one
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject(sm.readObject());
                oos.close();
            }

        } catch (JMSException e) {
            e.printStackTrace();
        } catch (IOException e1) {
            LOG.error("Error while writing to file '" + filePath + "'.");
            e1.printStackTrace();
        }
    }
项目:JmsTools    文件:DequeueWorker.java   
private void saveMessagePayload(Message msg, String baseName) throws JMSException, IOException {
    try (FileOutputStream fos = new FileOutputStream(new File(_messageFileDirectory, baseName + ".payload"))) {
        byte[] payload;
        if (msg instanceof TextMessage) {
            payload = TextMessageData.textToBytes(((TextMessage) msg).getText());
        }
        else if (msg instanceof BytesMessage) {
            BytesMessage bytesMessage = (BytesMessage) msg;
            payload = new byte[(int) bytesMessage.getBodyLength()];
            bytesMessage.readBytes(payload);
        }
        else if (msg instanceof ObjectMessage) {
            payload = _objectMessageAdapter.getObjectPayload((ObjectMessage) msg);
        }
        else if (msg instanceof MapMessage) {
            // Partial support, not all data types are handled and we may not be able to post
            MapMessage mapMessage = (MapMessage) msg;
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Properties props = new Properties();
            for (Enumeration<?> mapNames = mapMessage.getMapNames(); mapNames.hasMoreElements();) {
                String mapName = mapNames.nextElement().toString();
                props.setProperty(mapName, mapMessage.getObject(mapName).toString());
            }
            props.store(bos, "Map message properties for " + msg.getJMSMessageID());
            payload = bos.toByteArray();
        }
        else if (msg instanceof StreamMessage) {
            _logger.warn("Can't save payload for {}, stream messages not supported!", msg.getJMSMessageID());
            payload = new byte[0];
        }
        else {
            _logger.warn("Can't save payload for {}, unsupported type {}!", msg.getJMSMessageID(),
                msg.getClass().getName());
            payload = new byte[0];
        }
        fos.write(payload);
        fos.flush();
    }
}
项目:product-ei    文件:JMSQueueMessageProducer.java   
/**
 * Method to send a StreamMessage.
 *
 * @param payload content of the StreamMessage to be sent
 * @throws JMSException if an error occurs sending the BytesMessage
 */
public void sendStreamMessage(byte[] payload) throws JMSException {
    checkIfConnected();
    StreamMessage streamMessage = session.createStreamMessage();
    streamMessage.writeBytes(payload);
    producer.send(streamMessage);
}
项目:apex-malhar    文件:JMSStringInputOperator.java   
@Override
public String convert(Message message) throws JMSException
{
  if (message instanceof TextMessage) {
    return ((TextMessage)message).getText();
  } else if (message instanceof StreamMessage) {
    return ((StreamMessage)message).readString();
  } else {
    throw new IllegalArgumentException("Unhandled message type " + message.getClass().getName());
  }
}
项目:apex-malhar    文件:JMSObjectInputOperatorTest.java   
private void createStreamMsgs(int numMessages) throws Exception
{
  Long value = 1013L;
  StreamMessage message = testMeta.session.createStreamMessage();
  message.writeObject(value);
  for (int i = 0; i < numMessages; i++) {
    testMeta.producer.send(message);
  }
}
项目:activemq-artemis    文件:CompressedInteropTest.java   
private void receiveStreamMessage(boolean useCore) throws Exception {
   StreamMessage streamMessage = (StreamMessage) receiveMessage(useCore);
   boolean booleanVal = streamMessage.readBoolean();
   assertTrue(booleanVal);
   byte byteVal = streamMessage.readByte();
   assertEquals((byte) 10, byteVal);
   byte[] originVal = TEXT.getBytes();
   byte[] bytesVal = new byte[originVal.length];
   streamMessage.readBytes(bytesVal);
   for (int i = 0; i < bytesVal.length; i++) {
      assertTrue(bytesVal[i] == originVal[i]);
   }
   char charVal = streamMessage.readChar();
   assertEquals('A', charVal);
   double doubleVal = streamMessage.readDouble();
   assertEquals(55.3D, doubleVal, 0.1D);
   float floatVal = streamMessage.readFloat();
   assertEquals(79.1F, floatVal, 0.1F);
   int intVal = streamMessage.readInt();
   assertEquals(37, intVal);
   long longVal = streamMessage.readLong();
   assertEquals(56652L, longVal);
   Object objectVal = streamMessage.readObject();
   Object origVal = new String("VVVV");
   assertTrue(objectVal.equals(origVal));
   short shortVal = streamMessage.readShort();
   assertEquals((short) 333, shortVal);
   String strVal = streamMessage.readString();
   assertEquals(TEXT, strVal);
}
项目:activemq-artemis    文件:GeneralInteropTest.java   
private void sendStreamMessageUsingCoreJms(String queueName) throws Exception {
   Connection jmsConn = null;
   try {
      jmsConn = coreCf.createConnection();
      Session session = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      StreamMessage msg = session.createStreamMessage();
      msg.writeBoolean(true);
      msg.writeByte((byte) 2);
      msg.writeBytes(new byte[]{6, 7});
      msg.writeChar('b');
      msg.writeDouble(6.5);
      msg.writeFloat((float) 93.9);
      msg.writeInt(7657);
      msg.writeLong(239999L);
      msg.writeShort((short) 34222);
      msg.writeString("hello streammessage");

      Queue queue = session.createQueue(queueName);
      MessageProducer producer = session.createProducer(queue);

      producer.send(msg);
   } finally {
      if (jmsConn != null) {
         jmsConn.close();
      }
   }

}
项目:activemq-artemis    文件:MessageTypeTest.java   
/**
 * Send a <code>StreamMessage</code> with an empty body.
 * <br />
 * Receive it and test if the message is effectively an instance of
 * <code>StreamMessage</code>
 */
@Test
public void testStreamMessage_1() {
   try {
      StreamMessage message = senderSession.createStreamMessage();
      sender.send(message);

      Message msg = receiver.receive(TestConfig.TIMEOUT);
      Assert.assertTrue("The message should be an instance of StreamMessage.\n", msg instanceof StreamMessage);
   } catch (JMSException e) {
      fail(e);
   }
}
项目:activemq-artemis    文件:MessageBodyTest.java   
@Test
public void testSMBodyReadable() throws Exception {
   byte bValue = 123;
   StreamMessage sm = queueProducerSession.createStreamMessage();
   sm.writeByte(bValue);
   sm.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageEOFExceptionQTestforStreamMessage");
   queueProducer.send(sm);

   StreamMessage received = (StreamMessage) queueConsumer.receive(3000);
   received.readByte();
}
项目:activemq-artemis    文件:MessageHeaderTest.java   
@Test
public void testCopyOnForeignStreamMessage() throws JMSException {
   ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
   ClientSession session = new FakeSession(clientMessage);

   StreamMessage foreignStreamMessage = new SimpleJMSStreamMessage();
   foreignStreamMessage.writeByte((byte) 1);
   foreignStreamMessage.writeByte((byte) 2);
   foreignStreamMessage.writeByte((byte) 3);

   ActiveMQStreamMessage copy = new ActiveMQStreamMessage(foreignStreamMessage, session);

   MessageHeaderTestBase.ensureEquivalent(foreignStreamMessage, copy);
}
项目:activemq-artemis    文件:ActiveMQRASession.java   
/**
 * Create a stream message
 *
 * @return The message
 * @throws JMSException Thrown if an error occurs
 */
@Override
public StreamMessage createStreamMessage() throws JMSException {
   Session session = getSessionInternal();

   if (ActiveMQRASession.trace) {
      ActiveMQRALogger.LOGGER.trace("createStreamMessage" + session);
   }

   return session.createStreamMessage();
}
项目:activemq-artemis    文件:ActiveMQRAStreamMessage.java   
/**
 * Create a new wrapper
 *
 * @param message the message
 * @param session the session
 */
public ActiveMQRAStreamMessage(final StreamMessage message, final ActiveMQRASession session) {
   super(message, session);

   if (ActiveMQRAStreamMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("constructor(" + message + ", " + session + ")");
   }
}