Example usage for javax.jms BytesMessage getObjectProperty

List of usage examples for javax.jms BytesMessage getObjectProperty

Introduction

In this page you can find the example usage for javax.jms BytesMessage getObjectProperty.

Prototype


Object getObjectProperty(String name) throws JMSException;

Source Link

Document

Returns the value of the Java object property with the specified name.

Usage

From source file:org.exist.replication.jms.obsolete.FileSystemListener.java

private eXistMessage convertMessage(BytesMessage bm) {
    eXistMessage em = new eXistMessage();

    try {//ww w.  j  ava2  s.c  o m
        Enumeration e = bm.getPropertyNames();
        while (e.hasMoreElements()) {
            Object next = e.nextElement();
            if (next instanceof String) {
                em.getMetadata().put((String) next, bm.getObjectProperty((String) next));
            }
        }

        String value = bm.getStringProperty(eXistMessage.EXIST_RESOURCE_TYPE);
        eXistMessage.ResourceType resourceType = eXistMessage.ResourceType.valueOf(value);
        em.setResourceType(resourceType);

        value = bm.getStringProperty(eXistMessage.EXIST_RESOURCE_OPERATION);
        eXistMessage.ResourceOperation changeType = eXistMessage.ResourceOperation.valueOf(value);
        em.setResourceOperation(changeType);

        value = bm.getStringProperty(eXistMessage.EXIST_SOURCE_PATH);
        em.setResourcePath(value);

        value = bm.getStringProperty(eXistMessage.EXIST_DESTINATION_PATH);
        em.setDestinationPath(value);

        long size = bm.getBodyLength();
        LOG.debug("actual length=" + size);

        // This is potentially memory intensive
        byte[] payload = new byte[(int) size];
        bm.readBytes(payload);
        em.setPayload(payload);

    } catch (JMSException ex) {
        LOG.error(ex);
    }

    return em;

}

From source file:org.jbpm.process.workitem.jms.JMSSignalReceiver.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from  w w w .  j  a v a  2s  . co  m*/
public void onMessage(Message message) {
    if (message instanceof BytesMessage) {

        String deploymentId;
        Long processInstanceId;
        String signal;
        Long workItemId;

        Object data;

        BytesMessage bytesMessage = (BytesMessage) message;

        RuntimeManager runtimeManager = null;
        RuntimeEngine engine = null;
        try {
            deploymentId = (String) bytesMessage.getObjectProperty("KIE_SignalDeploymentId");
            if (deploymentId == null) {
                deploymentId = (String) bytesMessage.getObjectProperty("KIE_DeploymentId");
            }
            signal = (String) bytesMessage.getObjectProperty("KIE_Signal");
            processInstanceId = (Long) bytesMessage.getObjectProperty("KIE_SignalProcessInstanceId");
            workItemId = (Long) bytesMessage.getObjectProperty("KIE_SignalWorkItemId");

            logger.debug("Deployment id '{}', signal '{}', processInstanceId '{}', workItemId '{}'",
                    deploymentId, signal, processInstanceId, workItemId);

            runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId);

            if (runtimeManager == null) {
                throw new IllegalStateException("There is no runtime manager for deployment " + deploymentId);
            }
            logger.debug(
                    "RuntimeManager found for deployment id {}, reading message content with custom class loader of the deployment",
                    deploymentId);
            data = readData(bytesMessage,
                    ((InternalRuntimeManager) runtimeManager).getEnvironment().getClassLoader());
            logger.debug("Data read successfully with output {}", data);
            engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));

            // perform operation either signal or complete work item
            if (workItemId != null) {
                Map<String, Object> results = new HashMap<String, Object>();
                if (data != null) {
                    if (data instanceof Map) {
                        results.putAll((Map) data);
                    } else {
                        results.put("Data", data);
                    }
                }
                logger.debug("About to complete work item with id {} and data {}", workItemId, results);
                engine.getKieSession().getWorkItemManager().completeWorkItem(workItemId, results);
                logger.debug("Successfully completed work item with id {}", workItemId);
            } else if (signal != null) {
                if (processInstanceId != null) {
                    logger.debug("About to signal process instance with id {} and event data {} with signal {}",
                            processInstanceId, data, signal);
                    engine.getKieSession().signalEvent(signal, data, processInstanceId);
                } else {
                    logger.debug("About to broadcast signal {} and event data {}", signal, data);
                    runtimeManager.signalEvent(signal, data);
                }
                logger.debug("Signal completed successfully for signal {} with data {}", signal, data);
            } else {
                logger.warn("No signal or workitem id is given, skipping this message");
            }

        } catch (Exception e) {
            logger.error("Unexpected exception while processing signal JMS message: {}", e.getMessage(), e);
        } finally {
            if (runtimeManager != null && engine != null) {
                runtimeManager.disposeRuntimeEngine(engine);
            }
        }

    }
}