List of usage examples for javax.jms Message getIntProperty
int getIntProperty(String name) throws JMSException;
From source file:org.mule.transport.jms.redelivery.JmsXRedeliveryHandler.java
/** * process the redelivered message. If the Jms receiver should process the * message, it should be returned. Otherwise the connector should throw a * <code>MessageRedeliveredException</code> to indicate that the message should * be handled by the connector Exception Handler. * //from ww w. j a va 2 s . c om */ @Override public void handleRedelivery(Message message, InboundEndpoint endpoint, FlowConstruct flow) throws JMSException, MuleException { final int connectorRedelivery = connector.getMaxRedelivery(); if (connectorRedelivery == JmsConnector.REDELIVERY_IGNORE || connectorRedelivery < 0) // just in case, for manual setting) { if (logger.isDebugEnabled()) { logger.debug("We were asked to ignore the redelivery count, nothing to do here."); } return; } String messageId = message.getJMSMessageID(); int deliveryCount = -1; try { deliveryCount = message.getIntProperty(JmsConstants.JMS_X_DELIVERY_COUNT); } catch (NumberFormatException nex) { throw new MuleRuntimeException(MessageFactory.createStaticMessage(String.format( "Invalid use of %s. Message is flagged with JMSRedelivered, but JMSXDeliveryCount is not set", getClass().getName()))); } int redeliveryCount = deliveryCount - 1; if (redeliveryCount == 1) { if (logger.isDebugEnabled()) { logger.debug("Message with id: " + messageId + " has been redelivered for the first time"); } if (connectorRedelivery == JmsConnector.REDELIVERY_FAIL_ON_FIRST) { MuleMessage msg = createMuleMessage(message); throw new MessageRedeliveredException(messageId, redeliveryCount, connectorRedelivery, endpoint, flow, msg); } } else if (redeliveryCount > connectorRedelivery) { MuleMessage msg = createMuleMessage(message); throw new MessageRedeliveredException(messageId, redeliveryCount, connectorRedelivery, endpoint, flow, msg); } else { if (logger.isDebugEnabled()) { // re-delivery count is actually less by 1 than an actual delivery count logger.debug( "Message with id: " + messageId + " has been redelivered " + redeliveryCount + " times"); } } }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSInjectHandler.java
/** * Invoke the mediation logic for the passed message * *//*from w w w . ja va 2 s. c om*/ public boolean invoke(Object object, String name) throws SynapseException { Message msg = (Message) object; try { org.apache.synapse.MessageContext msgCtx = createMessageContext(); msgCtx.setProperty("inbound.endpoint.name", name); InboundEndpoint inboundEndpoint = msgCtx.getConfiguration().getInboundEndpoint(name); CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName()); String contentType = msg.getJMSType(); if (contentType == null || contentType.trim().equals("")) { String contentTypeProperty = jmsProperties.getProperty(JMSConstants.CONTENT_TYPE_PROPERTY); if (contentTypeProperty != null) { contentType = msg.getStringProperty(contentTypeProperty); } } else { msgCtx.setProperty(JMSConstants.JMS_MESSAGE_TYPE, contentType); } if (contentType == null || contentType.trim().equals("")) { contentType = jmsProperties.getProperty(JMSConstants.CONTENT_TYPE); } if (log.isDebugEnabled()) { log.debug("Processed JMS Message of Content-type : " + contentType); } MessageContext axis2MsgCtx = ((org.apache.synapse.core.axis2.Axis2MessageContext) msgCtx) .getAxis2MessageContext(); //setting transport headers axis2MsgCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, JMSUtils.getTransportHeaders(msg, axis2MsgCtx)); // set the JMS Message ID as the Message ID of the MessageContext try { msgCtx.setMessageID(msg.getJMSMessageID()); String jmsCorrelationID = msg.getJMSCorrelationID(); if (jmsCorrelationID != null && !jmsCorrelationID.isEmpty()) { msgCtx.setProperty(JMSConstants.JMS_COORELATION_ID, jmsCorrelationID); } else { msgCtx.setProperty(JMSConstants.JMS_COORELATION_ID, msg.getJMSMessageID()); } } catch (JMSException ignore) { log.warn("Error getting the COORELATION ID from the message."); } // Handle dual channel Destination replyTo = msg.getJMSReplyTo(); if (replyTo != null) { msgCtx.setProperty(SynapseConstants.IS_INBOUND, true); // Create the cachedJMSConnectionFactory with the existing // connection CachedJMSConnectionFactory cachedJMSConnectionFactory = new CachedJMSConnectionFactory( jmsProperties, connection); String strUserName = jmsProperties.getProperty(JMSConstants.PARAM_JMS_USERNAME); String strPassword = jmsProperties.getProperty(JMSConstants.PARAM_JMS_PASSWORD); JMSReplySender jmsReplySender = new JMSReplySender(replyTo, cachedJMSConnectionFactory, strUserName, strPassword); msgCtx.setProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER, jmsReplySender); } else if (replyDestination != null) { msgCtx.setProperty(SynapseConstants.IS_INBOUND, true); // Create the cachedJMSConnectionFactory with the existing // connection CachedJMSConnectionFactory cachedJMSConnectionFactory = new CachedJMSConnectionFactory( jmsProperties, connection); String strUserName = jmsProperties.getProperty(JMSConstants.PARAM_JMS_USERNAME); String strPassword = jmsProperties.getProperty(JMSConstants.PARAM_JMS_PASSWORD); JMSReplySender jmsReplySender = new JMSReplySender(replyDestination, cachedJMSConnectionFactory, strUserName, strPassword); msgCtx.setProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER, jmsReplySender); } // Determine the message builder to use Builder builder; if (contentType == null) { log.debug("No content type specified. Using SOAP builder."); builder = new SOAPBuilder(); } else { int index = contentType.indexOf(';'); String type = index > 0 ? contentType.substring(0, index) : contentType; builder = BuilderUtil.getBuilderFromSelector(type, axis2MsgCtx); if (builder == null) { if (log.isDebugEnabled()) { log.debug("No message builder found for type '" + type + "'. Falling back to SOAP."); } builder = new SOAPBuilder(); } } OMElement documentElement = null; // set the message payload to the message context try { if (msg instanceof TextMessage) { String message = ((TextMessage) msg).getText(); InputStream in = new AutoCloseInputStream(new ByteArrayInputStream(message.getBytes())); documentElement = builder.processDocument(in, contentType, axis2MsgCtx); } else if (msg instanceof BytesMessage) { if (builder instanceof DataSourceMessageBuilder) { documentElement = ((DataSourceMessageBuilder) builder).processDocument( new BytesMessageDataSource((BytesMessage) msg), contentType, axis2MsgCtx); } else { documentElement = builder.processDocument(new BytesMessageInputStream((BytesMessage) msg), contentType, axis2MsgCtx); } } else if (msg instanceof MapMessage) { documentElement = convertJMSMapToXML((MapMessage) msg); } } catch (Exception ex) { // Handle message building error log.error("Error while building the message", ex); msgCtx.setProperty(SynapseConstants.ERROR_CODE, GenericConstants.INBOUND_BUILD_ERROR); msgCtx.setProperty(SynapseConstants.ERROR_MESSAGE, ex.getMessage()); SequenceMediator faultSequence = getFaultSequence(msgCtx, inboundEndpoint); faultSequence.mediate(msgCtx); if (isRollback(msgCtx)) { return false; } return true; } // Setting JMSXDeliveryCount header on the message context try { int deliveryCount = msg.getIntProperty("JMSXDeliveryCount"); msgCtx.setProperty(JMSConstants.DELIVERY_COUNT, deliveryCount); } catch (NumberFormatException nfe) { if (log.isDebugEnabled()) { log.debug("JMSXDeliveryCount is not set in the received message"); } } // Inject the message to the sequence. msgCtx.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement)); if (injectingSeq == null || injectingSeq.equals("")) { log.error("Sequence name not specified. Sequence : " + injectingSeq); return false; } SequenceMediator seq = (SequenceMediator) synapseEnvironment.getSynapseConfiguration() .getSequence(injectingSeq); if (seq != null) { if (log.isDebugEnabled()) { log.debug("injecting message to sequence : " + injectingSeq); } if (!seq.isInitialized()) { seq.init(synapseEnvironment); } SequenceMediator faultSequence = getFaultSequence(msgCtx, inboundEndpoint); MediatorFaultHandler mediatorFaultHandler = new MediatorFaultHandler(faultSequence); msgCtx.pushFaultHandler(mediatorFaultHandler); if (!synapseEnvironment.injectInbound(msgCtx, seq, sequential)) { return false; } } else { log.error("Sequence: " + injectingSeq + " not found"); } if (isRollback(msgCtx)) { return false; } } catch (SynapseException se) { throw se; } catch (Exception e) { log.error("Error while processing the JMS Message", e); throw new SynapseException("Error while processing the JMS Message", e); } return true; }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSUtils.java
/** * Extract transport level headers from JMS message into a Map * @param message JMS message/*from www .j a v a 2 s.c o m*/ * @param msgContext axis2 message context * @return a Map of the transport headers */ public static Map<String, Object> getTransportHeaders(Message message, MessageContext msgContext) { // create a Map to hold transport headers Map<String, Object> map = new HashMap<>(); try { Enumeration<?> propertyNamesEnm = message.getPropertyNames(); while (propertyNamesEnm.hasMoreElements()) { String headerName = (String) propertyNamesEnm.nextElement(); Object headerValue = message.getObjectProperty(headerName); if (headerValue instanceof String) { if (isHyphenReplaceMode(msgContext)) { map.put(inverseTransformHyphenatedString(headerName), message.getStringProperty(headerName)); } else { map.put(headerName, message.getStringProperty(headerName)); } } else if (headerValue instanceof Integer) { map.put(headerName, message.getIntProperty(headerName)); } else if (headerValue instanceof Boolean) { map.put(headerName, message.getBooleanProperty(headerName)); } else if (headerValue instanceof Long) { map.put(headerName, message.getLongProperty(headerName)); } else if (headerValue instanceof Double) { map.put(headerName, message.getDoubleProperty(headerName)); } else if (headerValue instanceof Float) { map.put(headerName, message.getFloatProperty(headerName)); } else { map.put(headerName, headerValue); } } } catch (JMSException e) { log.error("Error while reading the Transport Headers from JMS Message", e); } return map; }
From source file:rewards.messaging.server.DiningListenerImpl.java
private void logMessage(Message message, Dining dining) throws JMSException { if (log.isDebugEnabled()) { String msg = "Received Dining with amount " + dining.getAmount(); if (message.getJMSRedelivered()) { int nrOfDeliveries = message.getIntProperty("JMSXDeliveryCount"); msg += " (redelivered " + (nrOfDeliveries - 1) + " times)"; }//from w w w. ja va2 s . c o m log.debug(msg); } }