List of usage examples for javax.jms Message getJMSDestination
Destination getJMSDestination() throws JMSException;
From source file:eu.semaine.jms.JMSLogReader.java
@Override public void onMessage(Message m) { try {//from w w w .j a v a2 s.c o m if (!(m instanceof TextMessage)) { return; // silently ignore } String dest = m.getJMSDestination().toString(); // dest is expected to have the form // semaine.log.component.log-level String[] parts = dest.split("\\."); String level = parts[parts.length - 1].toLowerCase(); String component = parts[parts.length - 2]; Log log = LogFactory.getLog("semaine.log." + component); String text = ((TextMessage) m).getText(); //text = time.format(new Date(m.getJMSTimestamp())) + " " + text; if (level.equals("info")) log.info(text); else if (level.equals("warn")) log.warn(text); else if (level.equals("error")) log.error(text); else if (level.equals("debug")) log.debug(text); else log.info(text); } catch (Exception e) { } }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java
private static String formatHeaders(Message message) { Destination dest = null;//from w w w . j a v a2 s . co m int delMode = 0; long expiration = 0; Time expTime = null; int priority = 0; String msgID = null; long timestamp = 0; Time timestampTime = null; String correlID = null; Destination replyTo = null; boolean redelivered = false; String type = null; StringBuilder sb = new StringBuilder(); try { try { dest = message.getJMSDestination(); sb.append(" JMSDestination: "); sb.append(dest); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDestination header\n", e); } try { delMode = message.getJMSDeliveryMode(); if (delMode == DeliveryMode.NON_PERSISTENT) { sb.append(" JMSDeliveryMode: non-persistent\n"); } else if (delMode == DeliveryMode.PERSISTENT) { sb.append(" JMSDeliveryMode: persistent\n"); } else { sb.append(" JMSDeliveryMode: neither persistent nor non-persistent; error\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDeliveryMode header\n", e); } try { expiration = message.getJMSExpiration(); if (expiration != 0) { expTime = new Time(expiration); sb.append(" JMSExpiration: "); sb.append(expTime); sb.append("\n"); } else { sb.append(" JMSExpiration: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSExpiration header\n", e); } try { priority = message.getJMSPriority(); sb.append(" JMSPriority: "); sb.append(priority); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSPriority header\n", e); } try { msgID = message.getJMSMessageID(); sb.append(" JMSMessageID: "); sb.append(msgID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSMessageID header\n", e); } try { timestamp = message.getJMSTimestamp(); if (timestamp != 0) { timestampTime = new Time(timestamp); sb.append(" JMSTimestamp: "); sb.append(timestampTime); sb.append("\n"); } else { sb.append(" JMSTimestamp: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSTimestamp header\n", e); } try { correlID = message.getJMSCorrelationID(); sb.append(" JMSCorrelationID: "); sb.append(correlID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSCorrelationID header\n", e); } try { replyTo = message.getJMSReplyTo(); sb.append(" JMSReplyTo: "); sb.append(replyTo); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSReplyTo header\n", e); } try { redelivered = message.getJMSRedelivered(); sb.append(" JMSRedelivered: "); sb.append(redelivered); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSRedelivered header\n", e); } try { type = message.getJMSType(); sb.append(" JMSType: "); sb.append(type); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSType header\n", e); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMS headers\n", e); } return sb.toString(); }
From source file:com.cognifide.aet.runner.distribution.RunnerMessageListener.java
private void processTestSuite(Message wrapperMessage, TaskMessage message) { Suite suite = (Suite) message.getData(); try {//from w w w . j ava 2 s. c om boolean isMaintenanceMessage = StringUtils.endsWith(wrapperMessage.getJMSDestination().toString(), maintenanceDestinationName); testRunProcessor.process(suite, wrapperMessage.getJMSReplyTo(), isMaintenanceMessage); } catch (JMSException e) { LOGGER.error("Error wile processing RUN {}: ", suite.getCorrelationId(), e); sendFatalMessage(wrapperMessage, e.getMessage()); } catch (StorageException e) { LOGGER.error("Failed to process test suite", e); sendFatalMessage(wrapperMessage, e.getMessage()); } }
From source file:hermes.store.schema.DefaultJDBCAdapter.java
public void insert(Connection connection, String storeId, Message message) throws SQLException, JMSException { final String destinationName = message.getJMSDestination() == null ? "default" : JMSUtils.getDestinationName(message.getJMSDestination()); final Domain domain = message.getJMSDestination() == null ? Domain.QUEUE : Domain.getDomain(message.getJMSDestination()); final String messageAsXMLString = xmlHelper.toXML(message); final InputStream messageAsXML = new StringInputStream(messageAsXMLString); final String messageId = getNextMessageId(storeId); ///*ww w . j av a 2s . co m*/ // DBUtils does not seem to correctly deal with CLOBS, so we have to use // normal JDBC... // // runner.update(connection, "insert into messages values (?, ?)", new // Object[] { message.getJMSMessageID(), messageAsXML }); final PreparedStatement pstmt = connection.prepareStatement("insert into messages values (?, ?)"); pstmt.setString(1, messageId); pstmt.setAsciiStream(2, messageAsXML, messageAsXMLString.length()); pstmt.execute(); pstmt.close(); final QueryRunner runner = new QueryRunner(); runner.update(connection, "insert into stores values (?, ?, ?, ?)", new Object[] { storeId, destinationName, domain.getId(), messageId }); }
From source file:hermes.store.SingleUserMessageStore.java
@Override public void update(Message message) throws Exception { final Connection connection = getWriterConnection(); final Destination destination = createStoreDestination(message.getJMSDestination()); try {//w w w. ja v a2 s. c o m adapter.update(connection, getId(), message); for (final MessageStoreListener l : listeners) { l.onMessageChanged(message); } } catch (SQLException ex) { throw new HermesException(ex); } }
From source file:hermes.store.SingleUserMessageStore.java
public void delete(Message message) throws JMSException { final Connection connection = getWriterConnection(); final Destination destination = createStoreDestination(message.getJMSDestination()); try {//from ww w . j a va 2 s . c om adapter.remove(connection, getId(), message); for (final MessageStoreListener l : listeners) { l.onMessageDeleted(message); } synchronized (depths) { if (depths.containsKey(destination)) { depths.put(destination, depths.get(destination) - 1); } } if (getDepth(destination) == 0) { destinations.remove(destination); synchronized (depths) { depths.remove(destination); } for (final MessageStoreListener l : listeners) { l.onDestinationDeleted(destination); } } } catch (SQLException ex) { throw new HermesException(ex); } }
From source file:hermes.store.SingleUserMessageStore.java
public synchronized void store(Message message) throws JMSException { try {// w w w . j ava 2s . co m adapter.insert(getWriterConnection(), getId(), message); final Destination from = createStoreDestination(message.getJMSDestination()); if (!destinations.contains(from)) { destinations.add(from); for (MessageStoreListener l : listeners) { l.onDestination(from); } } for (MessageStoreListener l : listeners) { l.onMessage(message); } synchronized (depths) { if (depths.containsKey(from)) { depths.put(from, depths.get(from) + 1); } } } catch (SQLException ex) { throw new HermesException(ex); } }
From source file:com.adaptris.core.jms.MetadataHandler.java
private void moveJmsHeaders(Message in, AdaptrisMessage out) throws JMSException { for (JmsPropertyHandler h : JmsPropertyHandler.values()) { try {/*from w w w. j a v a 2 s . c om*/ h.copy(in, out); } catch (Exception e) { reportException(h.getKey(), e); } } out.addObjectHeader(JMS_DESTINATION, in.getJMSDestination()); out.addObjectHeader(JMS_REPLY_TO, in.getJMSReplyTo()); }
From source file:com.jmstoolkit.beans.MessageTableModel.java
/** * * @param message/* w ww . jav a2s . co m*/ */ @Override public void onMessage(Message message) { LOGGER.log(Level.FINE, "Message Received"); messagesReceived++; try { MessageTableRecord qRecord = new MessageTableRecord(); qRecord.setJMSCorrelationID(message.getJMSCorrelationID()); qRecord.setJMSDeliveryMode(message.getJMSDeliveryMode()); qRecord.setJMSExpiration(message.getJMSExpiration()); qRecord.setJMSMessageID(message.getJMSMessageID()); qRecord.setJMSTimestamp(message.getJMSTimestamp()); qRecord.setJMSType(message.getJMSType()); qRecord.setJMSDestination(message.getJMSDestination()); qRecord.setJMSCorrelationIDAsBytes(message.getJMSCorrelationIDAsBytes()); qRecord.setJMSPriority(message.getJMSPriority()); qRecord.setJMSType(message.getJMSType()); qRecord.setJMSReplyTo(message.getJMSReplyTo()); qRecord.setJMSRedelivered(message.getJMSRedelivered()); Enumeration pEnumerator = message.getPropertyNames(); Properties props = new Properties(); while (pEnumerator.hasMoreElements()) { String pElement = (String) pEnumerator.nextElement(); props.put(pElement, message.getStringProperty(pElement)); } qRecord.setProperties(props); if (message instanceof TextMessage) { qRecord.setText(((TextMessage) message).getText()); } if (message instanceof ObjectMessage) { qRecord.setObject(((ObjectMessage) message).getObject()); } List newData = data; newData.add(qRecord); this.setData(newData); } catch (JMSException e) { LOGGER.log(Level.WARNING, "JMS problem", e); } }
From source file:org.calrissian.mango.jms.stream.AbstractJmsFileTransferSupport.java
@SuppressWarnings("unchecked") public void sendStream(Request req, final Destination replyTo) throws IOException { DigestInputStream is;/*from www. j av a2 s .co m*/ Assert.notNull(req, "Request cannot be null"); final URI downloadUrl; try { downloadUrl = new URI(req.getDownloadUri()); } catch (URISyntaxException e) { throw new IOException(e); } try { is = new DigestInputStream(new BufferedInputStream(streamOpener.openStream(downloadUrl)), MessageDigest.getInstance(getHashAlgorithm())); } catch (NoSuchAlgorithmException e) { throw new JmsFileTransferException(e); } catch (Throwable e) { logger.info("Error occurred opening stream: " + e); return; } MessageQueueListener queueListener = null; try { @SuppressWarnings("rawtypes") Message returnMessage = (Message) jmsTemplate.execute(new SessionCallback() { @Override public Object doInJms(Session session) throws JMSException { DestinationRequestor requestor = null; try { Message responseMessage = DomainMessageUtils.toResponseMessage(session, new Response(ResponseStatusEnum.ACCEPT)); // Actual file transfer should be done on a queue. // Topics will not work Destination streamTransferDestination = factoryDestination(session, UUID.randomUUID().toString()); requestor = new DestinationRequestor(session, replyTo, streamTransferDestination, jmsTemplate.getReceiveTimeout()); Message returnMessage = requestor.request(responseMessage); requestor.close(); return returnMessage; } finally { if (requestor != null) requestor.close(); } } }, true); // timeout if (returnMessage == null) return; Response response = DomainMessageUtils.fromResponseMessage(returnMessage); // cancel transfer if (!ResponseStatusEnum.STARTSEND.equals(response.getStatus())) return; final Destination receiveAckDestination = returnMessage.getJMSDestination(); final Destination sendDataDestination = returnMessage.getJMSReplyTo(); queueListener = new MessageQueueListener(this, receiveAckDestination); logger.info("Sender[" + req.getRequestId() + "]: Starting send to: " + sendDataDestination); byte[] buffer = new byte[getPieceSize()]; int read = is.read(buffer); long placeInFile = 0; while (read >= 0) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); stream.write(buffer, 0, read); stream.close(); final byte[] pieceData = stream.toByteArray(); final Piece piece = new Piece(placeInFile, pieceData, getHashAlgorithm()); logger.info("Sender[" + req.getRequestId() + "]: Sending piece with position: " + piece.getPosition() + " Size of piece: " + pieceData.length); jmsTemplate.send(sendDataDestination, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { return DomainMessageUtils.toPieceMessage(session, piece); } }); // Message ret = jmsTemplate.receive(receiveAckDestination); Message ret = queueListener.getMessageInQueue(); logger.info("Sender[" + req.getRequestId() + "]: Sent piece and got ack"); // no one on the other end any longer, timeout if (ret == null) return; Response res = DomainMessageUtils.fromResponseMessage(ret); // stop transfer if (ResponseStatusEnum.RESEND.equals(res.getStatus())) { // resend piece logger.info("Sender[" + req.getRequestId() + "]: Resending piece"); } else if (ResponseStatusEnum.DENY.equals(res.getStatus())) { return; } else { buffer = new byte[getPieceSize()]; placeInFile += read; read = is.read(buffer); } } logger.info("Sender[" + req.getRequestId() + "]: Sending stop send"); final DigestInputStream fiIs = is; jmsTemplate.send(sendDataDestination, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { Response stopSendResponse = new Response(ResponseStatusEnum.STOPSEND); stopSendResponse.setHash(new String(fiIs.getMessageDigest().digest())); return DomainMessageUtils.toResponseMessage(session, stopSendResponse); } }); Message ackMessage = queueListener.getMessageInQueue(); Object fromMessage = DomainMessageUtils.fromMessage(ackMessage); if (fromMessage instanceof Response) { Response ackResponse = (Response) fromMessage; if (ResponseStatusEnum.RESEND.equals(ackResponse.getStatus())) { // TODO: resend the whole file } } } catch (Exception e) { throw new JmsFileTransferException(e); } finally { try { is.close(); } catch (IOException ignored) { } if (queueListener != null) queueListener.close(); } }