List of usage examples for javax.jms TextMessage getJMSCorrelationID
String getJMSCorrelationID() throws JMSException;
From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java
public void testJmsCorrelationIdToAdaptrisMessageMetadata() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); JmsConnection conn = broker.getJmsConnection(); try {// w w w . j av a 2 s .c o m broker.start(); start(conn); Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); TextMessage jmsMsg = session.createTextMessage(); jmsMsg.setJMSCorrelationID(TEXT2); MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY); mcs.processCorrelationId(jmsMsg, adpMsg); assertEquals("Check Correlation Id Keys", jmsMsg.getJMSCorrelationID(), adpMsg.getMetadataValue(CORRELATIONID_KEY)); session.close(); } finally { stop(conn); broker.destroy(); } }
From source file:com.solveapuzzle.mapping.agnostic.JmsMessageListener.java
/** * Implementation of <code>MessageListener</code>. *///from ww w .ja v a 2 s.c o m public void onMessage(Message message) { try { int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT); logger.info("Processed message '{}'. value={}", message, messageCount); counter.incrementAndGet(); if (message instanceof TextMessage) { TextMessage tm = (TextMessage) message; String msg = tm.getText(); logger.info(" Read Transform property " + message.getStringProperty(TRANSFORM)); try { String parser = tm.getStringProperty(PARSER); String key = tm.getStringProperty(TRANSFORM); logger.info(" Read Transform propertys " + parser + " " + key); String response = engine.onTransformEvent(this.createConfig(parser, key), tm.getText(), Charset.defaultCharset()); logger.info(" Response " + response); logger.info("message ReplyTo ID " + tm.getJMSCorrelationID()); tm.setJMSDestination(this.outDestination); javax.jms.Queue queue = (javax.jms.Queue) tm.getJMSDestination(); logger.info("ReplyTo Queue name = " + queue.getQueueName()); tm.clearBody(); tm.setText(response); // Push to response queue } catch (MappingException e) { logger.error("Mapping exception from transformation ", e); // push to mapping error Queue? // May be fixable with input xml change or due to data quality, invalid against schema throw new RuntimeException(e); } catch (ConfigurationException e) { logger.error("Configuration exception from transformation", e); // Can't fix - dead letter queue - but worth tracing what config went missing? throw new RuntimeException(e); } } } catch (JMSException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
From source file:nl.nn.adapterframework.extensions.tibco.SendTibcoMessage.java
public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException { Connection connection = null; Session jSession = null;//from w w w .ja va 2 s . c o m MessageProducer msgProducer = null; Destination destination = null; String url_work; String authAlias_work; String userName_work; String password_work; String queueName_work; String messageProtocol_work; int replyTimeout_work; String soapAction_work; String result = null; ParameterValueList pvl = null; if (getParameterList() != null) { ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session); try { pvl = prc.getValues(getParameterList()); } catch (ParameterException e) { throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e); } } url_work = getParameterValue(pvl, "url"); if (url_work == null) { url_work = getUrl(); } authAlias_work = getParameterValue(pvl, "authAlias"); if (authAlias_work == null) { authAlias_work = getAuthAlias(); } userName_work = getParameterValue(pvl, "userName"); if (userName_work == null) { userName_work = getUserName(); } password_work = getParameterValue(pvl, "password"); if (password_work == null) { password_work = getPassword(); } queueName_work = getParameterValue(pvl, "queueName"); if (queueName_work == null) { queueName_work = getQueueName(); } messageProtocol_work = getParameterValue(pvl, "messageProtocol"); if (messageProtocol_work == null) { messageProtocol_work = getMessageProtocol(); } String replyTimeout_work_str = getParameterValue(pvl, "replyTimeout"); if (replyTimeout_work_str == null) { replyTimeout_work = getReplyTimeout(); } else { replyTimeout_work = Integer.parseInt(replyTimeout_work_str); } soapAction_work = getParameterValue(pvl, "soapAction"); if (soapAction_work == null) soapAction_work = getSoapAction(); if (StringUtils.isEmpty(soapAction_work) && !StringUtils.isEmpty(queueName_work)) { String[] q = queueName_work.split("\\."); if (q.length > 0) { if (q[0].equalsIgnoreCase("P2P") && q.length >= 4) { soapAction_work = q[3]; } else if (q[0].equalsIgnoreCase("ESB") && q.length == 8) { soapAction_work = q[5] + "_" + q[6]; } else if (q[0].equalsIgnoreCase("ESB") && q.length > 8) { soapAction_work = q[6] + "_" + q[7]; } } } if (StringUtils.isEmpty(soapAction_work)) { log.debug(getLogPrefix(session) + "deriving default soapAction"); try { URL resource = ClassUtils.getResourceURL(this, "/xml/xsl/esb/soapAction.xsl"); TransformerPool tp = new TransformerPool(resource, true); soapAction_work = tp.transform(input.toString(), null); } catch (Exception e) { log.error(getLogPrefix(session) + "failed to execute soapAction.xsl"); } } if (messageProtocol_work == null) { throw new PipeRunException(this, getLogPrefix(session) + "messageProtocol must be set"); } if (!messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY) && !messageProtocol_work.equalsIgnoreCase(FIRE_AND_FORGET)) { throw new PipeRunException(this, getLogPrefix(session) + "illegal value for messageProtocol [" + messageProtocol_work + "], must be '" + REQUEST_REPLY + "' or '" + FIRE_AND_FORGET + "'"); } CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work); try { TibjmsAdmin admin; try { admin = TibcoUtils.getActiveServerAdmin(url_work, cf); } catch (TibjmsAdminException e) { log.debug(getLogPrefix(session) + "caught exception", e); admin = null; } if (admin != null) { QueueInfo queueInfo; try { queueInfo = admin.getQueue(queueName_work); } catch (Exception e) { throw new PipeRunException(this, getLogPrefix(session) + " exception on getting queue info", e); } if (queueInfo == null) { throw new PipeRunException(this, getLogPrefix(session) + " queue [" + queueName_work + "] does not exist"); } try { admin.close(); } catch (TibjmsAdminException e) { log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e); } } ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(url_work); connection = factory.createConnection(cf.getUsername(), cf.getPassword()); jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); destination = jSession.createQueue(queueName_work); msgProducer = jSession.createProducer(destination); TextMessage msg = jSession.createTextMessage(); msg.setText(input.toString()); Destination replyQueue = null; if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) { replyQueue = jSession.createTemporaryQueue(); msg.setJMSReplyTo(replyQueue); msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); msgProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); msgProducer.setTimeToLive(replyTimeout_work); } else { msg.setJMSDeliveryMode(DeliveryMode.PERSISTENT); msgProducer.setDeliveryMode(DeliveryMode.PERSISTENT); } if (StringUtils.isNotEmpty(soapAction_work)) { log.debug( getLogPrefix(session) + "setting [SoapAction] property to value [" + soapAction_work + "]"); msg.setStringProperty("SoapAction", soapAction_work); } msgProducer.send(msg); if (log.isDebugEnabled()) { log.debug(getLogPrefix(session) + "sent message [" + msg.getText() + "] " + "to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]"); } else { if (log.isInfoEnabled()) { log.info(getLogPrefix(session) + "sent message to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]"); } } if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) { String replyCorrelationId = msg.getJMSMessageID(); MessageConsumer msgConsumer = jSession.createConsumer(replyQueue, "JMSCorrelationID='" + replyCorrelationId + "'"); log.debug(getLogPrefix(session) + "] start waiting for reply on [" + replyQueue + "] selector [" + replyCorrelationId + "] for [" + replyTimeout_work + "] ms"); try { connection.start(); Message rawReplyMsg = msgConsumer.receive(replyTimeout_work); if (rawReplyMsg == null) { throw new PipeRunException(this, getLogPrefix(session) + "did not receive reply on [" + replyQueue + "] replyCorrelationId [" + replyCorrelationId + "] within [" + replyTimeout_work + "] ms"); } TextMessage replyMsg = (TextMessage) rawReplyMsg; result = replyMsg.getText(); } finally { } } else { result = msg.getJMSMessageID(); } } catch (JMSException e) { throw new PipeRunException(this, getLogPrefix(session) + " exception on sending message to Tibco queue", e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { log.warn(getLogPrefix(session) + "exception on closing connection", e); } } } return result; }
From source file:org.codehaus.stomp.StompTest.java
public void testSendMessageWithStandardHeaders() throws Exception { MessageConsumer consumer = session.createConsumer(queue); String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL; sendFrame(frame);/* ww w.j av a 2 s. c om*/ frame = receiveFrame(10000); Assert.assertTrue(frame.startsWith("CONNECTED")); frame = "SEND\n" + "correlation-id:c123\n" + "priority:3\n" + "type:t345\n" + "JMSXGroupID:abc\n" + "foo:abc\n" + "bar:123\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World" + Stomp.NULL; sendFrame(frame); TextMessage message = (TextMessage) consumer.receive(1000); Assert.assertNotNull(message); Assert.assertEquals("Hello World", message.getText()); Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID()); Assert.assertEquals("getJMSType", "t345", message.getJMSType()); Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority()); Assert.assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode()); Assert.assertEquals("foo", "abc", message.getStringProperty("foo")); Assert.assertEquals("bar", "123", message.getStringProperty("bar")); Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID")); ActiveMQTextMessage amqMessage = (ActiveMQTextMessage) message; Assert.assertEquals("GroupID", "abc", amqMessage.getGroupID()); }
From source file:org.mule.transport.jms.JmsMuleMessageFactoryTestCase.java
@Override protected Object getValidTransportMessage() throws Exception { TextMessage textMessage = mock(TextMessage.class); when(textMessage.getText()).thenReturn(MESSAGE_TEXT); when(textMessage.getJMSCorrelationID()).thenReturn(null); when(textMessage.getJMSDeliveryMode()).thenReturn(Integer.valueOf(1)); when(textMessage.getJMSDestination()).thenReturn(null); when(textMessage.getJMSExpiration()).thenReturn(Long.valueOf(0)); when(textMessage.getJMSMessageID()).thenReturn("1234567890"); when(textMessage.getJMSPriority()).thenReturn(Integer.valueOf(4)); when(textMessage.getJMSRedelivered()).thenReturn(Boolean.FALSE); when(textMessage.getJMSReplyTo()).thenReturn(null); when(textMessage.getJMSTimestamp()).thenReturn(Long.valueOf(0)); when(textMessage.getJMSType()).thenReturn(null); when(textMessage.getPropertyNames()) .thenReturn(IteratorUtils.asEnumeration(IteratorUtils.arrayIterator(new Object[] { "foo" }))); when(textMessage.getObjectProperty("foo")).thenReturn("bar"); return textMessage; }
From source file:org.openengsb.ports.jms.JMSPortTest.java
private String sendWithTempQueue(final String msg) { String resultString = jmsTemplate.execute(new SessionCallback<String>() { @Override/*from w w w . j a va 2s .c o m*/ public String doInJms(Session session) throws JMSException { Queue queue = session.createQueue("receive"); MessageProducer producer = session.createProducer(queue); TemporaryQueue tempQueue = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(tempQueue); TextMessage message = session.createTextMessage(msg); message.setJMSReplyTo(tempQueue); producer.send(message); TextMessage response = (TextMessage) consumer.receive(10000); assertThat( "server should set the value of the correltion ID to the value of the received message id", response.getJMSCorrelationID(), is(message.getJMSMessageID())); JmsUtils.closeMessageProducer(producer); JmsUtils.closeMessageConsumer(consumer); return response != null ? response.getText() : null; } }, true); return resultString; }
From source file:org.oxymores.chronix.engine.Runner.java
private void recvTextMessage(TextMessage tmsg) throws JMSException { String res = tmsg.getText();//from w w w . j a v a 2s . co m String cid = tmsg.getJMSCorrelationID(); String pjid = cid.split("\\|")[0]; String paramid = cid.split("\\|")[1]; // Get the PipelineJob PipelineJob resolvedJob = null; for (PipelineJob pj : this.resolving) { if (pj.getId().toString().equals(pjid)) { resolvedJob = pj; break; } } if (resolvedJob == null) { log.error("received a param resolution for a job that is not in queue - ignored"); return; } // Get the parameter awaiting resolution int paramIndex = -1; ArrayList<Parameter> prms = resolvedJob.getActive(ctx).getParameters(); for (int i = 0; i < prms.size(); i++) { if (prms.get(i).getId().toString().equals(paramid)) { paramIndex = i; break; } } if (paramIndex == -1) { log.error("received a param resolution for a job that has no such parameter - ignored"); return; } // Update the parameter with its value trTransac.begin(); resolvedJob.setParamValue(paramIndex, res); trTransac.commit(); // Perhaps launch the job if (resolvedJob.isReady(ctx)) { this.sendRunDescription(resolvedJob.getRD(ctx), resolvedJob.getPlace(ctx), resolvedJob); } }
From source file:org.wso2.carbon.appfactory.eventing.jms.AFMessageListener.java
@Override public void onMessage(Message message) { if (log.isDebugEnabled()) { if (message instanceof MapMessage) { try { String messageBody = ((MapMessage) message).getString(TopicPublisher.MESSAGE_BODY); log.debug("Received a message:" + messageBody); } catch (JMSException e) { log.error("Error while getting message content.", e); }/*from w ww. java 2 s.c o m*/ } } MapMessage mapMessage; if (message instanceof MapMessage) { mapMessage = (MapMessage) message; MessageStore.getInstance().addMessage(this.subscriptionId, mapMessage); } else if (message instanceof TextMessage) { //Todo:remove this. we only support mapMessages initially and below code is only for testing purpose. final TextMessage textMessage = (TextMessage) message; mapMessage = new MapMessage() { @Override public boolean getBoolean(String s) throws JMSException { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public byte getByte(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public short getShort(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public char getChar(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public int getInt(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public long getLong(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public float getFloat(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public double getDouble(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public String getString(String s) throws JMSException { return textMessage.getText(); } @Override public byte[] getBytes(String s) throws JMSException { return new byte[0]; //To change body of implemented methods use File | Settings | File Templates. } @Override public Object getObject(String s) throws JMSException { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public Enumeration getMapNames() throws JMSException { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public void setBoolean(String s, boolean b) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setByte(String s, byte b) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setShort(String s, short i) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setChar(String s, char c) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setInt(String s, int i) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setLong(String s, long l) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setFloat(String s, float v) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setDouble(String s, double v) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setString(String s, String s2) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setBytes(String s, byte[] bytes) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setBytes(String s, byte[] bytes, int i, int i2) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setObject(String s, Object o) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean itemExists(String s) throws JMSException { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public String getJMSMessageID() throws JMSException { return textMessage.getJMSMessageID(); } @Override public void setJMSMessageID(String s) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public long getJMSTimestamp() throws JMSException { return textMessage.getJMSTimestamp(); } @Override public void setJMSTimestamp(long l) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public byte[] getJMSCorrelationIDAsBytes() throws JMSException { return new byte[0]; //To change body of implemented methods use File | Settings | File Templates. } @Override public void setJMSCorrelationIDAsBytes(byte[] bytes) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setJMSCorrelationID(String s) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public String getJMSCorrelationID() throws JMSException { return textMessage.getJMSCorrelationID(); } @Override public Destination getJMSReplyTo() throws JMSException { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public void setJMSReplyTo(Destination destination) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public Destination getJMSDestination() throws JMSException { return textMessage.getJMSDestination(); } @Override public void setJMSDestination(Destination destination) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public int getJMSDeliveryMode() throws JMSException { return textMessage.getJMSDeliveryMode(); } @Override public void setJMSDeliveryMode(int i) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean getJMSRedelivered() throws JMSException { return textMessage.getJMSRedelivered(); } @Override public void setJMSRedelivered(boolean b) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public String getJMSType() throws JMSException { return textMessage.getJMSType(); } @Override public void setJMSType(String s) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public long getJMSExpiration() throws JMSException { return textMessage.getJMSExpiration(); } @Override public void setJMSExpiration(long l) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public int getJMSPriority() throws JMSException { return textMessage.getJMSPriority(); } @Override public void setJMSPriority(int i) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void clearProperties() throws JMSException { textMessage.clearProperties(); } @Override public boolean propertyExists(String s) throws JMSException { return textMessage.propertyExists(s); } @Override public boolean getBooleanProperty(String s) throws JMSException { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public byte getByteProperty(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public short getShortProperty(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public int getIntProperty(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public long getLongProperty(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public float getFloatProperty(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public double getDoubleProperty(String s) throws JMSException { return 0; //To change body of implemented methods use File | Settings | File Templates. } @Override public String getStringProperty(String s) throws JMSException { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public Object getObjectProperty(String s) throws JMSException { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public Enumeration getPropertyNames() throws JMSException { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public void setBooleanProperty(String s, boolean b) throws JMSException { //To change body of implemented methods use File | Settings | File Templates. } @Override public void setByteProperty(String s, byte b) throws JMSException { textMessage.setByteProperty(s, b); } @Override public void setShortProperty(String s, short i) throws JMSException { textMessage.setShortProperty(s, i); } @Override public void setIntProperty(String s, int i) throws JMSException { textMessage.setIntProperty(s, i); } @Override public void setLongProperty(String s, long l) throws JMSException { textMessage.setLongProperty(s, l); } @Override public void setFloatProperty(String s, float v) throws JMSException { textMessage.setFloatProperty(s, v); } @Override public void setDoubleProperty(String s, double v) throws JMSException { textMessage.setDoubleProperty(s, v); } @Override public void setStringProperty(String s, String s2) throws JMSException { textMessage.setStringProperty(s, s2); } @Override public void setObjectProperty(String s, Object o) throws JMSException { textMessage.setObjectProperty(s, o); } @Override public void acknowledge() throws JMSException { textMessage.acknowledge(); } @Override public void clearBody() throws JMSException { textMessage.clearBody(); } }; MessageStore.getInstance().addMessage(this.subscriptionId, mapMessage); } }