Element outboundMsg;
try {
outboundMsg = setupOutbound(_oinvoke, _oinvoke.initCorrelationsInput);
} catch (FaultException e) {
__log.error(e);
FaultData fault = createFault(e.getQName(), _oinvoke);
_self.parent.completed(fault, CompensationHandler.emptySet());
return;
}
++_invoked;
// if there is no output variable, then this is a one-way invoke
boolean isTwoWay = _oinvoke.outputVar != null;
try {
if (!isTwoWay) {
FaultData faultData = null;
getBpelRuntimeContext().invoke(
_scopeFrame.resolve(_oinvoke.partnerLink),
_oinvoke.operation, outboundMsg, null);
_self.parent.completed(faultData, CompensationHandler.emptySet());
} else /* two-way */{
final VariableInstance outputVar = _scopeFrame.resolve(_oinvoke.outputVar);
InvokeResponseChannel invokeResponseChannel = newChannel(InvokeResponseChannel.class);
final String mexId = getBpelRuntimeContext().invoke(
_scopeFrame.resolve(_oinvoke.partnerLink), _oinvoke.operation,
outboundMsg, invokeResponseChannel);
object(new InvokeResponseChannelListener(invokeResponseChannel) {
private static final long serialVersionUID = 4496880438819196765L;
public void onResponse() {
// we don't have to write variable data -> this already
// happened in the nativeAPI impl
FaultData fault = null;
Element response;
try {
response = getBpelRuntimeContext().getPartnerResponse(mexId);
} catch (Exception e) {
__log.error(e);
// TODO: Better error handling
throw new RuntimeException(e);
}
getBpelRuntimeContext().initializeVariable(outputVar, response);
try {
for (OScope.CorrelationSet anInitCorrelationsOutput : _oinvoke.initCorrelationsOutput) {
initializeCorrelation(_scopeFrame.resolve(anInitCorrelationsOutput), outputVar);
}
if (_oinvoke.partnerLink.hasPartnerRole()) {
// Trying to initialize partner epr based on a message-provided epr/session.
if (!getBpelRuntimeContext().isPartnerRoleEndpointInitialized(_scopeFrame
.resolve(_oinvoke.partnerLink)) || !_oinvoke.partnerLink.initializePartnerRole) {
Node fromEpr = getBpelRuntimeContext().getSourceEPR(mexId);
if (fromEpr != null) {
getBpelRuntimeContext().writeEndpointReference(
_scopeFrame.resolve(_oinvoke.partnerLink), (Element) fromEpr);
}
}
String partnersSessionId = getBpelRuntimeContext().getSourceSessionId(mexId);
if (partnersSessionId != null)
getBpelRuntimeContext().initializePartnersSessionId(_scopeFrame.resolve(_oinvoke.partnerLink),
partnersSessionId);
}
} catch (FaultException e) {
fault = createFault(e.getQName(), _oinvoke);
}
// TODO update output variable with data from non-initiate
// correlation sets
getBpelRuntimeContext().releasePartnerMex(mexId);
_self.parent.completed(fault, CompensationHandler.emptySet());
}
public void onFault() {
QName faultName = getBpelRuntimeContext().getPartnerFault(mexId);
Element msg = getBpelRuntimeContext().getPartnerResponse(mexId);
QName msgType = getBpelRuntimeContext().getPartnerResponseType(mexId);
FaultData fault = createFault(faultName, msg,
_oinvoke.getOwner().messageTypes.get(msgType), _self.o);
_self.parent.completed(fault, CompensationHandler.emptySet());
}
public void onFailure() {
// This indicates a communication failure. We don't throw a fault,
// because there is no fault, instead we'll re-incarnate the invoke
// and either retry or indicate failure condition.
// admin to resume the process.
_self.parent.failure(getBpelRuntimeContext().getPartnerFaultExplanation(mexId), null);
}
});
}
} catch (FaultException fault) {
__log.error(fault);
FaultData faultData = createFault(fault.getQName(), _oinvoke, fault.getMessage());
_self.parent.completed(faultData, CompensationHandler.emptySet());
}
}