Example usage for javax.jms Message setStringProperty

List of usage examples for javax.jms Message setStringProperty

Introduction

In this page you can find the example usage for javax.jms Message setStringProperty.

Prototype


void setStringProperty(String name, String value) throws JMSException;

Source Link

Document

Sets a String property value with the specified name into the message.

Usage

From source file:com.seajas.search.bridge.jms.integration.GroupIdJmsHeaderMapper.java

@Override
public void fromHeaders(final MessageHeaders headers, final javax.jms.Message jmsMessage) {
    Object groupIdHeader = headers.get(SPI_HEADER_GROUPID);
    String groupId = groupIdHeader != null && groupIdHeader instanceof String ? (String) groupIdHeader : null;

    if (groupIdHeader != null && !(groupIdHeader instanceof String))
        logger.warn("A group ID header (" + SPI_HEADER_GROUPID
                + ") was set, but its type is invalid - should be String - not adding the message to a group");

    super.fromHeaders(headers, jmsMessage);

    if (useMessageGroups && groupId != null && !exclusions.contains(groupId))
        try {// w  w w . j  av  a2s.c  om
            jmsMessage.setStringProperty(JMS_HEADER_GROUPID, groupId);
        } catch (JMSException e) {
            logger.error("Could not set the JMS " + JMS_HEADER_GROUPID + " header", e);
        }

    try {
        jmsMessage.setStringProperty(JMS_HEADER_SEAJAS_DOMAIN, groupId);
    } catch (JMSException e) {
        logger.error("Could not set the JMS " + JMS_HEADER_SEAJAS_DOMAIN + " header", e);
    }
}

From source file:org.apache.servicemix.jms.AbstractJmsProcessor.java

protected Message createMessageFromExchange(Session session, MessageExchange exchange) throws Exception {
    //        TextMessage msg = session.createTextMessage();
    NormalizedMessage nm = exchange.getMessage("in");
    Message msg = fromNMS(nm, session);

    // Build the SoapAction from <interface namespace>/<interface
    // name>/<operation name>
    String soapAction = "";
    if (exchange.getOperation() != null) {
        String interFaceName = exchange.getInterfaceName() == null ? ""
                : exchange.getInterfaceName().getNamespaceURI() + "/"
                        + exchange.getInterfaceName().getLocalPart();
        soapAction = interFaceName + "/" + exchange.getOperation();
    }/*from ww w  . j av a  2s  .c o  m*/
    msg.setStringProperty("SoapAction", soapAction);
    msg.setStringProperty("SOAPJMS_soapAction", soapAction);
    return msg;
}

From source file:org.sdnmq.jms.PacketHandler.java

/**
 * Sets the properties of the message according to the message header fields for content-based filtering.
 * //from w ww  . jav  a 2s.com
 * @param msg the message whose properties are set
 * @param pkt the packet from where the message properties are derived
 */
private void setMsgProperties(Message msg, RawPacket rawPkt) {
    // The connector, the packet came from ("port")
    NodeConnector ingressConnector = rawPkt.getIncomingNodeConnector();
    // The node that received the packet ("switch")
    Node node = ingressConnector.getNode();

    try {
        msg.setStringProperty(MessageFilterAttributes.Keys.NODE_ID.toFilterName(), node.getNodeIDString());
        msg.setStringProperty(MessageFilterAttributes.Keys.NODE_TYPE.toFilterName(), node.getType());
    } catch (JMSException e) {
        log.error(e.getMessage());
    }

    try {
        msg.setStringProperty(MessageFilterAttributes.Keys.INPORT.toFilterName(),
                ingressConnector.getNodeConnectorIDString());
    } catch (JMSException e) {
        log.error(e.getMessage());
    }

    // Use DataPacketService to decode the packet.
    Packet pkt = dataPacketService.decodeDataPacket(rawPkt);

    while (pkt != null) {
        if (pkt instanceof Ethernet) {
            Ethernet ethernet = (Ethernet) pkt;
            ethernetToProperties(ethernet, msg);
        } else if (pkt instanceof IEEE8021Q) {
            IEEE8021Q ieee802q = (IEEE8021Q) pkt;
            ieee8021qToProperties(ieee802q, msg);
        } else if (pkt instanceof IPv4) {
            IPv4 ipv4 = (IPv4) pkt;
            ipv4ToProperties(ipv4, msg);
        } else if (pkt instanceof TCP) {
            TCP tcp = (TCP) pkt;
            tcpToProperties(tcp, msg);
        } else if (pkt instanceof UDP) {
            UDP udp = (UDP) pkt;
            udpToProperties(udp, msg);
        }

        pkt = pkt.getPayload();
    }
}

