Example usage for javax.jms Message getBooleanProperty

List of usage examples for javax.jms Message getBooleanProperty

Introduction

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

Prototype


boolean getBooleanProperty(String name) throws JMSException;

Source Link

Document

Returns the value of the boolean property with the specified name.

Usage

From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java

public static void assertJmsProperties(Message jmsMsg) throws JMSException {
    assertEquals(STRING_VALUE, jmsMsg.getStringProperty(STRING_METADATA));
    assertEquals(BOOLEAN_VALUE, jmsMsg.getStringProperty(BOOLEAN_METADATA));
    assertEquals(Boolean.valueOf(BOOLEAN_VALUE).booleanValue(), jmsMsg.getBooleanProperty(BOOLEAN_METADATA)); // default
    assertEquals(INTEGER_VALUE, jmsMsg.getStringProperty(INTEGER_METADATA));
    assertEquals(Integer.valueOf(INTEGER_VALUE).intValue(), jmsMsg.getIntProperty(INTEGER_METADATA));
}

From source file:de.adorsys.jmspojo.JMSJavaFutureAdapterTest.java

@Before
public void setup() throws Exception {
    broker = new BrokerService();
    broker.setPersistent(false);//from  w  w  w  .ja va  2  s .  c  o  m

    // configure the broker
    broker.addConnector("vm://test");
    broker.setBrokerName("test");
    broker.setUseShutdownHook(false);

    broker.start();

    cf = new ActiveMQConnectionFactory("vm://localhost?create=false");
    qc = cf.createQueueConnection();
    QueueSession createQueueSession = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    testQueue = createQueueSession.createQueue("TestQueue");
    createQueueSession.createReceiver(testQueue).setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                boolean sendTimeout = message.getBooleanProperty("timeout");
                boolean sendError = message.getBooleanProperty("error");
                if (sendError) {
                    JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>(
                            objectMapper, cf, null, TIMEOUT);
                    HashMap<String, Object> messageProperties = new HashMap<String, Object>();
                    messageProperties.put("ERROR", "test error");
                    jmsSender.send(message.getJMSReplyTo(), messageProperties, null);
                } else if (!sendTimeout) {
                    JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>(
                            objectMapper, cf, null, TIMEOUT);
                    jmsSender.send(message.getJMSReplyTo(), null, ((TextMessage) message).getText());
                }

            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    });
    qc.start();

}

From source file:de.adorsys.jmspojo.JMSServiceAdapterFactoryTest.java

@Before
public void setup() throws Exception {
    broker = new BrokerService();
    broker.setPersistent(false);//w ww.  j a va  2 s. c o  m

    // configure the broker
    broker.addConnector("vm://test");
    broker.setBrokerName("test");
    broker.setUseShutdownHook(false);

    broker.start();

    cf = new ActiveMQConnectionFactory("vm://localhost?create=false");
    qc = cf.createQueueConnection();
    QueueSession createQueueSession = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    defaultQueue = createQueueSession.createQueue("TestQueue");
    createQueueSession.createReceiver(defaultQueue).setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                boolean sendTimeout = message.getBooleanProperty("timeout");
                if (!sendTimeout) {
                    JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>(
                            OBJECT_MAPPER, cf, null, JMS_TIMEOUT);
                    jmsSender.send(message.getJMSReplyTo(), null, ((TextMessage) message).getText());
                }
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    });

    dedicatedQueue = createQueueSession.createQueue("DedicatedQueue");
    createQueueSession.createReceiver(dedicatedQueue).setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                JMSJavaFutureAdapter<PingMessage> jmsSender = new JMSJavaFutureAdapter<PingMessage>(
                        OBJECT_MAPPER, cf, null, JMS_TIMEOUT);
                PingMessage data = new PingMessage();
                data.setPing("dedicted response");
                jmsSender.send(message.getJMSReplyTo(), null, data);
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    });
    qc.start();

    JMSServiceAdapterFactory jmsServiceStubFactory = new JMSServiceAdapterFactory(OBJECT_MAPPER, cf,
            defaultQueue, JMS_TIMEOUT);
    service = jmsServiceStubFactory.generateJMSServiceProxy(JMSSampleService.class);

}

