List of usage examples for javax.jms Message getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
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;//from w w w . j a va 2s .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); } }
From source file:org.nuclos.client.main.MainController.java
private void handleMessage(final Message msg) { try {//from www .ja v a2 s . c o m if ((msg.getJMSCorrelationID() == null || msg.getJMSCorrelationID().equals(MainController.this.getUserName())) && msg instanceof ObjectMessage) { final Object objMessage = ((ObjectMessage) msg).getObject(); if (objMessage.getClass().equals(ApiMessageImpl.class)) { final ApiMessageImpl apiMsg = (ApiMessageImpl) ((ObjectMessage) msg).getObject(); LOG.info("Handle " + apiMsg); Component parent = null; if (apiMsg.getReceiverId() != null) { MainFrameTab target = MainFrameTab.getMainFrameTab(apiMsg.getReceiverId()); parent = target; if (target != null) { if (apiMsg.getMessage().isOverlay()) { OverlayOptionPane.showMessageDialog(target, apiMsg.getMessage().getMessage(), apiMsg.getMessage().getTitle(), new OvOpAdapter() { }); return; } } else { LOG.warn(String.format("Receiver with id %s not found!", apiMsg.getReceiverId())); } } if (parent == null) { parent = Main.getInstance().getMainFrame(); } JOptionPane.showMessageDialog(parent, apiMsg.getMessage().getMessage(), apiMsg.getMessage().getTitle(), JOptionPane.INFORMATION_MESSAGE); } else if (objMessage.getClass().equals(RuleNotification.class)) { final RuleNotification notification = (RuleNotification) ((ObjectMessage) msg).getObject(); getNotificationDialog().addMessage(notification); switch (notification.getPriority()) { case LOW: // just add the message, nothing else. break; case NORMAL: getMainFrame().getMessagePanel().startFlashing(); break; case HIGH: getNotificationDialog().setVisible(true); break; default: LOG.warn("Undefined message priority: " + notification.getPriority()); } LOG.info("Handled RuleNotification " + notification.toDescription()); } else if (objMessage.getClass().equals(CommandMessage.class)) { final CommandMessage command = (CommandMessage) ((ObjectMessage) msg).getObject(); switch (command.getCommand()) { case CommandMessage.CMD_SHUTDOWN: getNotificationDialog().addMessage(new RuleNotification(Priority.HIGH, getSpringLocaleDelegate().getMessage("MainController.19", "Der Client wird auf Anweisung des Administrators in 10 Sekunden beendet."), "Administrator")); getNotificationDialog().setVisible(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { Thread.sleep(10000); } catch (InterruptedException e) { // do nothing } finally { MainController.this.cmdExit(); } } }); break; } LOG.info("Handled CommandMessage " + command); } else if (objMessage.getClass().equals(CommandInformationMessage.class)) { final CommandInformationMessage command = (CommandInformationMessage) ((ObjectMessage) msg) .getObject(); switch (command.getCommand()) { case CommandInformationMessage.CMD_INFO_SHUTDOWN: Object[] options = { "OK" }; int decision = JOptionPane.showOptionDialog(getMainFrame(), command.getInfo(), getSpringLocaleDelegate().getMessage("MainController.17", "Administrator - Passwort\u00e4nderung"), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); if (decision == 0 || decision == JOptionPane.CLOSED_OPTION || decision == JOptionPane.NO_OPTION) { new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(10000); } catch (InterruptedException e) { // do nothing } finally { MainController.this.cmdExit(); } } }, "MainController.handleMessage.cmdExit").run(); } break; } LOG.info("Handled CommandInformationMessage " + command); } } else { LOG.warn(getSpringLocaleDelegate().getMessage("MainController.14", "Message of type {0} received, while an ObjectMessage was expected.", msg.getClass().getName())); } } catch (JMSException ex) { LOG.warn("Exception thrown in JMS message listener.", ex); } }
From source file:org.wso2.carbon.apimgt.jms.listener.utils.JMSMessageListener.java
public void onMessage(Message message) { try {/*from w w w . ja va 2 s .co m*/ if (message != null) { if (log.isDebugEnabled()) { log.debug("Event received in JMS Event Receiver - " + message); } if (message instanceof MapMessage) { MapMessage mapMessage = (MapMessage) message; Map<String, Object> map = new HashMap<String, Object>(); Enumeration enumeration = mapMessage.getMapNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); map.put(key, mapMessage.getObject(key)); } if (map.get(APIConstants.THROTTLE_KEY) != null) { /** * This message contains throttle data in map which contains Keys * throttleKey - Key of particular throttling level * isThrottled - Whether message has throttled or not * expiryTimeStamp - When the throttling time window will expires */ handleThrottleUpdateMessage(map); } else if (map.get(APIConstants.BLOCKING_CONDITION_KEY) != null) { /** * This message contains blocking condition data * blockingCondition - Blocking condition type * conditionValue - blocking condition value * state - State whether blocking condition is enabled or not */ handleBlockingMessage(map); } else if (map.get(APIConstants.POLICY_TEMPLATE_KEY) != null) { /** * This message contains key template data * keyTemplateValue - Value of key template * keyTemplateState - whether key template active or not */ handleKeyTemplateMessage(map); } } else { log.warn("Event dropped due to unsupported message type " + message.getClass()); } } else { log.warn("Dropping the empty/null event received through jms receiver"); } } catch (JMSException e) { log.error("JMSException occurred when processing the received message ", e); } }