Example usage for javax.jms Message getStringProperty

List of usage examples for javax.jms Message getStringProperty

Introduction

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

Prototype


String getStringProperty(String name) throws JMSException;

Source Link

Document

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

Usage

From source file:org.fcrepo.jms.headers.DefaultMessageFactoryTest.java

private Message doTestBuildMessage(final String baseUrl, final String userAgent, final String id)
        throws RepositoryException, JMSException {
    final Long testDate = 46647758568747L;
    when(mockEvent.getDate()).thenReturn(testDate);

    String url = null;/*  w w  w .j a  v a  2 s . c  o  m*/
    if (!StringUtils.isBlank(baseUrl) || !StringUtils.isBlank(userAgent)) {
        url = "{\"baseURL\":\"" + baseUrl + "\",\"userAgent\":\"" + userAgent + "\"}";
    }
    when(mockEvent.getUserData()).thenReturn(url);
    final String testUser = "testUser";
    when(mockEvent.getUserID()).thenReturn(testUser);
    when(mockEvent.getPath()).thenReturn(id);
    final Set<Integer> testTypes = singleton(NODE_ADDED);
    final String testReturnType = REPOSITORY_NAMESPACE + EventType.valueOf(NODE_ADDED).toString();
    when(mockEvent.getTypes()).thenReturn(testTypes);
    final String prop = "test-property";
    when(mockEvent.getProperties()).thenReturn(singleton(prop));
    final String eventID = "abcdefg12345678";
    when(mockEvent.getEventID()).thenReturn(eventID);

    final Message msg = testDefaultMessageFactory.getMessage(mockEvent, mockSession);

    String trimmedBaseUrl = baseUrl;
    while (!StringUtils.isBlank(trimmedBaseUrl) && trimmedBaseUrl.endsWith("/")) {
        trimmedBaseUrl = trimmedBaseUrl.substring(0, trimmedBaseUrl.length() - 1);
    }

    assertEquals("Got wrong date in message!", testDate, (Long) msg.getLongProperty(TIMESTAMP_HEADER_NAME));
    assertEquals("Got wrong type in message!", testReturnType, msg.getStringProperty(EVENT_TYPE_HEADER_NAME));
    assertEquals("Got wrong base-url in message", trimmedBaseUrl, msg.getStringProperty(BASE_URL_HEADER_NAME));
    assertEquals("Got wrong property in message", prop, msg.getStringProperty(PROPERTIES_HEADER_NAME));
    assertEquals("Got wrong userID in message", testUser, msg.getStringProperty(USER_HEADER_NAME));
    assertEquals("Got wrong userAgent in message", userAgent, msg.getStringProperty(USER_AGENT_HEADER_NAME));
    assertEquals("Got wrong eventID in message", eventID, msg.getStringProperty(EVENT_ID_HEADER_NAME));
    return msg;
}

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  ww . j a v a2s.  c  om*/
            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.mule.transport.jms.filters.JmsPropertyFilter.java

public boolean accept(MuleMessage message) {
    if (StringUtils.isBlank(propertyName)) {
        logger.warn("No property name was specified");
        return false;
    }//w ww.j  a  v  a 2s  .c  o  m

    if (StringUtils.isBlank(expression) && pattern == null) {
        logger.warn("Either no expression or pattern was specified");
        return false;
    }

    if (message.getPayload() instanceof javax.jms.Message) {
        try {
            Message m = (javax.jms.Message) message.getPayload();

            if (StringUtils.isBlank(propertyClass)) {
                Object object = m.getObjectProperty(propertyName);
                if (object == null) {
                    return false;
                }
                String value = object.toString();

                if (pattern != null) {
                    return pattern.matcher(value).find();
                } else {
                    return value.equals(expression);
                }
            } else if (propertyClass.equals("java.lang.String")) {
                String value = m.getStringProperty(propertyName);
                if (value == null) {
                    return false;
                }

                if (pattern != null) {
                    return pattern.matcher(value).find();
                } else {
                    return value.equals(expression);
                }
            } else if (propertyClass.equals("java.lang.Integer")) {
                int value = m.getIntProperty(propertyName);
                int match = Integer.parseInt(expression);
                return (value == match);
            } else if (propertyClass.equals("java.lang.Short")) {
                short value = m.getShortProperty(propertyName);
                short match = Short.parseShort(expression);
                return (value == match);
            }
        } catch (NumberFormatException nfe) {
            logger.warn("Unable to convert expression " + expression + " to " + propertyClass + ": "
                    + nfe.toString());
        } catch (Exception e) {
            logger.warn("Error filtering on property " + propertyName + ": " + e.toString());
        }
    } else {
        logger.warn("Expected a payload of javax.jms.Message but instead received "
                + ClassUtils.getSimpleName(message.getPayload().getClass()));
    }

    return false;
}

From source file:org.mule.transport.jms.integration.JmsMessageAwareTransformersMule2685TestCase.java

@Test
public void testMessageAwareTransformerChainedWithObjectToJMSMessage() throws Exception {
    RequestContext.setEvent(getTestEvent("test"));

    MuleMessage message = new DefaultMuleMessage("This is a test TextMessage", muleContext);

    SetTestRecipientsTransformer trans = new SetTestRecipientsTransformer();
    MuleMessage result1 = (MuleMessage) trans.transform(message);

    // Check that transformer 1 set message property ok.
    assertEquals("vm://recipient1, vm://recipient1, vm://recipient3",
            result1.getOutboundProperty("recipients"));

    AbstractJmsTransformer trans2 = new SessionEnabledObjectToJMSMessage(session);
    Message result2 = (Message) trans2.transform(result1);

    // Test to see that ObjectToJMSMessage transformer transformed to JMS message
    // correctly/*from   w  w w .j  a  va2s .  co m*/
    assertTrue("Transformed object should be a TextMessage", result2 instanceof TextMessage);
    assertEquals("This is a test TextMessage", ((TextMessage) result2).getText());

    // Check to see if after the ObjectToJMSMessage transformer these properties
    // are on JMS message
    assertEquals("vm://recipient1, vm://recipient1, vm://recipient3", result2.getStringProperty("recipients"));

}

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