From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java

private void setTransportHeaders(Message message, MessageContext synCtx) {
    //Set transport headers to the message
    Map<?, ?> headerMap = (Map<?, ?>) ((Axis2MessageContext) synCtx).getAxis2MessageContext()
            .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    if (headerMap != null) {
        for (Object headerName : headerMap.keySet()) {
            String name = (String) headerName;
            Object value = headerMap.get(name);
            try {
                if (value instanceof String) {
                    message.setStringProperty(name, (String) value);
                } else if (value instanceof Boolean) {
                    message.setBooleanProperty(name, (Boolean) value);
                } else if (value instanceof Integer) {
                    message.setIntProperty(name, (Integer) value);
                } else if (value instanceof Long) {
                    message.setLongProperty(name, (Long) value);
                } else if (value instanceof Double) {
                    message.setDoubleProperty(name, (Double) value);
                } else if (value instanceof Float) {
                    message.setFloatProperty(name, (Float) value);
                }// w  w  w.j  av  a2 s. com
            } catch (JMSException ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Could not save Message property: " + ex.getLocalizedMessage());
                }
            }
        }
    }
}

From source file:com.eviware.soapui.impl.wsdl.submit.transports.jms.HermesJmsRequestTransport.java

protected JMSHeader createJMSHeader(SubmitContext submitContext, Request request, Hermes hermes,
        Message message, Destination replyToDestination) {
    JMSHeader jmsHeader = new JMSHeader();
    jmsHeader.setMessageHeaders(message, request, hermes, submitContext);
    JMSHeader.setMessageProperties(message, request, hermes, submitContext);
    try {/*from  w w  w . ja  va2 s  .  com*/
        if (message.getJMSReplyTo() == null) {
            message.setJMSReplyTo(replyToDestination);
        }

        if (addSoapAction) {

            message.setStringProperty(JMSHeader.SOAPJMS_SOAP_ACTION, request.getOperation().getName());
            if (request.getOperation() instanceof WsdlOperation) {
                message.setStringProperty(JMSHeader.SOAP_ACTION,
                        ((WsdlOperation) request.getOperation()).getAction());
            } else {
                message.setStringProperty(JMSHeader.SOAP_ACTION, request.getOperation().getName());
            }
        }
    } catch (JMSException e) {
        SoapUI.logError(e);
    }
    return jmsHeader;
}

From source file:org.apache.axis2.transport.jms.MockEchoEndpoint.java

