List of usage examples for javax.jms BytesMessage setObjectProperty
void setObjectProperty(String name, Object value) throws JMSException;
From source file:me.norman.maurer.james.queue.HornetQMailQueue.java
@Override protected void produceMail(Session session, Map<String, Object> props, int msgPrio, Mail mail) throws JMSException, MessagingException, IOException { MessageProducer producer = null;/*ww w.j a v a 2 s. co m*/ try { BytesMessage message = session.createBytesMessage(); Iterator<String> propIt = props.keySet().iterator(); while (propIt.hasNext()) { String key = propIt.next(); message.setObjectProperty(key, props.get(key)); } // set the stream to read frome message.setObjectProperty("JMS_HQ_InputStream", new BufferedInputStream(new MimeMessageInputStream(mail.getMessage()))); Queue q = session.createQueue(queuename); producer = session.createProducer(q); producer.send(message, Message.DEFAULT_DELIVERY_MODE, msgPrio, Message.DEFAULT_TIME_TO_LIVE); } finally { if (producer != null) { producer.close(); } } }
From source file:org.mitre.mpf.markup.MarkupRequestConsumer.java
public void onMessage(Message message) { Stopwatch stopwatch = Stopwatch.createStarted(); if (message == null) { log.warn("Received a null JMS message. No action will be taken."); return;/* w w w . j a v a2s . com*/ } if (!(message instanceof BytesMessage)) { log.warn("Received a JMS message, but it was not of the correct type. No action will be taken."); return; } try { log.info("Received JMS message. Type = {}. JMS Message ID = {}. JMS Correlation ID = {}.", message.getClass().getName(), message.getJMSMessageID(), message.getJMSCorrelationID()); final Map<String, Object> requestHeaders = new HashMap<String, Object>(); Enumeration<String> properties = message.getPropertyNames(); String propertyName = null; while (properties.hasMoreElements()) { propertyName = properties.nextElement(); requestHeaders.put(propertyName, message.getObjectProperty(propertyName)); } byte[] messageBytes = new byte[(int) (((BytesMessage) message).getBodyLength())]; ((BytesMessage) message).readBytes(messageBytes); Markup.MarkupRequest markupRequest = Markup.MarkupRequest.parseFrom(messageBytes); Markup.MarkupResponse.Builder markupResponseBuilder = initializeResponse(markupRequest); markupResponseBuilder.setRequestTimestamp(message.getJMSTimestamp()); log.debug("Processing markup request. Media Index = {}. Media ID = {} (type = {}). Request ID = {}.", markupRequest.getMediaIndex(), markupRequest.getMediaId(), markupRequest.getMediaType(), markupRequest.getRequestId()); try { if (!new File(URI.create(markupRequest.getDestinationUri())).canWrite()) { throw new Exception(); } } catch (Exception exception) { markupResponseBuilder.setHasError(true); markupResponseBuilder.setErrorMessage( String.format("The target URI '%s' is not writable.", markupRequest.getDestinationUri())); } try { if (!new File(URI.create(markupRequest.getSourceUri())).canRead()) { throw new Exception(); } } catch (Exception exception) { markupResponseBuilder.setHasError(true); markupResponseBuilder.setErrorMessage( String.format("The source URI '%s' is not readable.", markupRequest.getSourceUri())); } if (!markupResponseBuilder.getHasError()) { if (markupRequest.getMapEntriesCount() == 0) { try { FileUtils.copyFile(new File(URI.create(markupRequest.getSourceUri())), new File(URI.create(markupRequest.getDestinationUri()))); markupResponseBuilder.setOutputFileUri(markupRequest.getDestinationUri()); } catch (Exception exception) { log.error("Failed to mark up the file '{}' because of an exception.", markupRequest.getSourceUri(), exception); finishWithError(markupResponseBuilder, exception); } } else if (markupRequest.getMediaType() == Markup.MediaType.IMAGE) { try { if (markupImage(markupRequest)) { markupResponseBuilder.setOutputFileUri(markupRequest.getDestinationUri()); } else { markupResponseBuilder.setOutputFileUri(markupRequest.getSourceUri()); } } catch (Exception exception) { log.error("Failed to mark up the image '{}' because of an exception.", markupRequest.getSourceUri(), exception); finishWithError(markupResponseBuilder, exception); } } else { try { if (markupVideo(markupRequest)) { markupResponseBuilder.setOutputFileUri(markupRequest.getDestinationUri()); } else { markupResponseBuilder.setOutputFileUri(markupRequest.getDestinationUri()); } } catch (Exception exception) { log.error("Failed to mark up the video '{}' because of an exception.", markupRequest.getSourceUri(), exception); finishWithError(markupResponseBuilder, exception); } } } stopwatch.stop(); markupResponseBuilder.setTimeProcessing(stopwatch.elapsed(TimeUnit.MILLISECONDS)); final Markup.MarkupResponse markupResponse = markupResponseBuilder.build(); log.info("Returning response for Media {}. Error: {}.", markupResponse.getMediaId(), markupResponse.getHasError()); markupResponseTemplate.setSessionTransacted(true); markupResponseTemplate.setDefaultDestination(message.getJMSReplyTo()); markupResponseTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { BytesMessage bytesMessage = session.createBytesMessage(); bytesMessage.writeBytes(markupResponse.toByteArray()); for (Map.Entry<String, Object> entry : requestHeaders.entrySet()) { bytesMessage.setObjectProperty(entry.getKey(), entry.getValue()); } return bytesMessage; } }); } catch (Exception e) { log.error(e.getMessage(), e); } }