Example usage for javax.jms TextMessage setIntProperty

List of usage examples for javax.jms TextMessage setIntProperty

Introduction

In this page you can find the example usage for javax.jms TextMessage setIntProperty.

Prototype


void setIntProperty(String name, int value) throws JMSException;

Source Link

Document

Sets an int property value with the specified name into the message.

Usage

From source file:org.apache.activemq.web.RestTest.java

@Test(timeout = 60 * 1000)
public void testSelector() throws Exception {
    int port = getPort();

    TextMessage msg1 = session.createTextMessage("test1");
    msg1.setIntProperty("test", 1);
    producer.send(msg1);/*w  w w.  ja  v a  2 s  .c  o  m*/
    LOG.info("message 1 sent");

    TextMessage msg2 = session.createTextMessage("test2");
    msg2.setIntProperty("test", 2);
    producer.send(msg2);
    LOG.info("message 2 sent");

    HttpClient httpClient = new HttpClient();
    httpClient.start();

    final StringBuffer buf = new StringBuffer();
    final CountDownLatch latch = new CountDownLatch(1);
    httpClient.newRequest("http://localhost:" + port + "/message/test?readTimeout=1000&type=queue")
            .header("selector", "test=2").send(new BufferingResponseListener() {
                @Override
                public void onComplete(Result result) {
                    buf.append(getContentAsString());
                    latch.countDown();
                }
            });
    latch.await();
    assertEquals("test2", buf.toString());
}

From source file:org.codehaus.stomp.StompTest.java

public void testSubscribeWithMessageSentWithProperties() throws Exception {

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);//from  w  w  w. ja va2  s . co  m

    frame = receiveFrame(100000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "ack:auto\n\n" + Stomp.NULL;
    sendFrame(frame);

    MessageProducer producer = session.createProducer(queue);
    TextMessage message = session.createTextMessage("Hello World");
    message.setStringProperty("s", "value");
    message.setBooleanProperty("n", false);
    message.setByteProperty("byte", (byte) 9);
    message.setDoubleProperty("d", 2.0);
    message.setFloatProperty("f", (float) 6.0);
    message.setIntProperty("i", 10);
    message.setLongProperty("l", 121);
    message.setShortProperty("s", (short) 12);
    producer.send(message);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));

    //        System.out.println("out: "+frame);

    frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);
}

From source file:org.openanzo.combus.endpoint.BaseServiceListener.java