@Setup
@SuppressWarnings("unused")
private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception {
    Destination destination = channel.getDestination();
    Destination replyDestination = channel.getReplyDestination();
    connection = env.getConnectionFactory().createConnection();
    connection.setExceptionListener(this);
    connection.start();//from   ww  w .  j  av a 2s .co  m
    replyConnection = env.getConnectionFactory().createConnection();
    replyConnection.setExceptionListener(this);
    final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final MessageProducer producer = replySession.createProducer(replyDestination);
    MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
            .createConsumer(destination);
    consumer.setMessageListener(new MessageListener() {
        public void onMessage(Message message) {
            try {
                log.info("Message received: ID = " + message.getJMSMessageID());
                Message reply;
                if (message instanceof BytesMessage) {
                    reply = replySession.createBytesMessage();
                    IOUtils.copy(new BytesMessageInputStream((BytesMessage) message),
                            new BytesMessageOutputStream((BytesMessage) reply));
                } else if (message instanceof TextMessage) {
                    reply = replySession.createTextMessage();
                    ((TextMessage) reply).setText(((TextMessage) message).getText());
                } else {
                    // TODO
                    throw new UnsupportedOperationException("Unsupported message type");
                }
                reply.setJMSCorrelationID(message.getJMSMessageID());
                reply.setStringProperty(BaseConstants.CONTENT_TYPE,
                        message.getStringProperty(BaseConstants.CONTENT_TYPE));
                producer.send(reply);
                log.info("Message sent: ID = " + reply.getJMSMessageID());
            } catch (Throwable ex) {
                fireEndpointError(ex);
            }
        }
    });
}

From source file:org.oxymores.chronix.engine.RunnerAgent.java

@Override
public void onMessage(Message msg) {
    log.info("Run request received");
    ObjectMessage omsg = (ObjectMessage) msg;
    RunDescription rd;/*w ww .ja  v a2  s  . c o  m*/
    RunResult res = null;

    try {
        Object o = omsg.getObject();
        if (!(o instanceof RunDescription)) {
            log.warn("An object was received on the runner queue but was not a RunDescription! Ignored.");
            jmsCommit();
            return;
        }
        rd = (RunDescription) o;
    } catch (JMSException e) {
        log.error(
                "An error occurred during RunDescription reception. Message will stay in queue and will be analysed later",
                e);
        jmsRollback();
        return;
    }

    if (!rd.getHelperExecRequest()) {
        log.info(String.format("Running command %s", rd.getCommand()));
    } else {
        log.debug(String.format("Running helper internal command %s", rd.getCommand()));
    }

    // Log file (only if true run)
    String logFilePath = null;
    String logFileName = null;
    Date start = new Date();
    if (!rd.getHelperExecRequest()) {
        SimpleDateFormat myFormatDir = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat myFormatFile = new SimpleDateFormat("yyyyMMddhhmmssSSS");
        String dd = myFormatDir.format(start);
        String logFileDateDir = FilenameUtils.concat(this.logDbPath, dd);
        if (!(new File(logFileDateDir)).exists() && !(new File(logFileDateDir)).mkdir()) {
            log.fatal("Could not create log directory, failing engine");
            this.broker.stop();
            jmsRollback();
            return;
        }
        logFileName = String.format("%s_%s_%s_%s.log", myFormatFile.format(start),
                rd.getPlaceName().replace(" ", "-"), rd.getActiveSourceName().replace(" ", "-"), rd.getId1());
        logFilePath = FilenameUtils.concat(logFileDateDir, logFileName);
    }

    // Run the command according to its method
    if (rd.getMethod().equals(Constants.JD_METHOD_SHELL)) {
        res = RunnerShell.run(rd, logFilePath, !rd.getHelperExecRequest(), rd.getShouldSendLogFile());
    } else {
        res = new RunResult();
        res.returnCode = -1;
        res.logStart = String.format("An unimplemented exec method (%s) was called!", rd.getMethod());
        log.error(String.format("An unimplemented exec method (%s) was called! Job will be failed.",
                rd.getMethod()));
    }
    res.start = start;
    res.end = new Date();
    res.logFileName = logFileName;
    res.logPath = logFilePath;

    // Copy the engine ids - that way it will be able to identify the launch
    // Part of the ids are in the JMS correlation id too
    res.id1 = rd.getId1();
    res.id2 = rd.getId2();
    res.outOfPlan = rd.getOutOfPlan();

    // Send the result!
    Message response;
    if (!rd.getHelperExecRequest()) {
        InputStream is = null;
        try {
            response = jmsSession.createObjectMessage(res);
            response.setJMSCorrelationID(msg.getJMSCorrelationID());
            jmsProducer.send(msg.getJMSReplyTo(), response);

            if (res.logSizeBytes <= 500000) {
                response = jmsSession.createBytesMessage();
                byte[] bytes = new byte[(int) res.logSizeBytes];
                is = new FileInputStream(res.logPath);
                is.read(bytes);
                IOUtils.closeQuietly(is);

                ((BytesMessage) response).writeBytes(bytes);
                response.setJMSCorrelationID(msg.getJMSCorrelationID());
                response.setStringProperty("FileName", logFileName);
                jmsProducer.send(msg.getJMSReplyTo(), response);
            } else {
                log.warn(
                        "A log file was too big and will not be sent. Only the full log file will be missing - the launch will still appear in the console.");
            }
        } catch (Exception e1) {
            log.error(
                    "The runner was not able to send the result of an execution to the engine. This may corrupt plan execution!",
                    e1);
            IOUtils.closeQuietly(is);
        }
    } else {
        try {
            response = jmsSession.createTextMessage(res.logStart);
            response.setJMSCorrelationID(msg.getJMSCorrelationID());
            jmsProducer.send(msg.getJMSReplyTo(), response);
        } catch (JMSException e1) {
            log.error(
                    "The runner was not able to send the result of a parameter resolution to the engine. This may corrupt plan execution!",
                    e1);
        }
    }

    jmsCommit();
}

