AxisOperation axisAnonymousOperation = anoymousService.getOperation(
outOnlyMessage ?
new QName(AnonymousServiceFactory.OUT_ONLY_OPERATION) :
new QName(AnonymousServiceFactory.OUT_IN_OPERATION));
Options clientOptions = MessageHelper.cloneOptions(originalInMsgCtx.getOptions());
clientOptions.setUseSeparateListener(separateListener);
// if RM is requested,
if (wsRMEnabled) {
// if a WS-RM policy is specified, use it
if (wsRMPolicyKey != null) {
Object property = synapseOutMessageContext.getEntry(wsRMPolicyKey);
if (property instanceof OMElement) {
OMElement policyOMElement = (OMElement) property;
RMAssertionBuilder builder = new RMAssertionBuilder();
SandeshaPolicyBean sandeshaPolicyBean = (SandeshaPolicyBean) builder.build(policyOMElement, null);
Parameter policyParam = new Parameter(Sandesha2Constants.SANDESHA_PROPERTY_BEAN, sandeshaPolicyBean);
anoymousService.addParameter(policyParam);
}
}
}
// if security is enabled,
if (wsSecurityEnabled) {
// if a WS-Sec policy is specified, use it
if (wsSecPolicyKey != null) {
clientOptions.setProperty(
SynapseConstants.RAMPART_POLICY,
MessageHelper.getPolicy(synapseOutMessageContext, wsSecPolicyKey));
} else {
if (inboundWsSecPolicyKey != null) {
clientOptions.setProperty(SynapseConstants.RAMPART_IN_POLICY,
MessageHelper.getPolicy(
synapseOutMessageContext, inboundWsSecPolicyKey));
}
if (outboundWsSecPolicyKey != null) {
clientOptions.setProperty(SynapseConstants.RAMPART_OUT_POLICY,
MessageHelper.getPolicy(
synapseOutMessageContext, outboundWsSecPolicyKey));
}
}
// temporary workaround for https://issues.apache.org/jira/browse/WSCOMMONS-197
if (axisOutMsgCtx.getEnvelope().getHeader() == null) {
SOAPFactory fac = axisOutMsgCtx.isSOAP11() ?
OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory();
fac.createSOAPHeader(axisOutMsgCtx.getEnvelope());
}
}
OperationClient mepClient = axisAnonymousOperation.createClient(serviceCtx, clientOptions);
mepClient.addMessageContext(axisOutMsgCtx);
axisOutMsgCtx.setAxisMessage(
axisAnonymousOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE));
// set the SEND_TIMEOUT for transport sender
if (endpoint != null && endpoint.getTimeoutDuration() > 0) {
axisOutMsgCtx.setProperty(SynapseConstants.SEND_TIMEOUT, endpoint.getTimeoutDuration());
}
if (!outOnlyMessage) {
// always set a callback as we decide if the send it blocking or non blocking within
// the MEP client. This does not cause an overhead, as we simply create a 'holder'
// object with a reference to the outgoing synapse message context
// synapseOutMessageContext
AsyncCallback callback = new AsyncCallback(synapseOutMessageContext);
if (endpoint != null) {
// set the timeout time and the timeout action to the callback, so that the
// TimeoutHandler can detect timed out callbacks and take approprite action.
callback.setTimeOutOn(System.currentTimeMillis() + endpoint.getTimeoutDuration());
callback.setTimeOutAction(endpoint.getTimeoutAction());
} else {
callback.setTimeOutOn(System.currentTimeMillis());
}
mepClient.setCallback(callback);
}
// this is a temporary fix for converting messages from HTTP 1.1 chunking to HTTP 1.0.
// Without this HTTP transport can block & become unresponsive because we are streaming
// HTTP 1.1 messages and HTTP 1.0 require the whole message to caculate the content length
if (originalInMsgCtx.isPropertyTrue(NhttpConstants.FORCE_HTTP_1_0)) {
synapseOutMessageContext.getEnvelope().toString();
}
// with the nio transport, this causes the listener not to write a 202
// Accepted response, as this implies that Synapse does not yet know if
// a 202 or 200 response would be written back.
originalInMsgCtx.getOperationContext().setProperty(
org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
// if the transport out is explicitly set use it
Object o = originalInMsgCtx.getProperty("TRANSPORT_OUT_DESCRIPTION");
if (o != null && o instanceof TransportOutDescription) {
axisOutMsgCtx.setTransportOut((TransportOutDescription) o);
clientOptions.setTransportOut((TransportOutDescription) o);
clientOptions.setProperty("TRANSPORT_OUT_DESCRIPTION", o);
}
mepClient.execute(true);
if (wsRMEnabled) {
Object rm11 = clientOptions.getProperty(SandeshaClientConstants.RM_SPEC_VERSION);
if ( (rm11 != null) && rm11.equals(Sandesha2Constants.SPEC_VERSIONS.v1_1)){
ServiceClient serviceClient = new ServiceClient(
axisOutMsgCtx.getConfigurationContext(), axisOutMsgCtx.getAxisService());
serviceClient.setTargetEPR(
new EndpointReference(endpoint.getAddress(synapseOutMessageContext)));