From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java

public void testMoveMetadata_AdaptrisMessageToJmsMessage_WithFilter() throws Exception {

    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    MessageTypeTranslatorImp trans = createTranslator();
    RegexMetadataFilter regexp = new RegexMetadataFilter();
    regexp.addExcludePattern("IntegerMetadataKey");
    trans.setMetadataFilter(regexp);/*from  ww  w . j av a 2  s  .c om*/
    try {
        broker.start();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        start(trans, session);
        Message jmsMsg = trans.translate(msg);
        assertEquals(STRING_VALUE, jmsMsg.getStringProperty(STRING_METADATA));
        assertEquals(BOOLEAN_VALUE, jmsMsg.getStringProperty(BOOLEAN_METADATA));
        assertEquals(Boolean.valueOf(BOOLEAN_VALUE).booleanValue(),
                jmsMsg.getBooleanProperty(BOOLEAN_METADATA));
        assertNull(jmsMsg.getStringProperty(INTEGER_METADATA));
    } finally {
        stop(trans);
        broker.destroy();
    }
}

From source file:nl.knaw.huygens.timbuctoo.messages.Action.java

public static Action fromMessage(Message message, TypeRegistry typeRegistry) throws JMSException {
    ActionType actionType = getActionType(message);
    String requestId = message.getStringProperty(PROP_REQUEST_ID);

    boolean forMultiEntities = message.getBooleanProperty(PROP_FOR_MULTI_ENTITIES);

    String typeString = message.getStringProperty(PROP_ENTITY_TYPE);
    Class<? extends DomainEntity> type = typeRegistry.getDomainEntityType(typeString);

    if (forMultiEntities) {
        return forMultiEntities(actionType, type);
    }// www .j av  a  2 s  . com

    String id = message.getStringProperty(PROP_ENTITY_ID);

    return new Action(actionType, type, id);
}

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

/**
 * Extract transport level headers for JMS from the given message into a Map
 *
 * @param message the JMS message/*ww w .  j a  va 2s .c om*/
 * @return a Map of the transport headers
 */
public static Map<String, Object> getTransportHeaders(Message message) {
    // create a Map to hold transport headers
    Map<String, Object> map = new HashMap<String, Object>();

    // correlation ID
    try {
        if (message.getJMSCorrelationID() != null) {
            map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID());
        }
    } catch (JMSException ignore) {
    }

    // set the delivery mode as persistent or not
    try {
        map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode()));
    } catch (JMSException ignore) {
    }

    // destination name
    try {
        if (message.getJMSDestination() != null) {
            Destination dest = message.getJMSDestination();
            map.put(JMSConstants.JMS_DESTINATION,
                    dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }

    // expiration
    try {
        map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration()));
    } catch (JMSException ignore) {
    }

    // if a JMS message ID is found
    try {
        if (message.getJMSMessageID() != null) {
            map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }

    // priority
    try {
        map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority()));
    } catch (JMSException ignore) {
    }

    // redelivered
    try {
        map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered()));
    } catch (JMSException ignore) {
    }

    // replyto destination name
    try {
        if (message.getJMSReplyTo() != null) {
            Destination dest = message.getJMSReplyTo();
            map.put(JMSConstants.JMS_REPLY_TO,
                    dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }

    // priority
    try {
        map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp()));
    } catch (JMSException ignore) {
    }

    // message type
    try {
        if (message.getJMSType() != null) {
            map.put(JMSConstants.JMS_TYPE, message.getJMSType());
        }
    } catch (JMSException ignore) {
    }

    // any other transport properties / headers
    Enumeration<?> e = null;
    try {
        e = message.getPropertyNames();
    } catch (JMSException ignore) {
    }

    if (e != null) {
        while (e.hasMoreElements()) {
            String headerName = (String) e.nextElement();
            try {
                map.put(headerName, message.getStringProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getBooleanProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getIntProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getLongProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getDoubleProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, message.getFloatProperty(headerName));
            } catch (JMSException ignore) {
            }
        }
    }

    return map;
}