private void processMessage(Message request) {
    try {//  w ww . ja v a  2s.  c om
        IOperationContext context = null;
        TextMessage response = null;
        String operation = request.getStringProperty(SerializationConstants.operation);
        try {
            Destination replyTo = null;
            try {
                if (mp == null) {
                    mp = session.createProducer(null);
                    mp.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
                }
                replyTo = request.getJMSReplyTo();

                String resultFormat = request.getStringProperty(SerializationConstants.resultFormat);
                context = new BaseOperationContext(operation, request.getJMSCorrelationID(), null);
                if (request.propertyExists(SerializationConstants.userDescription)) {
                    context.setAttribute(SerializationConstants.userDescription,
                            request.getStringProperty(SerializationConstants.userDescription));
                }
                if (request.propertyExists(OPTIONS.SKIPCACHE)) {
                    context.setAttribute(OPTIONS.SKIPCACHE, request.getBooleanProperty(OPTIONS.SKIPCACHE));
                }
                if (request.propertyExists(OPTIONS.INCLUDEMETADATAGRAPHS)) {
                    context.setAttribute(OPTIONS.INCLUDEMETADATAGRAPHS,
                            request.getBooleanProperty(OPTIONS.INCLUDEMETADATAGRAPHS));
                }

                AnzoPrincipal callerPrincipal = getContextPrincipal(context, request);
                context.setOperationPrincipal(callerPrincipal);

                if (log.isTraceEnabled()) {
                    log.trace(LogUtils.COMBUS_MARKER,
                            MessageUtils.prettyPrint(request,
                                    "Message Recieved from [" + callerPrincipal.getName() + "]"
                                            + ((replyTo != null) ? (" with replyto [" + replyTo + "]") : "")));
                } else if (log.isDebugEnabled()) {
                    log.debug(LogUtils.COMBUS_MARKER, "Message Recieved from [" + callerPrincipal.getName()
                            + "]" + ((replyTo != null) ? (" with replyto [" + replyTo + "]") : ""));
                }
                context.setMDC();
                Boolean analyzeRequest = request
                        .getBooleanProperty(RequestAnalysis.CONTEXT_PROP_REQUEST_ENABLED);
                if (analyzeRequest || recorder != null) {
                    RequestAnalysis.setCurrentContext(context.getAttributes());
                    RequestAnalysis.setRequestAnalysisEnabled(true);
                }

                if (recorder != null) {
                    recorder.recordRequest((TextMessage) request, request.getStringProperty("JMSXUserID"),
                            request.getStringProperty(SerializationConstants.runAsUser));
                }

                long start = 0, end = 0;
                if (RequestAnalysis.isAnalysisEnabled(context.getAttributes())) {
                    start = System.currentTimeMillis();
                }

                response = handleMessage(context, replyTo, resultFormat, operation, (TextMessage) request, mp);
                if (RequestAnalysis.isAnalysisEnabled(context.getAttributes())) {
                    end = System.currentTimeMillis();
                    RequestAnalysis.addAnalysisProperty(RequestAnalysis.ANS_PROP_OPERATION_TIME,
                            String.valueOf(end - start));
                }

                if (response != null) {
                    response.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
                    if (operation != null) {
                        response.setStringProperty(SerializationConstants.operation, operation);
                    }
                    Integer totalSolutions = context.getAttribute(SerializationConstants.totalSolutions,
                            Integer.class);
                    if (totalSolutions != null) {
                        response.setIntProperty(SerializationConstants.totalSolutions,
                                totalSolutions.intValue());
                    }
                    if (analyzeRequest) {
                        for (String name : RequestAnalysis.getAnalysisPropertyNames()) {
                            response.setStringProperty(name, context.getAttribute(name).toString());
                        }
                    }
                }

                if (response != null && replyTo != null) {
                    response.setJMSCorrelationID(request.getJMSCorrelationID());
                    if (log.isTraceEnabled()) {
                        log.trace(LogUtils.COMBUS_MARKER,
                                MessageUtils.prettyPrint(response, "Sending Response to [" + replyTo + "]"));
                    } else if (log.isDebugEnabled()) {
                        log.debug(LogUtils.COMBUS_MARKER, "Sending Response to [" + replyTo + "]");
                    }
                    mp.send(replyTo, response);
                }

            } catch (JMSException jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex,
                        ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString());
            } catch (AnzoException jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex, jmex.getErrorCode(), jmex.getArgs());
            } catch (AnzoRuntimeException jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex, jmex.getErrorCode(), jmex.getArgs());
            } catch (RuntimeException jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex,
                        ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString());
            } catch (Throwable jmex) {
                response = sendJMSErrorMessage(replyTo, request, jmex,
                        ExceptionConstants.COMBUS.JMS_SERVICE_EXCEPTION, jmex.toString());
            }

            if (recorder != null) {
                if (response != null) {
                    recorder.recordResponse(response);
                } else {
                    recorder.recordResponse(request.getJMSCorrelationID(), operation);
                }
            }
        } finally {
            if (context != null) {
                context.clearMDC();
            }
        }
    } catch (JMSException jmsex) {
        if (jmsex.getCause() instanceof InterruptedException) {
            log.debug(LogUtils.COMBUS_MARKER, "Thread interrupted in order to stop.", jmsex);
        } else {
            log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmsex);
        }
    } catch (Throwable jmex) {
        log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmex);
    }
}

From source file:org.openanzo.combus.endpoint.BaseServiceListener.java

private TextMessage sendJMSErrorMessage(Destination replyTo, Message request, Throwable jmex, long errorCode,
        String... args) throws JMSException {
    try {/*from  w  w w. j a v  a 2s  .  co  m*/
        if (replyTo != null) {
            if (log.isWarnEnabled()) {
                log.warn(LogUtils.COMBUS_MARKER,
                        "Exception while ServiceListener [" + name + "] was precessing request.", jmex);

            }
            String message = null;
            if (jmex instanceof AnzoException) {
                message = ((AnzoException) jmex).getMessage(false);
            } else if (jmex instanceof AnzoRuntimeException) {
                message = ((AnzoRuntimeException) jmex).getMessage(false);
            } else {
                message = jmex.getMessage();
            }
            TextMessage response = session.createTextMessage(message);
            response.setJMSCorrelationID(request.getJMSCorrelationID());
            response.setBooleanProperty(SerializationConstants.operationFailed, true);
            response.setLongProperty(SerializationConstants.errorTags, 0);
            response.setLongProperty(SerializationConstants.errorCode, errorCode);
            response.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
            // send a single arg string for compat. with older readers
            response.setStringProperty(SerializationConstants.errorMessageArg, Arrays.toString(args));

            // send the individual error args for readers that can make use of them
            for (int i = 0; i < args.length; i++) {
                response.setStringProperty(SerializationConstants.errorMessageArg + i, args[i]);
            }

            // we log all JMS messages, even errors.
            if (log.isDebugEnabled()) {
                log.debug(LogUtils.COMBUS_MARKER,
                        MessageUtils.prettyPrint(response, "Sending Response to " + replyTo));
            }
            mp.send(replyTo, response);
            return response;
        }
    } catch (JMSException jmsex) {
        log.debug(LogUtils.COMBUS_MARKER, "Error sending error message to client", jmsex);
    }
    return null;
}

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

