public static String sendSOAP( EndpointReference soapEPR, String requestString, String action, String operation) throws Exception { ServiceClient sender = PmServiceClient.getServiceClient(); OperationClient operationClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP); // creating message context MessageContext outMsgCtx = new MessageContext(); // assigning message context's option object into instance variable Options opts = outMsgCtx.getOptions(); // setting properties into option log.debug(soapEPR); opts.setTo(soapEPR); opts.setAction(action); opts.setTimeOutInMilliSeconds(180000); log.debug(requestString); SOAPEnvelope envelope = null; try { SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); envelope = fac.getDefaultEnvelope(); OMNamespace omNs = fac.createOMNamespace( "http://rpdr.partners.org/", //$NON-NLS-1$ "rpdr"); //$NON-NLS-1$ // creating the SOAP payload OMElement method = fac.createOMElement(operation, omNs); OMElement value = fac.createOMElement("RequestXmlString", omNs); // $NON-NLS-1$ value.setText(requestString); method.addChild(value); envelope.getBody().addChild(method); } catch (FactoryConfigurationError e) { log.error(e.getMessage()); throw new Exception(e); } outMsgCtx.setEnvelope(envelope); operationClient.addMessageContext(outMsgCtx); operationClient.execute(true); MessageContext inMsgtCtx = operationClient.getMessageContext("In"); // $NON-NLS-1$ SOAPEnvelope responseEnv = inMsgtCtx.getEnvelope(); OMElement soapResponse = responseEnv.getBody().getFirstElement(); // System.out.println("Sresponse: "+ soapResponse.toString()); OMElement soapResult = soapResponse.getFirstElement(); // System.out.println("Sresult: "+ soapResult.toString()); String i2b2Response = soapResult.getText(); log.debug(i2b2Response); return i2b2Response; }
/** * Called by execute(OperationClient) to perform pre-execute tasks. * * @param opClient * @param block - Indicates if blocking or non-blocking execute * @param msgContext - Axis2 MessageContext */ private void preExecute( OperationClient opClient, boolean block, org.apache.axis2.context.MessageContext msgContext) throws AxisFault { // This assumes that we are on the ultimate execution thread // This has to be here so the ThreadContextMigrator can pick it up. msgContext.getOptions().setUseSeparateListener(opClient.getOptions().isUseSeparateListener()); ThreadContextMigratorUtil.performMigrationToContext( Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID, msgContext); // Enable the ThreadContextMigrator to override UseSeparateListener opClient.getOptions().setUseSeparateListener(msgContext.getOptions().isUseSeparateListener()); if (log.isDebugEnabled()) { log.debug("Start OperationClient.execute(" + block + ")"); log.debug("UseSeparateListener: " + opClient.getOptions().isUseSeparateListener()); } }
/** @param synCtx */ public void evaluate(MessageContext synCtx) { String result; if (value != null) { result = value; } else if (expression != null) { result = expression.stringValueOf(synCtx); } else { throw new SynapseException("A value or expression must be specified"); } if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) { synCtx.setProperty(name, result); } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) { // Setting property into the Axis2 Message Context Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.setProperty(name, result); } else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope)) { // Setting property into the Axis2 Message Context client options Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.getOptions().setProperty(name, result); } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) { // Setting Transport Headers Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null && headers instanceof Map) { Map headersMap = (Map) headers; headersMap.put(name, result); } if (headers == null) { Map headersMap = new HashMap(); headersMap.put(name, result); axis2MessageCtx.setProperty( org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap); } } }
private void initOperationClient(OperationClient opClient, MessageContext requestMsgCtx) { org.apache.axis2.context.MessageContext axisRequest = requestMsgCtx.getAxisMessageContext(); setupProperties(requestMsgCtx); // , axisRequest.getOptions()); if (opClient != null) { Options options = opClient.getOptions(); // Get the target endpoint address and setup the TO endpoint // reference. This tells us where the request is going. EndpointReference toEPR = axisRequest.getTo(); if (toEPR == null) { String targetUrl = (String) requestMsgCtx.getProperty(BindingProvider.ENDPOINT_ADDRESS_PROPERTY); toEPR = new EndpointReference(targetUrl); } options.setTo(toEPR); // Get the SOAP Action (if needed) String soapAction = ClientUtils.findSOAPAction(requestMsgCtx); options.setAction(soapAction); // get the timeout from the request message context options as it may have been // set by the user; if it was not set by the user we will just be setting the // timeout on the operation client to the default so it will not have a negative // effect; this logic is reliant on the fact the JAX-WS MessageContext is delegating // to the Axis2 Options object and not storing its own property bag long timeout = axisRequest.getOptions().getTimeOutInMilliSeconds(); options.setTimeOutInMilliSeconds(timeout); // Use the OperationClient to send the request and put the contents // of the response in the response MessageContext. try { // Set the Axis2 request MessageContext opClient.addMessageContext(axisRequest); } catch (Exception e) { // TODO: Do something } } }
/** * Everytime a response message is received this method gets invoked. It will then select the * outgoing *Synapse* message context for the reply we received, and determine what action to take * at the Synapse level * * @param messageCtx the Axis2 message context of the reply received * @throws AxisFault */ public void receive(MessageContext messageCtx) throws AxisFault { String messageID = null; /** * In an Out-only scenario if the client receives a HTTP 202 accepted we need to remove the call * back/s registered for that request. This if will check weather this is a message sent in a * that scenario and remove the callback */ if (messageCtx.getProperty(NhttpConstants.HTTP_202_RECEIVED) != null && "true".equals(messageCtx.getProperty(NhttpConstants.HTTP_202_RECEIVED))) { if (callbackStore.containsKey(messageCtx.getMessageID())) { callbackStore.remove(messageCtx.getMessageID()); if (log.isDebugEnabled()) { log.debug( "CallBack registered with Message id : " + messageCtx.getMessageID() + " removed from the " + "callback store since we got an accepted Notification"); } } return; } if (messageCtx.getOptions() != null && messageCtx.getOptions().getRelatesTo() != null) { // never take a chance with a NPE at this stage.. so check at each level :-) Options options = messageCtx.getOptions(); if (options != null) { RelatesTo relatesTo = options.getRelatesTo(); if (relatesTo != null) { messageID = relatesTo.getValue(); } } } else if (messageCtx.getProperty(SandeshaClientConstants.SEQUENCE_KEY) == null) { messageID = (String) messageCtx.getProperty(SynapseConstants.RELATES_TO_FOR_POX); } if (messageID != null) { AsyncCallback callback = (AsyncCallback) callbackStore.remove(messageID); if (log.isDebugEnabled()) { log.debug( "Callback removed for request message id : " + messageID + ". Pending callbacks count : " + callbackStore.size()); } RelatesTo[] relates = messageCtx.getRelationships(); if (relates != null && relates.length > 1) { // we set a relates to to the response message so that if WSA is not used, we // could still link back to the original message. But if WSA was used, this // gets duplicated, and we should remove it removeDuplicateRelatesTo(messageCtx, relates); } if (callback != null) { handleMessage( messageID, messageCtx, ((AsyncCallback) callback).getSynapseOutMsgCtx(), (AsyncCallback) callback); } else { // TODO invoke a generic synapse error handler for this message log.warn( "Synapse received a response for the request with message Id : " + messageID + " But a callback is not registered (anymore) to process this response"); } } else if (!messageCtx.isPropertyTrue(NhttpConstants.SC_ACCEPTED)) { // TODO invoke a generic synapse error handler for this message log.warn("Synapse received a response message without a message Id"); } }
/** * Based on the Axis2 client code. Sends the Axis2 Message context out and returns the Axis2 * message context for the response. * * <p>Here Synapse works as a Client to the service. It would expect 200 ok, 202 ok and 500 * internal server error as possible responses. * * @param endpoint the endpoint being sent to, maybe null * @param synapseOutMessageContext the outgoing synapse message * @throws AxisFault on errors */ public static void send( EndpointDefinition endpoint, org.apache.synapse.MessageContext synapseOutMessageContext) throws AxisFault { boolean separateListener = false; boolean wsSecurityEnabled = false; String wsSecPolicyKey = null; String inboundWsSecPolicyKey = null; String outboundWsSecPolicyKey = null; boolean wsRMEnabled = false; String wsRMPolicyKey = null; boolean wsAddressingEnabled = false; String wsAddressingVersion = null; if (endpoint != null) { separateListener = endpoint.isUseSeparateListener(); wsSecurityEnabled = endpoint.isSecurityOn(); wsSecPolicyKey = endpoint.getWsSecPolicyKey(); inboundWsSecPolicyKey = endpoint.getInboundWsSecPolicyKey(); outboundWsSecPolicyKey = endpoint.getOutboundWsSecPolicyKey(); wsRMEnabled = endpoint.isReliableMessagingOn(); wsRMPolicyKey = endpoint.getWsRMPolicyKey(); wsAddressingEnabled = endpoint.isAddressingOn() || wsRMEnabled; wsAddressingVersion = endpoint.getAddressingVersion(); } if (log.isDebugEnabled()) { String to; if (endpoint != null && endpoint.getAddress() != null) { to = endpoint.getAddress(synapseOutMessageContext); } else { to = synapseOutMessageContext.getTo().toString(); } log.debug( "Sending [add = " + wsAddressingEnabled + "] [sec = " + wsSecurityEnabled + "] [rm = " + wsRMEnabled + (endpoint != null ? "] [mtom = " + endpoint.isUseMTOM() + "] [swa = " + endpoint.isUseSwa() + "] [format = " + endpoint.getFormat() + "] [force soap11=" + endpoint.isForceSOAP11() + "] [force soap12=" + endpoint.isForceSOAP12() + "] [pox=" + endpoint.isForcePOX() + "] [get=" + endpoint.isForceGET() + "] [encoding=" + endpoint.getCharSetEncoding() : "") + "] [to=" + to + "]"); } // save the original message context without altering it, so we can tie the response MessageContext originalInMsgCtx = ((Axis2MessageContext) synapseOutMessageContext).getAxis2MessageContext(); // TODO Temp hack: ESB removes the session id from request in a random manner. Map headers = (Map) originalInMsgCtx.getProperty(MessageContext.TRANSPORT_HEADERS); String session = (String) synapseOutMessageContext.getProperty("LB_COOKIE_HEADER"); if (session != null) { headers.put("Cookie", session); } // create a new MessageContext to be sent out as this should not corrupt the original // we need to create the response to the original message later on String preserveAddressingProperty = (String) synapseOutMessageContext.getProperty(SynapseConstants.PRESERVE_WS_ADDRESSING); MessageContext axisOutMsgCtx = cloneForSend(originalInMsgCtx, preserveAddressingProperty); if (log.isDebugEnabled()) { log.debug( "Message [Original Request Message ID : " + synapseOutMessageContext.getMessageID() + "]" + " [New Cloned Request Message ID : " + axisOutMsgCtx.getMessageID() + "]"); } // set all the details of the endpoint only to the cloned message context // so that we can use the original message context for resending through different endpoints if (endpoint != null) { if (SynapseConstants.FORMAT_POX.equals(endpoint.getFormat())) { axisOutMsgCtx.setDoingREST(true); axisOutMsgCtx.setProperty( org.apache.axis2.Constants.Configuration.MESSAGE_TYPE, org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_APPLICATION_XML); axisOutMsgCtx.setProperty( Constants.Configuration.CONTENT_TYPE, org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_APPLICATION_XML); Object o = axisOutMsgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); Map _headers = (Map) o; if (_headers != null) { _headers.remove(HTTP.CONTENT_TYPE); _headers.put( HTTP.CONTENT_TYPE, org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_APPLICATION_XML); } } else if (SynapseConstants.FORMAT_GET.equals(endpoint.getFormat())) { axisOutMsgCtx.setDoingREST(true); axisOutMsgCtx.setProperty( Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET); axisOutMsgCtx.setProperty( org.apache.axis2.Constants.Configuration.MESSAGE_TYPE, org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_X_WWW_FORM); } else if (SynapseConstants.FORMAT_SOAP11.equals(endpoint.getFormat())) { axisOutMsgCtx.setDoingREST(false); axisOutMsgCtx.removeProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE); // We need to set this explicitly here in case the request was not a POST axisOutMsgCtx.setProperty( Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_POST); if (axisOutMsgCtx.getSoapAction() == null && axisOutMsgCtx.getWSAAction() != null) { axisOutMsgCtx.setSoapAction(axisOutMsgCtx.getWSAAction()); } if (!axisOutMsgCtx.isSOAP11()) { SOAPUtils.convertSOAP12toSOAP11(axisOutMsgCtx); } Object o = axisOutMsgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); Map _headers = (Map) o; if (_headers != null) { _headers.remove(HTTP.CONTENT_TYPE); _headers.put( HTTP.CONTENT_TYPE, org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_TEXT_XML); } } else if (SynapseConstants.FORMAT_SOAP12.equals(endpoint.getFormat())) { axisOutMsgCtx.setDoingREST(false); axisOutMsgCtx.removeProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE); // We need to set this explicitly here in case the request was not a POST axisOutMsgCtx.setProperty( Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_POST); if (axisOutMsgCtx.getSoapAction() == null && axisOutMsgCtx.getWSAAction() != null) { axisOutMsgCtx.setSoapAction(axisOutMsgCtx.getWSAAction()); } if (axisOutMsgCtx.isSOAP11()) { SOAPUtils.convertSOAP11toSOAP12(axisOutMsgCtx); } Object o = axisOutMsgCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); Map _headers = (Map) o; if (_headers != null) { _headers.remove(HTTP.CONTENT_TYPE); _headers.put( HTTP.CONTENT_TYPE, org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML); } } else if (SynapseConstants.FORMAT_REST.equals(endpoint.getFormat())) { /*format=rest is kept only backword compatibility. We no longer needed that.*/ /* Remove Message Type for GET and DELETE Request */ if (originalInMsgCtx.getProperty(Constants.Configuration.HTTP_METHOD) != null) { if (originalInMsgCtx .getProperty(Constants.Configuration.HTTP_METHOD) .toString() .equals(Constants.Configuration.HTTP_METHOD_GET) || originalInMsgCtx .getProperty(Constants.Configuration.HTTP_METHOD) .toString() .equals(Constants.Configuration.HTTP_METHOD_DELETE)) { axisOutMsgCtx.removeProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE); } } axisOutMsgCtx.setDoingREST(true); } else { processWSDL2RESTRequestMessageType(originalInMsgCtx, axisOutMsgCtx); } if (endpoint.isUseMTOM()) { axisOutMsgCtx.setDoingMTOM(true); // fix / workaround for AXIS2-1798 axisOutMsgCtx.setProperty( org.apache.axis2.Constants.Configuration.ENABLE_MTOM, org.apache.axis2.Constants.VALUE_TRUE); axisOutMsgCtx.setDoingMTOM(true); } else if (endpoint.isUseSwa()) { axisOutMsgCtx.setDoingSwA(true); // fix / workaround for AXIS2-1798 axisOutMsgCtx.setProperty( org.apache.axis2.Constants.Configuration.ENABLE_SWA, org.apache.axis2.Constants.VALUE_TRUE); axisOutMsgCtx.setDoingSwA(true); } if (endpoint.getCharSetEncoding() != null) { axisOutMsgCtx.setProperty( Constants.Configuration.CHARACTER_SET_ENCODING, endpoint.getCharSetEncoding()); // Need to Clean this up. TargetRequest line 176 contains a code block which over writes the // Content-Type returned by the message formatter with the Content-Type in // TRANSPORT_HEADERS. Because of that, even when // the Character set encoding is set by the message formatter, it will be replaced by the // Content-Type header in TRANSPORT_HEADERS. // So Im setting a property to check in TargetRequest before over writing the header. axisOutMsgCtx.setProperty("EndpointCharEncodingSet", "true"); } // HTTP Endpoint : use the specified HTTP method and remove REST_URL_POSTFIX, it's not // supported in HTTP Endpoint if (endpoint.isHTTPEndpoint()) { axisOutMsgCtx.setProperty( Constants.Configuration.HTTP_METHOD, synapseOutMessageContext.getProperty(Constants.Configuration.HTTP_METHOD)); axisOutMsgCtx.removeProperty(NhttpConstants.REST_URL_POSTFIX); } // add rest request' suffix URI String restSuffix = (String) axisOutMsgCtx.getProperty(NhttpConstants.REST_URL_POSTFIX); boolean isRest = SynapseConstants.FORMAT_REST.equals(endpoint.getFormat()); if (!isRest && !endpoint.isForceSOAP11() && !endpoint.isForceSOAP12()) { isRest = isRequestRest(originalInMsgCtx); } if (endpoint.getAddress() != null) { String address = endpoint.getAddress(synapseOutMessageContext); if (isRest && restSuffix != null && !"".equals(restSuffix)) { String url; if (!address.endsWith("/") && !restSuffix.startsWith("/") && !restSuffix.startsWith("?")) { url = address + "/" + restSuffix; } else if (address.endsWith("/") && restSuffix.startsWith("/")) { url = address + restSuffix.substring(1); } else if (address.endsWith("/") && restSuffix.startsWith("?")) { url = address.substring(0, address.length() - 1) + restSuffix; } else { url = address + restSuffix; } axisOutMsgCtx.setTo(new EndpointReference(url)); } else { axisOutMsgCtx.setTo(new EndpointReference(address)); } axisOutMsgCtx.setProperty(NhttpConstants.ENDPOINT_PREFIX, address); synapseOutMessageContext.setProperty(SynapseConstants.ENDPOINT_PREFIX, address); } else { // Supporting RESTful invocation if (isRest && restSuffix != null && !"".equals(restSuffix)) { EndpointReference epr = axisOutMsgCtx.getTo(); if (epr != null) { String address = epr.getAddress(); String url; if (!address.endsWith("/") && !restSuffix.startsWith("/") && !restSuffix.startsWith("?")) { url = address + "/" + restSuffix; } else { url = address + restSuffix; } axisOutMsgCtx.setTo(new EndpointReference(url)); } } } if (endpoint.isUseSeparateListener()) { axisOutMsgCtx.getOptions().setUseSeparateListener(true); } } else { processWSDL2RESTRequestMessageType(originalInMsgCtx, axisOutMsgCtx); } // only put whttp:location for the REST (GET) requests, otherwise causes issues for POX messages if (axisOutMsgCtx.isDoingREST() && HTTPConstants.MEDIA_TYPE_X_WWW_FORM.equals( axisOutMsgCtx.getProperty(Constants.Configuration.MESSAGE_TYPE))) { if (axisOutMsgCtx.getProperty(WSDL2Constants.ATTR_WHTTP_LOCATION) == null && axisOutMsgCtx.getEnvelope().getBody().getFirstElement() != null) { axisOutMsgCtx.setProperty( WSDL2Constants.ATTR_WHTTP_LOCATION, axisOutMsgCtx.getEnvelope().getBody().getFirstElement().getQName().getLocalPart()); } } if (wsAddressingEnabled) { if (wsAddressingVersion != null && SynapseConstants.ADDRESSING_VERSION_SUBMISSION.equals(wsAddressingVersion)) { axisOutMsgCtx.setProperty( AddressingConstants.WS_ADDRESSING_VERSION, AddressingConstants.Submission.WSA_NAMESPACE); } else if (wsAddressingVersion != null && SynapseConstants.ADDRESSING_VERSION_FINAL.equals(wsAddressingVersion)) { axisOutMsgCtx.setProperty( AddressingConstants.WS_ADDRESSING_VERSION, AddressingConstants.Final.WSA_NAMESPACE); } axisOutMsgCtx.setProperty( AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.FALSE); } else { axisOutMsgCtx.setProperty( AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.TRUE); } // remove the headers if we don't need to preserve them. // determine weather we need to preserve the processed headers String preserveHeaderProperty = (String) synapseOutMessageContext.getProperty(SynapseConstants.PRESERVE_PROCESSED_HEADERS); if (preserveHeaderProperty == null || !Boolean.parseBoolean(preserveHeaderProperty)) { // default behaviour is to remove the headers MessageHelper.removeProcessedHeaders( axisOutMsgCtx, (preserveAddressingProperty != null && Boolean.parseBoolean(preserveAddressingProperty))); } ConfigurationContext axisCfgCtx = axisOutMsgCtx.getConfigurationContext(); AxisConfiguration axisCfg = axisCfgCtx.getAxisConfiguration(); AxisService anoymousService = AnonymousServiceFactory.getAnonymousService( synapseOutMessageContext.getConfiguration(), axisCfg, wsAddressingEnabled, wsRMEnabled, wsSecurityEnabled); // mark the anon services created to be used in the client side of synapse as hidden // from the server side of synapse point of view anoymousService.getParent().addParameter(SynapseConstants.HIDDEN_SERVICE_PARAM, "true"); ServiceGroupContext sgc = new ServiceGroupContext(axisCfgCtx, (AxisServiceGroup) anoymousService.getParent()); ServiceContext serviceCtx = sgc.getServiceContext(anoymousService); boolean outOnlyMessage = "true".equals(synapseOutMessageContext.getProperty(SynapseConstants.OUT_ONLY)); // get a reference to the DYNAMIC operation of the Anonymous Axis2 service 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()); } // 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(axisOutMsgCtx, synapseOutMessageContext); if (!outOnlyMessage) { 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); // // if (Utils.isClientThreadNonBlockingPropertySet(axisOutMsgCtx)) { // SynapseCallbackReceiver synapseCallbackReceiver = (SynapseCallbackReceiver) // axisOutMsgCtx.getAxisOperation().getMessageReceiver(); // synapseCallbackReceiver.addCallback(axisOutMsgCtx.getMessageID(), new // FaultCallback(axisOutMsgCtx, synapseOutMessageContext)); // } // 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))); serviceClient.setOptions(clientOptions); serviceClient .getOptions() .setTo(new EndpointReference(endpoint.getAddress(synapseOutMessageContext))); SandeshaClient.terminateSequence(serviceClient); } } }
private void send(MessageContext msgctx) throws AxisFault { // create the responseMessageContext and set that its related to the current outgoing // message, so that it could be tied back to the original request even if the response // envelope does not contain addressing headers MessageContext responseMessageContext = new MessageContext(); responseMessageContext.setMessageID(msgctx.getMessageID()); responseMessageContext.setProperty( SynapseConstants.RELATES_TO_FOR_POX, msgctx.getMessageID()); responseMessageContext.setOptions(options); responseMessageContext.setServerSide(true); addMessageContext(responseMessageContext); responseMessageContext.setProperty("synapse.send", "true"); AxisEngine.send(msgctx); // did the engine receive a immediate synchronous response? // e.g. sometimes the transport sender may listen for a syncronous reply if (msgctx.getProperty(MessageContext.TRANSPORT_IN) != null) { responseMessageContext.setOperationContext(msgctx.getOperationContext()); responseMessageContext.setAxisMessage( msgctx .getOperationContext() .getAxisOperation() .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE)); responseMessageContext.setAxisService(msgctx.getAxisService()); responseMessageContext.setProperty( MessageContext.TRANSPORT_OUT, msgctx.getProperty(MessageContext.TRANSPORT_OUT)); responseMessageContext.setProperty( org.apache.axis2.Constants.OUT_TRANSPORT_INFO, msgctx.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO)); responseMessageContext.setProperty( org.apache.synapse.SynapseConstants.ISRESPONSE_PROPERTY, Boolean.TRUE); responseMessageContext.setTransportIn(msgctx.getTransportIn()); responseMessageContext.setTransportOut(msgctx.getTransportOut()); // If request is REST assume that the responseMessageContext is REST too responseMessageContext.setDoingREST(msgctx.isDoingREST()); responseMessageContext.setProperty( MessageContext.TRANSPORT_IN, msgctx.getProperty(MessageContext.TRANSPORT_IN)); responseMessageContext.setTransportIn(msgctx.getTransportIn()); responseMessageContext.setTransportOut(msgctx.getTransportOut()); // Options object reused above so soapAction needs to be removed so // that soapAction+wsa:Action on response don't conflict responseMessageContext.setSoapAction(""); if (responseMessageContext.getEnvelope() == null) { // If request is REST we assume the responseMessageContext is // REST, so set the variable Options options = responseMessageContext.getOptions(); if (options != null) { RelatesTo relatesTo = options.getRelatesTo(); if (relatesTo != null) { relatesTo.setValue(msgctx.getMessageID()); } else { options.addRelatesTo(new RelatesTo(msgctx.getMessageID())); } } SOAPEnvelope resenvelope = TransportUtils.createSOAPMessage(responseMessageContext); if (resenvelope != null) { responseMessageContext.setEnvelope(resenvelope); AxisEngine.receive(responseMessageContext); if (responseMessageContext.getReplyTo() != null) { sc.setTargetEPR(responseMessageContext.getReplyTo()); } complete(msgctx); } else { throw new AxisFault(Messages.getMessage("blockingInvocationExpectsResponse")); } } } }
/** * Sets a property into the current (local) Synapse Context or into the Axis Message Context or * into Transports Header and removes above properties from the corresponding locations. * * @param synCtx the message context * @return true always */ public boolean mediate(MessageContext synCtx) { SynapseLog synLog = getLog(synCtx); if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug("Start : Property mediator"); if (synLog.isTraceTraceEnabled()) { synLog.traceTrace("Message : " + synCtx.getEnvelope()); } } if (action == ACTION_SET) { Object resultValue = getResultValue(synCtx); // if the result value is a String we can apply a reguar expression to // choose part of it if (resultValue instanceof String && pattern != null) { resultValue = getMatchedValue((String) resultValue, synLog); } if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug( "Setting property : " + name + " at scope : " + (scope == null ? "default" : scope) + " to : " + resultValue + " (i.e. " + (value != null ? "constant : " + value : "result of expression : " + expression) + ")"); } if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) { // Setting property into the Synapse Context synCtx.setProperty(name, resultValue); } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope) && synCtx instanceof Axis2MessageContext) { // Setting property into the Axis2 Message Context Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.setProperty(name, resultValue); } else if (XMLConfigConstants.SCOPE_CLIENT.equals(scope) && synCtx instanceof Axis2MessageContext) { // Setting property into the Axis2 Message Context client options Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.getOptions().setProperty(name, resultValue); } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) { // Setting Transport Headers Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null && headers instanceof Map) { Map headersMap = (Map) headers; headersMap.put(name, resultValue); } if (headers == null) { Map headersMap = new HashMap(); headersMap.put(name, resultValue); axis2MessageCtx.setProperty( org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headersMap); } } else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope) && synCtx instanceof Axis2MessageContext) { // Setting Transport Headers Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2smc.getAxis2MessageContext().getOperationContext().setProperty(name, resultValue); } } else { if (synLog.isTraceOrDebugEnabled()) { synLog.traceOrDebug( "Removing property : " + name + " (scope:" + (scope == null ? "default" : scope) + ")"); } if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) { // Removing property from the Synapse Context Set pros = synCtx.getPropertyKeySet(); if (pros != null) { pros.remove(name); } } else if ((XMLConfigConstants.SCOPE_AXIS2.equals(scope) || XMLConfigConstants.SCOPE_CLIENT.equals(scope)) && synCtx instanceof Axis2MessageContext) { // Removing property from the Axis2 Message Context Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.removeProperty(name); } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) { // Removing transport headers Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null && headers instanceof Map) { Map headersMap = (Map) headers; headersMap.remove(name); } else { synLog.traceOrDebug("No transport headers found for the message"); } } } synLog.traceOrDebug("End : Property mediator"); return true; }