From source file:org.apache.synapse.transport.jms.JMSUtils.java

/**
 * Extract transport level headers for JMS from the given message into a Map
 *
 * @param message the JMS message/* w  w  w. j a v  a 2  s.  co  m*/
 * @return a Map of the transport headers
 */
public static Map getTransportHeaders(Message message) {
    // create a Map to hold transport headers
    Map map = new HashMap();

    // correlation ID
    try {
        if (message.getJMSCorrelationID() != null) {
            map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID());
        }
    } catch (JMSException ignore) {
    }

    // set the delivery mode as persistent or not
    try {
        map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode()));
    } catch (JMSException ignore) {
    }

    // destination name
    try {
        if (message.getJMSDestination() != null) {
            Destination dest = message.getJMSDestination();
            map.put(JMSConstants.JMS_DESTINATION,
                    dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }

    // expiration
    try {
        map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration()));
    } catch (JMSException ignore) {
    }

    // if a JMS message ID is found
    try {
        if (message.getJMSMessageID() != null) {
            map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID());
        }
    } catch (JMSException ignore) {
    }

    // priority
    try {
        map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority()));
    } catch (JMSException ignore) {
    }

    // redelivered
    try {
        map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered()));
    } catch (JMSException ignore) {
    }

    // replyto destination name
    try {
        if (message.getJMSReplyTo() != null) {
            Destination dest = message.getJMSReplyTo();
            map.put(JMSConstants.JMS_REPLY_TO,
                    dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName());
        }
    } catch (JMSException ignore) {
    }

    // priority
    try {
        map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp()));
    } catch (JMSException ignore) {
    }

    // message type
    try {
        if (message.getJMSType() != null) {
            map.put(JMSConstants.JMS_TYPE, message.getJMSType());
        }
    } catch (JMSException ignore) {
    }

    // any other transport properties / headers
    Enumeration e = null;
    try {
        e = message.getPropertyNames();
    } catch (JMSException ignore) {
    }

    if (e != null) {
        while (e.hasMoreElements()) {
            String headerName = (String) e.nextElement();
            try {
                map.put(headerName, message.getStringProperty(headerName));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, Boolean.valueOf(message.getBooleanProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, new Integer(message.getIntProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, new Long(message.getLongProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, new Double(message.getDoubleProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
            try {
                map.put(headerName, new Float(message.getFloatProperty(headerName)));
                continue;
            } catch (JMSException ignore) {
            }
        }
    }

    return map;
}

From source file:org.jwebsocket.plugins.scripting.ScriptingPlugIn.java

@Override
public void systemStarted() throws Exception {
    // initializing apps
    Map<String, String> lApps = mSettings.getApps();
    for (String lAppName : lApps.keySet()) {
        try {/*from w  w  w .  j  av  a  2s. co m*/
            execAppBeforeLoadChecks(lAppName, lApps.get(lAppName));
            loadApp(lAppName, lApps.get(lAppName), false);
        } catch (Exception lEx) {
            mLog.error(Logging.getSimpleExceptionMessage(lEx, "loading '" + lAppName + "' application"));
        }
    }

    notifyToApps(BaseScriptApp.EVENT_SYSTEM_STARTED, new Object[0]);
    try {
        // registering on message hub if running on a cluster
        getServer().getJMSManager().subscribe(new MessageListener() {

            @Override
            public void onMessage(Message aMessage) {
                try {
                    // discard processing if the message comes from the current server node
                    if (JWebSocketConfig.getConfig().getNodeId()
                            .equals(aMessage.getStringProperty(Attributes.NODE_ID))) {
                        return;
                    }

                    ClusterMessageTypes lType = ClusterMessageTypes
                            .valueOf(aMessage.getStringProperty(Attributes.MESSAGE_TYPE));
                    switch (lType) {
                    case LOAD_APP: {
                        String lAppName = aMessage.getStringProperty("appName");
                        Boolean lHotLoad = aMessage.getBooleanProperty("hotLoad");
                        String lPath = mSettings.getApps().get(lAppName);

                        // loading app
                        loadApp(lAppName, lPath, lHotLoad);
                        break;
                    }
                    case UNDEPLOY_APP: {
                        String lAppName = aMessage.getStringProperty("appName");
                        // validating
                        BaseScriptApp lScriptApp = mApps.get(lAppName);

                        // notifying event before undeploy
                        lScriptApp.notifyEvent(BaseScriptApp.EVENT_UNDEPLOYING, new Object[0]);

                        // deleting app
                        mApps.remove(lAppName);
                        FileUtils.deleteDirectory(new File(lScriptApp.getPath()));
                        break;
                    }
                    }
                } catch (Exception lEx) {
                    mLog.error(Logging.getSimpleExceptionMessage(lEx,
                            "processing cluster message: " + aMessage.toString()));
                }
            }
        }, "ns = '" + NS + "'");
    } catch (Exception aException) {
        mLog.error("Exception catched while getting the JMS Manager instance with the following message: "
                + aException.getMessage());
    }

    if (mLog.isDebugEnabled()) {
        mLog.debug("Scripting plug-in finished startup process!");
    }
}

From source file:org.openanzo.client.RealtimeUpdateManager.java

protected void handleUpdateMessage(Message message) throws AnzoException {
    try {/*from   w ww  .  j  av a  2s  .  c o  m*/
        if (!message.propertyExists(SerializationConstants.method)) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        if (!message.propertyExists(SerializationConstants.subject)) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        if (!message.propertyExists(SerializationConstants.predicate)) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        if (!message.propertyExists(SerializationConstants.namedGraphUri)) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        if (!message.propertyExists(SerializationConstants.object)) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        boolean method = message.getBooleanProperty(SerializationConstants.method);
        // Extract statement info from message.
        String predicateUri = message.getStringProperty(SerializationConstants.predicate);
        String namedGraph = message.getStringProperty(SerializationConstants.namedGraphUri);

        // Construct  statement.
        Value object = CommonSerializationUtils.getObjectFromMessage(message);
        if (object == null) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        Resource subject = CommonSerializationUtils.getSubjectFromMessage(message);
        if (subject == null) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        URI predicate = Constants.valueFactory.createURI(predicateUri);
        URI namedGraphUri = Constants.valueFactory.createURI(namedGraph);
        URI graphURI = namedGraphUri;
        Statement stmt = Constants.valueFactory.createStatement(subject, predicate, object, graphURI);
        notifyTrackers(method, stmt);
    } catch (JMSException jmsex) {
        throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, jmsex);
    }
}

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

public void onMessage(Message message) {

    if (started) {
        try {//w  w w.  ja  v a2  s . c o  m
            if (threadPool != null) {
                if (message.propertyExists(SerializationConstants.bypassPool)
                        && message.getBooleanProperty(SerializationConstants.bypassPool)) {
                    processMessage(message);
                } else {
                    if (message.getJMSPriority() < 4) {
                        while (threadPool.getNumActive() >= threadPool.getMaxActive()
                                || (highActive > (threadPool.getNumActive() / 2) && lowActive > 1)) {
                            synchronized (threadPool) {
                                threadPool.wait();
                            }
                        }
                        ProcessThread pt = (ProcessThread) threadPool.borrowObject();
                        pt.setRequest(message, false);

                    } else {
                        ProcessThread pt = (ProcessThread) threadPool.borrowObject();
                        pt.setRequest(message, true);
                    }
                }
            } else {
                processMessage(message);
            }
        } catch (Throwable jmex) {
            log.error(LogUtils.COMBUS_MARKER, "Error in BaseService Listener's process thread loop", jmex);
        }
    }
}