List of usage examples for javax.jms TextMessage getText
String getText() throws JMSException;
From source file:com.oneops.controller.jms.CmsListenerTest.java
@Test public void msgDeployment() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty("source")).thenReturn("deployment"); String msgJson = gson.toJson(createCmsDeployment("active")); when(message.getText()).thenReturn(msgJson); listener.onMessage(message);//from w ww. j av a2 s .c om //once more to get a SKIP when(message.getText()).thenReturn(gson.toJson(createCmsDeployment("is-not-active"))); listener.onMessage(message); listener.cleanup(); listener.getConnectionStats(); }
From source file:org.apache.servicemix.jms.JMSComponentTest.java
public void testConsumerInOut() throws Exception { // JMS Component JmsComponent component = new JmsComponent(); container.activateComponent(component, "JMSComponent"); // Add an echo component EchoComponent echo = new EchoComponent(); ActivationSpec asEcho = new ActivationSpec("receiver", echo); asEcho.setService(new QName("http://jms.servicemix.org/Test", "Echo")); container.activateComponent(asEcho); // Deploy Consumer SU URL url = getClass().getClassLoader().getResource("consumer/jms.wsdl"); File path = new File(new URI(url.toString())); path = path.getParentFile();//from w ww .ja v a 2s.co m component.getServiceUnitManager().deploy("consumer", path.getAbsolutePath()); component.getServiceUnitManager().init("consumer", path.getAbsolutePath()); component.getServiceUnitManager().start("consumer"); // Send test message jmsTemplate.setDefaultDestinationName("queue/A"); jmsTemplate.afterPropertiesSet(); jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { Message m = session.createTextMessage("<hello>world</hello>"); m.setJMSReplyTo(session.createQueue("queue/B")); return m; } }); // Receive echo message TextMessage reply = (TextMessage) jmsTemplate.receive("queue/B"); assertNotNull(reply); logger.info(reply.getText()); }
From source file:com.amalto.core.storage.task.staging.ClusteredStagingTaskManagerTestCase.java
@Test public void testReceiveEmptyMessage() throws Exception { TextMessage message = Mockito.mock(TextMessage.class); Mockito.when(message.getText()).thenReturn(StringUtils.EMPTY); taskManager.onMessage(message);/*from w w w . j a v a 2s .c o m*/ Mockito.verifyNoMoreInteractions(this.repository); this.internalListener.assertNoMessageSent(); }
From source file:com.amalto.core.storage.task.staging.ClusteredStagingTaskManagerTestCase.java
@Test public void testReceiveUnparsableTextMessage() throws Exception { TextMessage message = Mockito.mock(TextMessage.class); Mockito.when(message.getText()).thenReturn("THIS IS NOT XML"); taskManager.onMessage(message);// ww w . ja v a 2 s .com Mockito.verifyNoMoreInteractions(this.repository); this.internalListener.assertNoMessageSent(); }
From source file:com.amalto.core.storage.task.staging.ClusteredStagingTaskManagerTestCase.java
@Test(expected = RuntimeException.class) public void testExceptionWhenReadingMessage() throws Exception { TextMessage message = Mockito.mock(TextMessage.class); Mockito.when(message.getText()).thenThrow(new JMSException("")); taskManager.onMessage(message);//w ww .ja v a 2 s . c o m Mockito.verifyNoMoreInteractions(this.repository); this.internalListener.assertNoMessageSent(); }
From source file:com.amalto.core.storage.task.staging.ClusteredStagingTaskManagerTestCase.java
@Test public void testReceiveMessageForUnknownTask() throws Exception { TextMessage message = Mockito.mock(TextMessage.class); Mockito.when(message.getText()).thenReturn( "<?xml version=\"1.0\"?><stagingJobCancellationMessage><dataContainer>container</dataContainer><taskId>1234</taskId></stagingJobCancellationMessage>"); taskManager.onMessage(message);//from ww w . ja va 2s . c o m Mockito.verifyNoMoreInteractions(this.repository); this.internalListener.assertNoMessageSent(); }
From source file:com.amalto.core.storage.task.staging.ClusteredStagingTaskManagerTestCase.java
@Test public void testReceiveMessageForLocalTask() throws Exception { String container = "container"; String taskId = "ABCD"; long startDate = System.currentTimeMillis(); StagingTask task = createTask(container, taskId, startDate); taskManager.taskStarted(task);// w w w.java2 s. com TextMessage message = Mockito.mock(TextMessage.class); Mockito.when(message.getText()) .thenReturn("<?xml version=\"1.0\"?><stagingJobCancellationMessage><dataContainer>" + container + "</dataContainer><taskId>" + taskId + "</taskId></stagingJobCancellationMessage>"); taskManager.onMessage(message); Mockito.verify(task).cancel(); this.internalListener.assertNoMessageSent(); }
From source file:Requestor.java
/** Create JMS client for sending messages. */ private void start(String broker, String username, String password, String sQueue) { // Create a connection. try {/*from w w w .jav a2s . c o m*/ javax.jms.QueueConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createQueueConnection(username, password); session = connect.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create the Queue and QueueRequestor for sending requests. javax.jms.Queue queue = null; try { queue = session.createQueue(sQueue); requestor = new javax.jms.QueueRequestor(session, queue); // Now that all setup is complete, start the Connection. connect.start(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); exit(); } try { // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); System.out.println("\nRequestor application:\n" + "============================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application uses a QueueRequestor to on the " + DEFAULT_QUEUE + " queue." + "The Replier application gets the message, and transforms it." + "The Requestor application displays the result.\n\n" + "Type some mixed case text, and then press Enter to make a request.\n"); while (true) { String s = stdin.readLine(); if (s == null) exit(); else if (s.length() > 0) { javax.jms.TextMessage msg = session.createTextMessage(); msg.setText(username + ": " + s); // Instead of sending, we will use the QueueRequestor. javax.jms.Message response = requestor.request(msg); // The message should be a TextMessage. Just report it. javax.jms.TextMessage textMessage = (javax.jms.TextMessage) response; System.out.println("[Reply] " + textMessage.getText()); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } }
From source file:de.slub.fedora.jms.MessageMapperTest.java
@Test public void returnsIndexJobForIngestMessage() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty(eq("pid"))).thenReturn("test-rest:1"); when(message.getStringProperty(eq("methodName"))).thenReturn("ingest"); when(message.getText()).thenReturn(getContent("/jms/ingest.xml")); IndexJob ij = findFirstByClass(MessageMapper.map(message), ObjectIndexJob.class); assertEquals(new ObjectIndexJob(IndexJob.Type.CREATE, "test-rest:1"), ij); }
From source file:org.dawnsci.commandserver.core.producer.AliveConsumer.java
protected void createTerminateListener() throws Exception { ConnectionFactory connectionFactory = ConnectionFactoryFacade.createConnectionFactory(uri); this.terminateConnection = connectionFactory.createConnection(); terminateConnection.start();/*from ww w . j a v a 2s. co m*/ Session session = terminateConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); final Topic topic = session.createTopic(Constants.TERMINATE_CONSUMER_TOPIC); final MessageConsumer consumer = session.createConsumer(topic); final ObjectMapper mapper = new ObjectMapper(); MessageListener listener = new MessageListener() { public void onMessage(Message message) { try { if (message instanceof TextMessage) { TextMessage t = (TextMessage) message; final ConsumerBean bean = mapper.readValue(t.getText(), ConsumerBean.class); if (bean.getStatus().isFinal()) { // Something else already happened terminateConnection.close(); return; } if (consumerId.equals(bean.getConsumerId())) { if (bean.getStatus() == ConsumerStatus.REQUEST_TERMINATE) { System.out.println(getName() + " has been requested to terminate and will exit."); cbean.setStatus(ConsumerStatus.REQUEST_TERMINATE); Thread.currentThread().sleep(2500); System.exit(0); } } } } catch (Exception e) { e.printStackTrace(); } } }; consumer.setMessageListener(listener); }