List of usage examples for javax.jms TextMessage getText
String getText() throws JMSException;
From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListenerTest.java
@Test public void a_complete_log_authorization_grant_auth_event_is_saved_to_storage() throws Exception { MonitoringMessageListener mml = new MonitoringMessageListener(); TextMessage message = mock(TextMessage.class); when(message.getText()).thenReturn(createMessagePayLoadForAuthEvent(AuthEventType.AUTHORIZATIONGRANT)); mml.setAuthEventRepository(authEventRepository); mml.onMessage(message);/* w w w .j a va2s.c o m*/ List<AuthEvent> events = authEventRepository.findAll(); assertEquals(1, events.size()); AuthEvent event = events.get(0); assertEquals(AuthEventType.AUTHORIZATIONGRANT, event.getEventType()); assertNotNull("Event timestamp can not be null", event.getTimestamp()); assertEquals(RequestState.SUCCESS, event.getRequestState()); assertNotNull("Message needs to be there", event.getMessage()); assertNotNull("User needs to be there", event.getUser()); assertNotNull("code needs to be there", event.getCode()); assertNotNull("client needs to be there", event.getClient()); assertNotNull("scope needs to be there", event.getScopes()); assertNotNull("requestId needs to be there", event.getRequestId()); }
From source file:de.adorsys.jmspojo.JMSMessageListenerServiceAdapterTest.java
@Test public void testCreateAdapterWithHeaders() throws JMSException { TextMessage textMessage = queueSession.createTextMessage(OBJECT_MAPPER.serialize(new PingMessage("ping"))); textMessage.setJMSReplyTo(reqlayQ);//from ww w . j a v a 2s . co m textMessage.setBooleanProperty("testHeader", true); SampleMessageServiceWithHeaders service = new SampleMessageServiceWithHeaders(); JMSMessageListenerServiceAdapter<SampleMessageServiceWithHeaders> adapter = JMSMessageListenerServiceAdapter .createAdapter(service, cf, OBJECT_MAPPER); adapter.onMessage(textMessage); TextMessage message = (TextMessage) queueSession.createReceiver(reqlayQ).receive(1000); assertNotNull(message); assertNull(message.getStringProperty("ERROR")); assertNull(message.getText()); }
From source file:org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventMessageDelegator.java
@Override public void run() { try {// w w w. ja v a 2s.com if (log.isInfoEnabled()) { log.info("Instance notifier event message delegator started"); } while (!terminated) { try { TextMessage message = messageQueue.take(); // Retrieve the header String type = message.getStringProperty(Constants.EVENT_CLASS_NAME); // Retrieve the actual message String json = message.getText(); if (log.isDebugEnabled()) { log.debug(String.format("Instance notifier event message received from queue: %s", type)); } // Delegate message to message processor chain if (log.isDebugEnabled()) { log.debug(String.format("Delegating instance notifier event message: %s", type)); } processorChain.process(type, json, null); } catch (Exception e) { log.error("Failed to retrieve instance notifier event message", e); } } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Instance notifier event message delegator failed", e); } } }
From source file:org.apache.stratos.messaging.message.receiver.tenant.TenantEventMessageDelegator.java
@Override public void run() { try {/*from w w w. j a v a 2s .c o m*/ if (log.isInfoEnabled()) { log.info("Tenant event message delegator started"); } while (!terminated) { try { TextMessage message = messageQueue.take(); // Retrieve the header String type = message.getStringProperty(Constants.EVENT_CLASS_NAME); // Retrieve the actual message String json = message.getText(); if (log.isDebugEnabled()) { log.debug(String.format("Tenant event message received from queue: %s", type)); } // Delegate message to message processor chain if (log.isDebugEnabled()) { log.debug(String.format("Delegating tenant event message: %s", type)); } processorChain.process(type, json, null); } catch (Exception e) { log.error("Failed to retrieve tenant event message", e); } } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Tenant event message delegator failed", e); } } }
From source file:org.apache.servicemix.jms.JmsMarshalerTest.java
public void testEncoding() throws Exception { JmsEndpoint ep = new JmsEndpoint(); ep.setService(ReceiverComponent.SERVICE); ep.setEndpoint("jms"); ep.setTargetService(ReceiverComponent.SERVICE); ep.setTargetEndpoint(ReceiverComponent.ENDPOINT); ep.setRole(MessageExchange.Role.CONSUMER); ep.setDestinationStyle(AbstractJmsProcessor.STYLE_QUEUE); ep.setDestination(queue);/*from www . j av a 2 s. com*/ ep.setDefaultMep(JbiConstants.IN_ONLY); ep.setMarshaler(new DefaultJmsMarshaler(ep)); QueueConnection qConn = connectionFactory.createQueueConnection(); QueueSession qSess = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // Test character encoding. String defaultCharset = SourceTransformer.getDefaultCharset(); try { SourceTransformer.setDefaultCharset("ISO-8859-1"); SourceTransformer sourceTransformer = new SourceTransformer(); SoapMarshaler marshaler = new SoapMarshaler(true); SoapMessage soapMessage = marshaler.createReader() .read(getClass().getResourceAsStream("charsettest.xml")); soapMessage.setHeaders(null); soapMessage.setBodyName(null); soapMessage.setEnvelopeName(null); soapMessage.setSource(sourceTransformer.toDOMSource(soapMessage.getSource())); TextMessage m = (TextMessage) ep.getMarshaler().toJMS(soapMessage, null, qSess); assertEquals("Messages match", new SourceTransformer().toString(soapMessage.getSource()), m.getText().replace('\'', '"')); } finally { SourceTransformer.setDefaultCharset(defaultCharset); } }
From source file:com.linagora.obm.sync.TestQueueManager.java
@Test public void testSimple() throws Exception { String testText = "test text"; Connection connection = createManagedConnection(); connection.start();/* w ww . j a va2s .com*/ Session consumerSession = createManagedSession(connection); MessageConsumer consumer = queueManager.createConsumerOnTopic(consumerSession, TOPIC); writeMessageOnTopic(testText, TOPIC, queueManager); TextMessage messageReceived = (TextMessage) consumer.receive(TIMEOUT); Assert.assertEquals(testText, messageReceived.getText()); }
From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListenerTest.java
@Test public void a_complete_log_request_resource_event_is_saved_to_storage() throws Exception { MonitoringMessageListener mml = new MonitoringMessageListener(); TextMessage message = mock(TextMessage.class); when(message.getText()).thenReturn(createMessagePayLoadForResourceEvent(ResourceEventType.LOGREQUEST)); mml.setResourceEventRepository(resourceEventRepository); mml.onMessage(message);/* www . j av a 2 s.c o m*/ List<ResourceEvent> events = resourceEventRepository.findAll(); assertEquals(1, events.size()); ResourceEvent event = events.get(0); assertEquals(ResourceEventType.LOGREQUEST, event.getEventType()); assertNotNull("Event timestamp can not be null", event.getTimestamp()); assertNotNull("Must have a CorrelationId", event.getCorrelationId()); assertNotNull("Resource needs to be there", event.getResource()); assertNotNull("Method needs to be there", event.getMethod()); assertNotNull("Request needs to be there", event.getRequest()); assertNotNull("Logical address needs to be there", event.getLogicalAddress()); assertEquals(RequestState.SUCCESS, event.getRequestState()); assertNotNull("Message needs to be there", event.getMessage()); assertNotNull("Client needs to be there", event.getClient()); assertNotNull("User needs to be there", event.getUser()); assertNotNull("Scopes needs to be there", event.getScopes()); }
From source file:com.linagora.obm.sync.TestQueueManager.java
@Test public void testDurableSubscription() throws Exception { String testText = "test text"; String clientId = "c1"; Connection connection = queueManager.createConnection(); connection.setClientID(clientId);//from w w w . jav a 2s. c o m connection.start(); Session consumerSession = queueManager.createSession(connection); MessageConsumer consumer = queueManager.createDurableConsumerOnTopic(consumerSession, TOPIC, clientId); consumerSession.close(); connection.close(); writeMessageOnTopic(testText, TOPIC, queueManager); Connection connection2 = createManagedConnection(); connection2.setClientID(clientId); connection2.start(); consumerSession = queueManager.createSession(connection2); consumer = queueManager.createDurableConsumerOnTopic(consumerSession, TOPIC, clientId); TextMessage messageReceived = (TextMessage) consumer.receive(TIMEOUT); Assert.assertEquals(testText, messageReceived.getText()); }
From source file:com.linagora.obm.sync.TestQueueManager.java
@Test public void testDurableSubscription2() throws Exception { String testText = "test text"; String clientId = "c1"; Connection connection = createManagedConnection(); connection.setClientID(clientId);//w w w . j a v a 2 s . co m connection.start(); Session consumerSession = createManagedSession(connection); MessageConsumer consumer = queueManager.createDurableConsumerOnTopic(consumerSession, TOPIC, clientId); writeMessageOnTopic(testText, TOPIC, queueManager); shutdownQueueManager(); startQueueManager(); Connection connection2 = createManagedConnection(); connection2.setClientID(clientId); connection2.start(); consumerSession = createManagedSession(connection2); consumer = queueManager.createDurableConsumerOnTopic(consumerSession, TOPIC, clientId); TextMessage messageReceived = (TextMessage) consumer.receive(TIMEOUT); Assert.assertEquals(testText, messageReceived.getText()); }
From source file:org.apache.stratos.messaging.message.receiver.topology.TopologyEventMessageDelegator.java
@Override public void run() { try {// w w w. j a v a 2 s .c o m if (log.isInfoEnabled()) { log.info("Topology event message delegator started"); } while (!terminated) { try { TextMessage message = messageQueue.take(); // Retrieve the header String type = message.getStringProperty(Constants.EVENT_CLASS_NAME); // Retrieve the actual message String json = message.getText(); if (log.isDebugEnabled()) { log.debug(String.format("Topology event message [%s] received from queue: %s", type, messageQueue.getClass())); } try { TopologyManager.acquireWriteLock(); if (log.isDebugEnabled()) { log.debug(String.format("Delegating topology event message: %s", type)); } processorChain.process(type, json, TopologyManager.getTopology()); } finally { TopologyManager.releaseWriteLock(); } } catch (Exception e) { log.error("Failed to retrieve topology event message", e); } } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Topology event message delegator failed", e); } } }