Search in sources :

Example 1 with MyRoleMessageExchange

use of org.apache.ode.bpel.iapi.MyRoleMessageExchange in project carbon-business-process by wso2.

the class BPELProcessProxy method onAxisServiceInvoke.

public final void onAxisServiceInvoke(final BPELMessageContext bpelMessageContext) throws AxisFault {
    boolean success = true;
    MyRoleMessageExchange odeMessageExchange = null;
    Future responseFuture = null;
    // Used to handle exception loosing in when exception occurred
    // inside finally block.
    Exception cachedException = null;
    try {
        transactionManager.begin();
        if (log.isDebugEnabled()) {
            log.debug("Starting Transaction.");
        }
        odeBpelServer.acquireTransactionLocks();
        odeMessageExchange = createMessageExchange(bpelMessageContext.getInMessageContext());
        if (odeMessageExchange.getOperation() != null) {
            responseFuture = invokeBPELProcessThroughODEMessageExchange(odeMessageExchange, bpelMessageContext);
            success = commitODEMessageExchange(odeMessageExchange);
        } else {
            success = false;
        }
    } catch (Exception e) {
        cachedException = e;
        success = false;
        handleExceptionAtODEInvocation(e);
    } finally {
        if (!success) {
            releaseODEMessageExchangeAndRollbackTransaction(odeMessageExchange, cachedException, success);
        }
    }
    if (odeMessageExchange.getOperation().getOutput() != null) {
        waitForTheResponse(responseFuture, odeMessageExchange);
        if (bpelMessageContext.getOutMessageContext() != null) {
            if (log.isDebugEnabled()) {
                log.debug("Handling response for MEX " + odeMessageExchange);
            }
            setOutMessageContextSOAPEnvelope(bpelMessageContext);
            boolean commit = false;
            beginTransactionForTheResponsePath();
            try {
                // Refreshing the message exchange
                odeMessageExchange = (MyRoleMessageExchange) odeBpelServer.getEngine().getMessageExchange(odeMessageExchange.getMessageExchangeId());
                onResponse(bpelMessageContext, odeMessageExchange, bpelMessageContext.getOutMessageContext());
                // Everything went well. So we can commit the transaction now.
                commit = true;
            } catch (AxisFault af) {
                cachedException = af;
                log.warn("MEX produced a fault " + odeMessageExchange, af);
                commit = true;
                throw af;
            } catch (Exception e) {
                cachedException = e;
                log.error("Error processing response for MEX " + odeMessageExchange, e);
                throw new BPELFault("An exception occurred when invoking ODE.", e);
            } finally {
                try {
                    odeMessageExchange.release(commit);
                } finally {
                    if (commit) {
                        commitTransactionForTheResponsePath(cachedException);
                    } else {
                        rollbackTransactionForTheResponsePath(cachedException);
                    }
                }
            }
        }
        if (!success) {
            throw new BPELFault("Message was either un-routable or timed out!");
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) MyRoleMessageExchange(org.apache.ode.bpel.iapi.MyRoleMessageExchange) Future(java.util.concurrent.Future)

Example 2 with MyRoleMessageExchange

use of org.apache.ode.bpel.iapi.MyRoleMessageExchange in project carbon-business-process by wso2.

the class BPELProcessProxy method createMessageExchange.

private MyRoleMessageExchange createMessageExchange(final MessageContext inMessageContext) {
    Integer tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    MyRoleMessageExchange messageExchange;
    String messageId = new GUID().toString();
    messageExchange = odeBpelServer.getEngine().createMessageExchange("" + messageId, serviceName, inMessageContext.getAxisOperation().getName().getLocalPart(), null, tenantId.toString());
    if (log.isDebugEnabled()) {
        log.debug("ODE routed to portType " + messageExchange.getPortType() + " operation " + messageExchange.getOperation() + " from service " + serviceName);
    }
    messageExchange.setProperty("isTwoWay", Boolean.toString(inMessageContext.getAxisOperation() instanceof TwoChannelAxisOperation));
    return messageExchange;
}
Also used : MyRoleMessageExchange(org.apache.ode.bpel.iapi.MyRoleMessageExchange) TwoChannelAxisOperation(org.apache.axis2.description.TwoChannelAxisOperation) GUID(org.apache.ode.utils.GUID)

Aggregations

MyRoleMessageExchange (org.apache.ode.bpel.iapi.MyRoleMessageExchange)2 Future (java.util.concurrent.Future)1 AxisFault (org.apache.axis2.AxisFault)1 TwoChannelAxisOperation (org.apache.axis2.description.TwoChannelAxisOperation)1 GUID (org.apache.ode.utils.GUID)1