/**
 * Reset cache the cache of acls/* w w  w  . j  av  a  2  s.  co  m*/
 * 
 * @param session
 *            session
 * @throws AnzoException
 */
public void reset(Session session) throws AnzoException {
    synchronized (datasetTrackers) {
        datasetTrackers.clear();
    }
    userRolesCache.clear();
    graphRolesCache.clear();
    registeredSysadmins.clear();
    trackers.clear();
    namedGraphTrackers.clear();
    try {
        // Now send a transaction complete to all users
        TextMessage endMessage = session.createTextMessage();
        endMessage.setStringProperty(SerializationConstants.operation, SerializationConstants.reset);
        endMessage.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
        for (Map.Entry<URI, Collection<Destination>> entry : userDestinations.entrySet()) {
            Collection<Destination> destinations = entry.getValue();
            for (Destination destination : destinations) {
                try {
                    getProducer().send(destination, endMessage);
                } catch (JMSException jmex) {
                    log.debug(LogUtils.COMBUS_MARKER, "Error sending reset message", jmex);
                    cleanupDestination(entry.getKey(), destination);
                }
            }
        }
    } catch (JMSException jmse) {
        throw new AnzoException(ExceptionConstants.COMBUS.PROCESS_UPDATE_FAILED, jmse);
    }
    //currentServerId = serviceContainer.getInstanceURI().toString();
}

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

/**
 * Handle an namedgraph update message from the model service
 * //from ww w . ja  v a 2 s  . com
 * @param context
 *            context of operation
 * @param session
 *            JMS session message came in over
 * @param message
 *            JMS Message containing update message stream
 * @throws AnzoException
 */
public void handleNamedgraphUpdateMessage(String operationid, INamedGraphUpdate update,
        Map<String, Object> updateMessage) throws AnzoException {
    try {
        if (trackers.isEmpty() && datasetTrackers.isEmpty() && namedGraphTrackers.isEmpty())
            return;
        NotificationUpdateHandler handler = new NotificationUpdateHandler(session, null);
        handler.handleNamedGraphUpdate(update);
        Collection<DestinationNamedgraphTracker> ngListeners = namedGraphTrackers.get(update.getUUID());
        if (ngListeners != null && !ngListeners.isEmpty()) {
            TextMessage textMessage = session.createTextMessage();
            textMessage.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
            setMessageProperties(textMessage, updateMessage);

            for (DestinationNamedgraphTracker ngt : ngListeners) {
                try {
                    getProducer().send(ngt.getDestination(), textMessage);
                } catch (JMSException jmex) {
                    log.warn(LogUtils.COMBUS_MARKER,
                            MessageFormat.format(
                                    Messages.getString(ExceptionConstants.COMBUS.SEND_MESSAGE_FAILED),
                                    ngt.getUserUri().toString()),
                            jmex);
                    cleanupDestination(ngt.getUserUri(), ngt.getDestination());
                }
            }
        }
    } catch (JMSException jmsex) {
        log.error(LogUtils.COMBUS_MARKER, "Error handling named graph update message", jmsex);
    }
}

From source file:org.wso2.carbon.appfactory.eventing.jms.AFMessageListener.java

