Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: ProcessMessageReceiver.java 19483 2010-09-09 12:07:12Z tcarlson $
   * --------------------------------------------------------------------------------------
   * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
   *
   * The software in this package is published under the terms of the CPAL v1.0
   * license, a copy of which has been included with this distribution in the
   * LICENSE.txt file.
   */
 
 package org.mule.transport.bpm;
 
 
 import java.util.Map;
 
 import  javax.resource.spi.work.Work;
 import  javax.resource.spi.work.WorkException;

Generates an incoming Mule event from an executing workflow process.
 
 {
 
     private ProcessConnector connector = null;
 
     public ProcessMessageReceiver(Connector connectorFlowConstruct flowConstructInboundEndpoint endpoint)
             throws CreateException
     {
         super(connectorflowConstructendpoint);
         this. = (ProcessConnectorconnector;
     }
 
     public MuleMessage generateSynchronousEvent(String endpointObject payloadMap messagePropertiesthrows MuleException
     {
         .debug("Executing process is sending an event (synchronously) to Mule endpoint = " + endpoint);
         MuleMessage response = generateEvent(endpointpayloadmessageProperties
             .);
         if (.isDebugEnabled())
         {
             .debug("Synchronous response is " + (response != null ? response.getPayload() : null));
         }
         return response;
     }
 
     public void generateAsynchronousEvent(String endpointObject payloadMap messagePropertiesthrows MuleException, WorkException
     {
         .debug("Executing process is dispatching an event (asynchronously) to Mule endpoint = " + endpoint);
         WorkManager workManager = getWorkManager();
         if (workManager != null)
         {
             workManager.scheduleWork(new Worker(endpointpayloadmessageProperties));
         }
         else
         {
             throw new ConnectorException(MessageFactory.createStaticMessage("WorkManager not available"), getConnector());
         }
     }
 
     protected MuleMessage generateEvent(String endpointObject payloadMap messagePropertiesMessageExchangePattern exchangePatternthrows MuleException
     {
         MuleMessage message;
         if (payload instanceof MuleMessage)
         {
             message = (MuleMessagepayload;
         }
         else
         {
             message = createMuleMessage(payloadthis..getEncoding());
         }
         message.addProperties(messageProperties.);
         message.addProperties(messageProperties.);
 
         //TODO should probably cache this
         EndpointBuilder endpointBuilder = .getMuleContext().getRegistry().lookupEndpointFactory().getEndpointBuilder(endpoint);
         endpointBuilder.setExchangePattern(exchangePattern);
         OutboundEndpoint ep = endpointBuilder.buildOutboundEndpoint();
        
         DefaultMuleEvent event = new DefaultMuleEvent(messageepnew DefaultMuleSession(.getMuleContext()));
 
         // Set correlation properties in SESSION scope so that they get propagated to response messages.
         RequestContext.setEvent(event);
         if (messageProperties.get(.) != null)
        {
        }
        if (messageProperties.get(.) != null)
        {
        }
        
        MuleEvent resultEvent = ep.process(event);
        
        MuleMessage response = null;
        if (resultEvent != null)
        {
            response = resultEvent.getMessage();
            if (response.getExceptionPayload() != null)
            {
                throw new ConnectorException(MessageFactory.createStaticMessage("Unable to send or route message"), getConnector(), response.getExceptionPayload().getRootException());
            }
        }
        
        return response;
    }
    private class Worker implements Work
    {
        private String endpoint;
        private Object payload;
        private Map messageProperties;
        public Worker(String endpointObject payloadMap messageProperties)
        {
            this. = endpoint;
            this. = payload;
            this. = messageProperties;
        }
        public void run()
        {
            try
            {
            }
            catch (Exception e)
            {
                getConnector().getMuleContext().getExceptionListener().handleException(e);
            }
        }
        public void release()
        { /*nop*/ }
    }
New to GrepCode? Check out our FAQ X