public void onMessage(final Message message) {
    if (message == null) {
        log.error(LogUtils.COMBUS_MARKER,
                Messages.formatString(ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "null message"),
                new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING));
        return;//from  ww  w.j  a  va 2s. c  o  m
    }
    try {
        if (log.isTraceEnabled()) {
            log.trace(LogUtils.COMBUS_MARKER, MessageUtils.prettyPrint(message, "Notification Recieved: "));
        }
        String operation = message.getStringProperty(SerializationConstants.operation);
        if (operation != null) {
            if (operation.equals(SerializationConstants.transactionComplete)) {
                handleTransactionMessage(message);
            } else if (SerializationConstants.updateResults.equals(operation)) {
                handleUpdateMessage(message);
            } else if (SerializationConstants.datasetUpdate.equals(operation)) {
                handleDatasetUpdateMessage(message);
            }
        }

    } catch (JMSException jmsex) {
        log.error(LogUtils.INTERNAL_MARKER, Messages.formatString(
                ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "realtime update message"), jmsex);
    } catch (AnzoException e) {
        log.error(LogUtils.INTERNAL_MARKER, Messages
                .formatString(ExceptionConstants.COMBUS.ERROR_PROCESSING_MESSGE, "realtime update message"), e);
    }

}

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

protected void handleUpdateMessage(Message message) throws AnzoException {
    try {/*from  w  w w. j av  a  2 s . co  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.client.RealtimeUpdateManager.java

protected void handleDatasetUpdateMessage(Message message) throws AnzoException {
    try {/*  www  . j av a 2 s. c  o m*/
        if (!message.propertyExists(SerializationConstants.datasetUri)) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        if (!message.propertyExists(SerializationConstants.namedGraphUri)) {
            throw new AnzoException(ExceptionConstants.COMBUS.JMS_MISSING_MESSAGE_PARAMETER);
        }
        String namedGraph = message.getStringProperty(SerializationConstants.namedGraphUri);
        String datasetUris = message.getStringProperty(SerializationConstants.datasetUri);
        Collection<URI> uris = new ArrayList<URI>();
        StringTokenizer st = new StringTokenizer(datasetUris, ",");
        while (st.hasMoreTokens()) {
            uris.add(Constants.valueFactory.createURI(st.nextToken()));
        }
        notifyTrackers(Constants.valueFactory.createURI(namedGraph), uris);
    } catch (JMSException jmsex) {
        throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, jmsex);
    }
}

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

protected void handleTransactionMessage(Message message) throws AnzoException {
    // Extract method and transactionId.
    String transactionContextString = null;
    try {/*www.j a  v  a 2 s.  c o m*/
        transactionContextString = message.propertyExists(SerializationConstants.transactionContext)
                ? message.getStringProperty(SerializationConstants.transactionContext)
                : null;
    } catch (JMSException e) {
        throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e);
    }
    String updatedNamedGraphs = null;
    try {
        updatedNamedGraphs = message.propertyExists(SerializationConstants.namedGraphUpdates)
                ? message.getStringProperty(SerializationConstants.namedGraphUpdates)
                : null;
    } catch (JMSException e) {
        throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e);
    }
    long timestamp = -1;
    try {
        timestamp = Long.valueOf(message.getLongProperty(SerializationConstants.transactionTimestamp));
    } catch (JMSException e) {
        throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e);
    }
    String transactionUri = null;
    try {
        transactionUri = message.propertyExists(SerializationConstants.transactionURI)
                ? message.getStringProperty(SerializationConstants.transactionURI)
                : null;
    } catch (JMSException e) {
        throw new AnzoException(ExceptionConstants.COMBUS.JMS_MESSAGE_PARSING, e);
    }
    URI transactionURI = (transactionUri != null) ? MemURI.create(transactionUri) : null;
    transactionLock.writeLock().lock();
    try {
        Collection<Statement> context = null;
        if (transactionContextString != null) {
            context = ReadWriteUtils.readStatements(transactionContextString, RDFFormat.JSON);
        }
        Map<URI, Long> updatedGraphs = null;
        if (updatedNamedGraphs != null) {
            updatedGraphs = CommonSerializationUtils.readNamedGraphRevisions(updatedNamedGraphs);
        }
        UpdateTransaction transaction = new UpdateTransaction(transactionURI, timestamp, context,
                updatedGraphs);
        notifyTransactionListeners(transaction);
    } finally {
        transactionLock.writeLock().unlock();
    }
}

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

protected AnzoPrincipal getContextPrincipal(IOperationContext context, Message request)
        throws JMSException, AnzoException {
    String uid = request.getStringProperty("JMSXUserID");
    AnzoPrincipal credentials = authenticationService.getUserPrincipal(context, uid);
    String runAsUser = request.getStringProperty(SerializationConstants.runAsUser);
    if (credentials != null && runAsUser != null) {
        if (!credentials.isSysadmin()) {
            throw new AnzoException(ExceptionConstants.COMBUS.RUNAS_NOT_AUTHORIZED);
        }/*from   www .ja v  a2  s.  co m*/
        credentials = authenticationService.getUserPrincipal(context, runAsUser);
    }
    return credentials;
}

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

private void processMessage(Message request) {
    try {/*  w  w  w.j a  v  a 2s.  co  m*/
        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);
    }
}