@Override
public void onMessage(Message message) {
    if (log.isDebugEnabled()) {
        if (message instanceof MapMessage) {
            try {
                String messageBody = ((MapMessage) message).getString(TopicPublisher.MESSAGE_BODY);
                log.debug("Received a message:" + messageBody);
            } catch (JMSException e) {
                log.error("Error while getting message content.", e);
            }//from w w  w .  jav a 2s.co  m
        }
    }
    MapMessage mapMessage;
    if (message instanceof MapMessage) {
        mapMessage = (MapMessage) message;
        MessageStore.getInstance().addMessage(this.subscriptionId, mapMessage);
    } else if (message instanceof TextMessage) {
        //Todo:remove this. we only support mapMessages initially and below code is only for testing purpose.
        final TextMessage textMessage = (TextMessage) message;
        mapMessage = new MapMessage() {
            @Override
            public boolean getBoolean(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte getByte(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public short getShort(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public char getChar(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getInt(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getLong(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public float getFloat(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public double getDouble(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getString(String s) throws JMSException {
                return textMessage.getText();
            }

            @Override
            public byte[] getBytes(String s) throws JMSException {
                return new byte[0]; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Object getObject(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Enumeration getMapNames() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBoolean(String s, boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setByte(String s, byte b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setShort(String s, short i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setChar(String s, char c) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setInt(String s, int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setLong(String s, long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setFloat(String s, float v) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setDouble(String s, double v) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setString(String s, String s2) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBytes(String s, byte[] bytes) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBytes(String s, byte[] bytes, int i, int i2) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setObject(String s, Object o) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public boolean itemExists(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSMessageID() throws JMSException {
                return textMessage.getJMSMessageID();
            }

            @Override
            public void setJMSMessageID(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getJMSTimestamp() throws JMSException {
                return textMessage.getJMSTimestamp();
            }

            @Override
            public void setJMSTimestamp(long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
                return new byte[0]; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSCorrelationIDAsBytes(byte[] bytes) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSCorrelationID(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSCorrelationID() throws JMSException {
                return textMessage.getJMSCorrelationID();
            }

            @Override
            public Destination getJMSReplyTo() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSReplyTo(Destination destination) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Destination getJMSDestination() throws JMSException {
                return textMessage.getJMSDestination();
            }

            @Override
            public void setJMSDestination(Destination destination) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getJMSDeliveryMode() throws JMSException {
                return textMessage.getJMSDeliveryMode();
            }

            @Override
            public void setJMSDeliveryMode(int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public boolean getJMSRedelivered() throws JMSException {
                return textMessage.getJMSRedelivered();
            }

            @Override
            public void setJMSRedelivered(boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSType() throws JMSException {
                return textMessage.getJMSType();
            }

            @Override
            public void setJMSType(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getJMSExpiration() throws JMSException {
                return textMessage.getJMSExpiration();
            }

            @Override
            public void setJMSExpiration(long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getJMSPriority() throws JMSException {
                return textMessage.getJMSPriority();
            }

            @Override
            public void setJMSPriority(int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void clearProperties() throws JMSException {
                textMessage.clearProperties();
            }

            @Override
            public boolean propertyExists(String s) throws JMSException {
                return textMessage.propertyExists(s);
            }

            @Override
            public boolean getBooleanProperty(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte getByteProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public short getShortProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getIntProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getLongProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public float getFloatProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public double getDoubleProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getStringProperty(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Object getObjectProperty(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Enumeration getPropertyNames() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBooleanProperty(String s, boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setByteProperty(String s, byte b) throws JMSException {
                textMessage.setByteProperty(s, b);
            }

            @Override
            public void setShortProperty(String s, short i) throws JMSException {
                textMessage.setShortProperty(s, i);
            }

            @Override
            public void setIntProperty(String s, int i) throws JMSException {
                textMessage.setIntProperty(s, i);
            }

            @Override
            public void setLongProperty(String s, long l) throws JMSException {
                textMessage.setLongProperty(s, l);
            }

            @Override
            public void setFloatProperty(String s, float v) throws JMSException {
                textMessage.setFloatProperty(s, v);
            }

            @Override
            public void setDoubleProperty(String s, double v) throws JMSException {
                textMessage.setDoubleProperty(s, v);
            }

            @Override
            public void setStringProperty(String s, String s2) throws JMSException {
                textMessage.setStringProperty(s, s2);
            }

            @Override
            public void setObjectProperty(String s, Object o) throws JMSException {
                textMessage.setObjectProperty(s, o);
            }

            @Override
            public void acknowledge() throws JMSException {
                textMessage.acknowledge();
            }

            @Override
            public void clearBody() throws JMSException {
                textMessage.clearBody();
            }
        };
        MessageStore.getInstance().addMessage(this.subscriptionId, mapMessage);
    }

}