javax.jms.ObjectMessage Java Examples
The following examples show how to use
javax.jms.ObjectMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmsInvoker.java From dubbox with Apache License 2.0 | 6 votes |
@Override protected Result doInvoke(Invocation invocation) throws Throwable { try { // transfer a RPC to a jms-requestor and return the call result QueueSession session = this.queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); JmsQueueRequestor requestor = new JmsQueueRequestor(session, queue); Message message = session.createObjectMessage((Serializable) invocation); message.setJMSRedelivered(false); ObjectMessage result = (ObjectMessage) requestor.request(message, timeout); if (result == null) return new RpcResult(new RpcException("request is timeout in " + timeout + "ms")); return (Result) (result.getObject()); } catch (JMSException e) { throw new RpcException(e); } }
Example #2
Source File: XAProducerSB.java From solace-integration-guides with Apache License 2.0 | 6 votes |
@TransactionAttribute(value = TransactionAttributeType.REQUIRED) @Override public void sendMessage() throws JMSException { Connection conn = null; Session session = null; MessageProducer prod = null; try { conn = myCF.createConnection(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); prod = session.createProducer(myReplyQueue); ObjectMessage msg = session.createObjectMessage(); msg.setObject("Hello world!"); prod.send(msg, DeliveryMode.PERSISTENT, 0, 0); } finally { if (prod != null) prod.close(); if (session != null) session.close(); if (conn != null) conn.close(); } }
Example #3
Source File: IndexMQSenderTest.java From development with Apache License 2.0 | 6 votes |
@Test public void sendMessage_withJMSResources() throws Exception { MockitoAnnotations.initMocks(this); doReturn(Boolean.TRUE).when(sender).checkJMSResources(); Connection conn = mock(Connection.class); doReturn(conn).when(factory).createConnection(); Session session = mock(Session.class); doReturn(session).when(conn).createSession(eq(false), eq(Session.AUTO_ACKNOWLEDGE)); MessageProducer producer = mock(MessageProducer.class); doReturn(producer).when(session).createProducer(eq(queue)); ObjectMessage om = mock(ObjectMessage.class); doReturn(om).when(session).createObjectMessage(); doNothing().when(om).setObject(caughtMessage.capture()); sender.sendMessage(objectMessage); verify(factory, times(1)).createConnection(); verify(session, times(1)).close(); verify(conn, times(1)).close(); verify(producer, times(1)).send(eq(om)); assertEquals(objectMessage, caughtMessage.getValue()); }
Example #4
Source File: SimpleMessageConverter.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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. * @see #extractStringFromMessage * @see #extractByteArrayFromMessage * @see #extractMapFromMessage * @see #extractSerializableFromMessage */ @Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { if (message instanceof TextMessage) { return extractStringFromMessage((TextMessage) message); } 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; } }
Example #5
Source File: SensorListener.java From oneops with Apache License 2.0 | 6 votes |
/** * takes the jms message */ public void onMessage(Message msg) { try { if (msg instanceof ObjectMessage) { BasicEvent event = (BasicEvent)((ObjectMessage)msg).getObject(); if (logger.isDebugEnabled() || cisToLog.contains(event.getCiId())) { logger.info(gson.toJson(event)); } sensorHeartBeat.timeStampIt(event.getChannel()); sensorHeartBeat.timeStampIt(BasicEvent.DEFAULT_CHANNEL); sensor.sendCEPEvent(event); } msg.acknowledge(); } catch (JMSException e) { logger.info("caught Exception in onMessage",e); } }
Example #6
Source File: GeneralInteropTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void sendObjectMessageUsingCoreJms(String queueName, Serializable object) throws Exception { Connection jmsConn = null; try { jmsConn = coreCf.createConnection(); Session session = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE); ObjectMessage objectMessage = session.createObjectMessage(object); Queue queue = session.createQueue(queueName); MessageProducer producer = session.createProducer(queue); producer.send(objectMessage); } finally { if (jmsConn != null) { jmsConn.close(); } } }
Example #7
Source File: EmbeddedRestActiveMQJMSTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private static void publish(String destination, Serializable object, String contentType) throws Exception { Connection conn = factory.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination dest = session.createQueue(destination); try { assertNotNull("Destination was null", dest); MessageProducer producer = session.createProducer(dest); ObjectMessage message = session.createObjectMessage(); if (contentType != null) { message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType); } message.setObject(object); producer.send(message); } finally { conn.close(); } }
Example #8
Source File: JMSMessageConverter.java From cxf with Apache License 2.0 | 6 votes |
public Object fromMessage(Message message) throws JMSException { if (message instanceof TextMessage) { return ((TextMessage)message).getText(); } else if (message instanceof BytesMessage) { BytesMessage message1 = (BytesMessage)message; byte[] bytes = new byte[(int)message1.getBodyLength()]; message1.readBytes(bytes); return bytes; } else if (message instanceof ObjectMessage) { return ((ObjectMessage)message).getObject(); } else if (message instanceof StreamMessage) { StreamMessage streamMessage = (StreamMessage)message; return streamMessage.readObject(); } else { return new byte[]{}; } }
Example #9
Source File: JMSAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** This method called by {@link AppenderSkeleton#doAppend} method to do most of the real appending work. */ public void append(LoggingEvent event) { if(!checkEntryConditions()) { return; } try { ObjectMessage msg = topicSession.createObjectMessage(); if(locationInfo) { event.getLocationInformation(); } msg.setObject(event); topicPublisher.publish(msg); } catch(Exception e) { errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e, ErrorCode.GENERIC_FAILURE); } }
Example #10
Source File: JMSTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public static void publish(String dest, Serializable object, String contentType) throws Exception { Connection conn = connectionFactory.createConnection(); try { Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = createDestination(dest); MessageProducer producer = session.createProducer(destination); ObjectMessage message = session.createObjectMessage(); if (contentType != null) { message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType); } message.setObject(object); producer.send(message); } finally { conn.close(); } }
Example #11
Source File: HandlingEventRegistrationAttemptConsumer.java From dddsample-core with MIT License | 6 votes |
@Override public void onMessage(final Message message) { try { final ObjectMessage om = (ObjectMessage) message; HandlingEventRegistrationAttempt attempt = (HandlingEventRegistrationAttempt) om.getObject(); handlingEventService.registerHandlingEvent( attempt.getCompletionTime(), attempt.getTrackingId(), attempt.getVoyageNumber(), attempt.getUnLocode(), attempt.getType() ); } catch (Exception e) { logger.error(e, e); } }
Example #12
Source File: ObjectMessageClassWhitelistingTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
private void doTestWhiteListedEnclosedClassTest(Connection c, Serializable content) throws Exception { Queue destination = createQueue(getTestName()); c.start(); Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = s.createConsumer(destination); MessageProducer producer = s.createProducer(destination); final ObjectMessage sendMessage = s.createObjectMessage(); sendMessage.setObject(content); producer.send(sendMessage); Message receivedMessage = consumer.receive(getReceiveTimeout()); assertNotNull("did not receive message within receive timeout", receivedMessage); assertTrue("message is of wrong type", receivedMessage instanceof ObjectMessage); Object receivedObject = ((ObjectMessage) receivedMessage).getObject(); assertEquals("Received object has unexpected class", content.getClass(), receivedObject.getClass()); assertEquals("Received object has unexpected content", content, receivedObject); }
Example #13
Source File: TriggerQueueServiceBean.java From development with Apache License 2.0 | 6 votes |
private void sendObjectMsgSingleSession(List<? extends Serializable> objectsToSend) throws JMSException { Session session = null; Connection conn = null; try { conn = qFactory.createConnection(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(queue); for (Serializable objectToSend : objectsToSend) { ObjectMessage msg = session.createObjectMessage(); msg.setObject(objectToSend); producer.send(msg); } } finally { closeSession(session); closeConnection(conn); } }
Example #14
Source File: TestGetJMSQueue.java From localization_nifi with Apache License 2.0 | 6 votes |
@org.junit.Ignore public void testSendObjectToQueue() throws Exception { final TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class); runner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER); runner.setProperty(JmsProperties.URL, "tcp://localhost:61616"); runner.setProperty(JmsProperties.DESTINATION_TYPE, JmsProperties.DESTINATION_TYPE_QUEUE); runner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing"); runner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO); WrappedMessageProducer wrappedProducer = JmsFactory.createMessageProducer(runner.getProcessContext(), true); final Session jmsSession = wrappedProducer.getSession(); final MessageProducer producer = wrappedProducer.getProducer(); // Revision class is used because test just needs any Serializable class in core NiFi final ObjectMessage message = jmsSession.createObjectMessage(new Revision(1L, "ID", "COMP_ID")); producer.send(message); jmsSession.commit(); producer.close(); jmsSession.close(); }
Example #15
Source File: Step6Test.java From learning with Apache License 2.0 | 6 votes |
@Test public void sendTextMessageToJMSQueue() throws Exception { // Mock the qualify service to verify it's invoked MockHandler qualifyMock = testKit.replaceService("IntakeJMS"); // Create and send a JMS message with the request XML payload MessageProducer producer = hornetQ.getJMSSession().createProducer( HornetQMixIn.getJMSQueue(REQUEST_QUEUE)); ObjectMessage message = hornetQ.getJMSSession().createObjectMessage(); message.setObject(MockApplication.good()); producer.send(message); // Verify that we received the message in the service qualifyMock.waitForOKMessage(); Assert.assertEquals(1, qualifyMock.getMessages().size()); }
Example #16
Source File: TaskListenerTest.java From development with Apache License 2.0 | 6 votes |
@Test public void onMessageErrorHandlingFailed() throws Exception { // given PayloadStub payload = new PayloadStub(); payload.setExecuteCauseException(true); payload.setHandleErrorCauseException(true); TaskMessage taskMessage = new TaskMessage(HandlerStub.class, payload); ObjectMessage messageMock = mock(ObjectMessage.class); when(messageMock.getObject()).thenReturn(taskMessage); // when listener.onMessage(messageMock); // then assertTrue(payload.isExecuted()); assertFalse(payload.isExecutedSuccessfully()); assertTrue(payload.isErrorHandled()); assertFalse(payload.isHandledErrorSuccessfully()); }
Example #17
Source File: RiksdagenApiAgentWorkConsumerImplITest.java From cia with Apache License 2.0 | 5 votes |
/** * On message failure test. * * @throws JMSException * the JMS exception */ @Test public void onMessageFailureTest() throws JMSException { final ObjectMessage message = mock(ObjectMessage.class); when(message.getObject()).thenThrow(new JMSException("test")); messsageListener.onMessage(message); verify(message, atLeastOnce()).getObject(); }
Example #18
Source File: RiksdagenDocumentElementWorkConsumerImplITest.java From cia with Apache License 2.0 | 5 votes |
/** * On message success test. * * @throws JMSException * the JMS exception */ @Test @Transactional public void onMessageSuccessTest() throws JMSException { final ObjectMessage message = mock(ObjectMessage.class); when(message.getObject()).thenReturn(new DocumentElement().withId("2a6fd34d-969f-48b5-b472-363ee61cdb96")); messsageListener.onMessage(message); verify(message, atLeastOnce()).getObject(); }
Example #19
Source File: ObjectMessageTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Test public void sendEmptyObjectMessage() throws Exception { Queue queue = createQueue(getTestName()); Connection connection = getConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); ObjectMessage testMessage = session.createObjectMessage(); MessageProducer producer = session.createProducer(queue); producer.send(testMessage); MessageConsumer consumer = session.createConsumer(queue); connection.start(); Message receivedMessage = consumer.receive(getReceiveTimeout()); assertTrue("ObjectMessage should be received", receivedMessage instanceof ObjectMessage); Object result = ((ObjectMessage) receivedMessage).getObject(); assertEquals("First read: unexpected object received", null, result); result = ((ObjectMessage) receivedMessage).getObject(); assertEquals("Second read: unexpected object received", null, result); } finally { connection.close(); } }
Example #20
Source File: RiksdagenVoteDataWorkConsumerImplITest.java From cia with Apache License 2.0 | 5 votes |
/** * On message failure test. * * @throws JMSException * the JMS exception */ @Test public void onMessageFailureTest() throws JMSException { final ObjectMessage message = mock(ObjectMessage.class); when(message.getObject()).thenThrow(new JMSException("test")); messsageListener.onMessage(message); verify(message, atLeastOnce()).getObject(); }
Example #21
Source File: RiksdagenCommitteeProposalComponentDataWorkConsumerImplITest.java From cia with Apache License 2.0 | 5 votes |
/** * On message failure test. * * @throws JMSException * the JMS exception */ @Test public void onMessageFailureTest() throws JMSException { final ObjectMessage message = mock(ObjectMessage.class); when(message.getObject()).thenThrow(new JMSException("test")); messsageListener.onMessage(message); verify(message, atLeastOnce()).getObject(); }
Example #22
Source File: ActiveMQRASession.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Create an object message * * @param object The object * @return The message * @throws JMSException Thrown if an error occurs */ @Override public ObjectMessage createObjectMessage(final Serializable object) throws JMSException { Session session = getSessionInternal(); if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("createObjectMessage(" + object + ")" + session); } return session.createObjectMessage(object); }
Example #23
Source File: WorldbankIndicatorElementWorkConsumerImplITest.java From cia with Apache License 2.0 | 5 votes |
/** * On message success test. * * @throws JMSException * the JMS exception */ @Test @Transactional public void onMessageSuccessTest() throws JMSException { final ObjectMessage message = mock(ObjectMessage.class); when(message.getObject()).thenReturn(new IndicatorElement()); messsageListener.onMessage(message); verify(message, atLeastOnce()).getObject(); }
Example #24
Source File: MockJMSProducer.java From pooled-jms with Apache License 2.0 | 5 votes |
@Override public JMSProducer send(Destination destination, Serializable body) { try { ObjectMessage message = session.createObjectMessage(); message.setObject(body); doSend(destination, message); } catch (JMSException jmse) { throw JMSExceptionSupport.createRuntimeException(jmse); } return this; }
Example #25
Source File: MockJMSContext.java From pooled-jms with Apache License 2.0 | 5 votes |
@Override public ObjectMessage createObjectMessage(Serializable object) { try { return getSession().createObjectMessage(object); } catch (JMSException jmse) { throw JMSExceptionSupport.createRuntimeException(jmse); } }
Example #26
Source File: ActiveMQConnectionFactoryTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void sendObjectMessage(String qname, Serializable obj) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://0"); Connection connection = factory.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue q = session.createQueue(qname); MessageProducer producer = session.createProducer(q); ObjectMessage objMessage = session.createObjectMessage(); objMessage.setObject(obj); producer.send(objMessage); } finally { connection.close(); } }
Example #27
Source File: JmsProducer.java From qpid-jms with Apache License 2.0 | 5 votes |
@Override public JMSProducer send(Destination destination, Serializable body) { try { ObjectMessage message = session.createObjectMessage(); message.setObject(body); doSend(destination, message); } catch (JMSException jmse) { throw JmsExceptionSupport.createRuntimeException(jmse); } return this; }
Example #28
Source File: RiksdagenDocumentStatusContainerWorkConsumerImplITest.java From cia with Apache License 2.0 | 5 votes |
/** * On message failure test. * * @throws JMSException * the JMS exception */ @Test public void onMessageFailureTest() throws JMSException { final ObjectMessage message = mock(ObjectMessage.class); when(message.getObject()).thenThrow(new JMSException("test")); messsageListener.onMessage(message); verify(message, atLeastOnce()).getObject(); }
Example #29
Source File: JmsPoolJMSContext.java From pooled-jms with Apache License 2.0 | 5 votes |
@Override public ObjectMessage createObjectMessage() { try { return getSession().createObjectMessage(); } catch (JMSException jmse) { throw JMSExceptionSupport.createRuntimeException(jmse); } }
Example #30
Source File: RiksdagenDocumentContentWorkConsumerImplITest.java From cia with Apache License 2.0 | 5 votes |
/** * On message failure test. * * @throws JMSException * the JMS exception */ @Test public void onMessageFailureTest() throws JMSException { final ObjectMessage message = mock(ObjectMessage.class); when(message.getObject()).thenThrow(new JMSException("test")); messsageListener.onMessage(message); verify(message, atLeastOnce()).getObject(); }