From source file:org.openanzo.combus.realtime.RealtimeUpdatePublisher.java

private void setMessageProperties(Message message, Map<String, Object> properties) throws JMSException {
    // How can we do this more efficiently?
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        String name = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof String) {
            message.setStringProperty(name, (String) value);
        } else if (value instanceof Integer) {
            message.setIntProperty(name, ((Integer) value).intValue());
        } else if (value instanceof Long) {
            message.setLongProperty(name, ((Long) value).longValue());
        } else if (value instanceof Float) {
            message.setFloatProperty(name, ((Float) value).floatValue());
        } else if (value instanceof Double) {
            message.setDoubleProperty(name, ((Double) value).doubleValue());
        } else if (value instanceof Short) {
            message.setShortProperty(name, ((Short) value).shortValue());
        } else if (value instanceof Byte) {
            message.setByteProperty(name, ((Byte) value).byteValue());
        } else if (value instanceof Boolean) {
            message.setBooleanProperty(name, ((Boolean) value).booleanValue());
        }//from ww w. j  av  a2  s .c om
    }
}

From source file:org.apache.qpid.disttest.client.MessageProvider.java

protected void setCustomProperty(Message message, String propertyName, Object propertyValue)
        throws JMSException {
    if (propertyValue instanceof Integer) {
        message.setIntProperty(propertyName, ((Integer) propertyValue).intValue());
    } else if (propertyValue instanceof Long) {
        message.setLongProperty(propertyName, ((Long) propertyValue).longValue());
    } else if (propertyValue instanceof Boolean) {
        message.setBooleanProperty(propertyName, ((Boolean) propertyValue).booleanValue());
    } else if (propertyValue instanceof Byte) {
        message.setByteProperty(propertyName, ((Byte) propertyValue).byteValue());
    } else if (propertyValue instanceof Double) {
        message.setDoubleProperty(propertyName, ((Double) propertyValue).doubleValue());
    } else if (propertyValue instanceof Float) {
        message.setFloatProperty(propertyName, ((Float) propertyValue).floatValue());
    } else if (propertyValue instanceof Short) {
        message.setShortProperty(propertyName, ((Short) propertyValue).shortValue());
    } else if (propertyValue instanceof String) {
        message.setStringProperty(propertyName, (String) propertyValue);
    } else {// ww  w.  j  a  v a2  s .c  om
        message.setObjectProperty(propertyName, propertyValue);
    }
}