Search in sources :

Example 21 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class FailoverForwardingServiceTest method test.

/**
 * Testing whether the failover forwarding service is successfully storing
 * the message in the queue
 *
 * @throws Exception
 */
@Test
public void test() throws Exception {
    JmsStore jmsStore = new JmsStore();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    parameters.put("java.naming.provider.url", "tcp://127.0.0.1:61616");
    jmsStore.setParameters(parameters);
    jmsStore.setName("JMSStore");
    MessageProcessor messageProcessor = new FailoverScheduledMessageForwardingProcessor();
    Map<String, Object> parametersPro = new HashMap<>();
    parametersPro.put("message.target.store.name", jmsStore.getName());
    parametersPro.put("interval", "5000");
    messageProcessor.setName("FailoverProcessor");
    messageProcessor.setParameters(parametersPro);
    messageProcessor.setMessageStoreName("JMSStore");
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(synapseConfiguration.getAxisConfiguration());
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    synapseConfiguration.addMessageStore("JMSStore", jmsStore);
    synapseConfiguration.addMessageProcessor("FailoverProcessor", messageProcessor);
    jmsStore.init(synapseEnvironment);
    FailoverForwardingService failoverForwardingService = new FailoverForwardingService(messageProcessor, synapseEnvironment, 5000, false);
    failoverForwardingService.init(synapseEnvironment);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    SOAP11Factory factory = new SOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    OMElement element = AXIOMUtil.stringToOM("<name><value>Test</value></name>");
    envelope.getBody().addChild(element);
    messageContext.setEnvelope(envelope);
    Assert.assertEquals("Queue is not empty!", 0, broker.getAdminView().getTotalMessageCount());
    failoverForwardingService.dispatch(messageContext);
    Assert.assertEquals("Message not forwarded!", 1, broker.getAdminView().getTotalMessageCount());
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) HashMap(java.util.HashMap) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) JmsStore(org.apache.synapse.message.store.impl.jms.JmsStore) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 22 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class SynapseCommodityServiceTest method setUp.

protected void setUp() throws java.lang.Exception {
    ServerConfigurationInformation information = new ServerConfigurationInformation();
    information.setCreateNewInstance(false);
    information.setSynapseHome(".");
    // Initializing Synapse repository
    information.setSynapseXMLLocation("./../../repository/conf/sample/resources/misc/synapse.xml");
    information.setAxis2Xml("./../../repository/conf/axis2.xml");
    findAndReplace(new File("./../../repository/conf/axis2_pt_server.xml"), new File("./target/test_repos/axis2.xml"), "lib/", "./../../modules/distribution/src/main/conf/");
    findAndReplace(new File("./../../repository/conf/axis2_be_server.xml"), new File("./target/test_repos/axis2_be_server.xml"), "lib/", "./../../modules/distribution/src/main/conf/");
    System.setProperty("jmx.agent.name", "synapse");
    ConfigurationContext synapseConfigCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("./target/test_repos/synapse", "./target/test_repos/axis2.xml");
    TransportInDescription synTrsIn = synapseConfigCtx.getAxisConfiguration().getTransportsIn().get("http");
    synTrsIn.getParameter("port").setValue("10100");
    synTrsIn = synapseConfigCtx.getAxisConfiguration().getTransportsIn().get("https");
    synTrsIn.getParameter("port").setValue("12100");
    startServer(synapseConfigCtx);
    ServerContextInformation contextInformation = new ServerContextInformation(synapseConfigCtx, information);
    ServerManager serverManager = new ServerManager();
    serverManager.init(information, contextInformation);
    serverManager.start();
    // Initializing Business Endpoint
    // Set a different agent name to avoid collisions between the MBeans registered
    // by the two servers.
    System.setProperty("jmx.agent.name", "business");
    ConfigurationContext businessConfigCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("./target/test_repos/synapse", "./target/test_repos/axis2_be_server.xml");
    HashMap messageReciverMap = new HashMap();
    Class inOnlyMessageReceiver = org.apache.axis2.util.Loader.loadClass("org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver");
    org.apache.axis2.engine.MessageReceiver messageReceiver = (org.apache.axis2.engine.MessageReceiver) inOnlyMessageReceiver.newInstance();
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_IN_ONLY, messageReceiver);
    Class inoutMessageReceiver = org.apache.axis2.util.Loader.loadClass("org.apache.axis2.rpc.receivers.RPCMessageReceiver");
    MessageReceiver inOutmessageReceiver = (MessageReceiver) inoutMessageReceiver.newInstance();
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_IN_OUT, inOutmessageReceiver);
    messageReciverMap.put(org.apache.axis2.description.WSDL2Constants.MEP_URI_ROBUST_IN_ONLY, inOutmessageReceiver);
    AxisService businessService = AxisService.createService(Services.class.getName(), businessConfigCtx.getAxisConfiguration(), messageReciverMap, "http://business.org", "http://business.org", Services.class.getClassLoader());
    businessConfigCtx.getAxisConfiguration().addService(businessService);
    TransportInDescription busTrsIn = businessConfigCtx.getAxisConfiguration().getTransportsIn().get("http");
    busTrsIn.getParameter("port").setValue("10101");
    busTrsIn = businessConfigCtx.getAxisConfiguration().getTransportsIn().get("https");
    busTrsIn.getParameter("port").setValue("12101");
    startServer(businessConfigCtx);
}
Also used : ServerManager(org.apache.synapse.ServerManager) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MessageReceiver(org.apache.axis2.engine.MessageReceiver) HashMap(java.util.HashMap) AxisService(org.apache.axis2.description.AxisService) ServerConfigurationInformation(org.apache.synapse.ServerConfigurationInformation) TransportInDescription(org.apache.axis2.description.TransportInDescription) Services(org.apache.synapse.util.Services) ServerContextInformation(org.apache.synapse.ServerContextInformation) MessageReceiver(org.apache.axis2.engine.MessageReceiver)

Example 23 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class Axis2LoadBalanceMembershipHandler method setConfigurationContext.

public void setConfigurationContext(ConfigurationContext configCtx) {
    this.configCtx = configCtx;
    // The following code does the bridging between Axis2 and Synapse load balancing
    ClusteringAgent clusteringAgent = configCtx.getAxisConfiguration().getClusteringAgent();
    if (clusteringAgent == null) {
        String msg = "In order to enable load balancing across an Axis2 cluster, " + "the cluster entry should be enabled in the axis2.xml file";
        log.error(msg);
        throw new SynapseException(msg);
    }
    groupMgtAgent = clusteringAgent.getGroupManagementAgent(lbDomain);
    if (groupMgtAgent == null) {
        String msg = "A LoadBalanceEventHandler has not been specified in the axis2.xml " + "file for the domain " + lbDomain;
        log.error(msg);
        throw new SynapseException(msg);
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) ClusteringAgent(org.apache.axis2.clustering.ClusteringAgent)

Example 24 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class BlockingMsgSender method send.

/**
 * Blocking Invocation
 *
 * @param endpointDefinition the endpoint being sent to.
 * @param synapseInMsgCtx the outgoing synapse message.
 * @throws AxisFault on errors.
 */
public void send(EndpointDefinition endpointDefinition, MessageContext synapseInMsgCtx) throws AxisFault {
    if (log.isDebugEnabled()) {
        log.debug("Start Sending the Message ");
    }
    org.apache.axis2.context.MessageContext axisInMsgCtx = ((Axis2MessageContext) synapseInMsgCtx).getAxis2MessageContext();
    org.apache.axis2.context.MessageContext axisOutMsgCtx = new org.apache.axis2.context.MessageContext();
    String endpointReferenceValue = null;
    if (endpointDefinition.getAddress() != null) {
        endpointReferenceValue = endpointDefinition.getAddress();
    } else if (axisInMsgCtx.getTo() != null) {
        endpointReferenceValue = axisInMsgCtx.getTo().getAddress();
    } else {
        handleException("Service url, Endpoint or 'To' header is required");
    }
    EndpointReference epr = new EndpointReference(endpointReferenceValue);
    axisOutMsgCtx.setTo(epr);
    AxisService anonymousService;
    if (endpointReferenceValue != null && endpointReferenceValue.startsWith(Constants.TRANSPORT_LOCAL)) {
        configurationContext = axisInMsgCtx.getConfigurationContext();
        anonymousService = AnonymousServiceFactory.getAnonymousService(configurationContext.getAxisConfiguration(), LOCAL_ANON_SERVICE);
    } else {
        anonymousService = AnonymousServiceFactory.getAnonymousService(null, configurationContext.getAxisConfiguration(), endpointDefinition.isAddressingOn() | endpointDefinition.isReliableMessagingOn(), endpointDefinition.isReliableMessagingOn(), endpointDefinition.isSecurityOn(), false);
    }
    axisOutMsgCtx.setConfigurationContext(configurationContext);
    axisOutMsgCtx.setEnvelope(axisInMsgCtx.getEnvelope());
    axisOutMsgCtx.setProperty(HTTPConstants.NON_ERROR_HTTP_STATUS_CODES, axisInMsgCtx.getProperty(HTTPConstants.NON_ERROR_HTTP_STATUS_CODES));
    axisOutMsgCtx.setProperty(HTTPConstants.ERROR_HTTP_STATUS_CODES, axisInMsgCtx.getProperty(HTTPConstants.ERROR_HTTP_STATUS_CODES));
    axisOutMsgCtx.setProperty(SynapseConstants.DISABLE_CHUNKING, axisInMsgCtx.getProperty(SynapseConstants.DISABLE_CHUNKING));
    axisOutMsgCtx.setProperty(SynapseConstants.NO_KEEPALIVE, axisInMsgCtx.getProperty(SynapseConstants.NO_KEEPALIVE));
    axisOutMsgCtx.setProperty(SynapseConstants.NO_DEFAULT_CONTENT_TYPE, axisInMsgCtx.getProperty(SynapseConstants.NO_DEFAULT_CONTENT_TYPE));
    // Fill MessageContext
    BlockingMsgSenderUtils.fillMessageContext(endpointDefinition, axisOutMsgCtx, synapseInMsgCtx);
    if (JsonUtil.hasAJsonPayload(axisInMsgCtx)) {
        JsonUtil.cloneJsonPayload(axisInMsgCtx, axisOutMsgCtx);
    }
    Options clientOptions;
    if (initClientOptions) {
        clientOptions = new Options();
    } else {
        clientOptions = axisInMsgCtx.getOptions();
        clientOptions.setTo(epr);
    }
    // Fill Client options
    BlockingMsgSenderUtils.fillClientOptions(endpointDefinition, clientOptions, synapseInMsgCtx);
    // Update To url if mock-service exists for unit test
    MediatorPropertyUtils.updateSendToUrlForMockServices(endpointDefinition, synapseInMsgCtx, axisOutMsgCtx);
    anonymousService.getParent().addParameter(SynapseConstants.HIDDEN_SERVICE_PARAM, "true");
    ServiceGroupContext serviceGroupContext = new ServiceGroupContext(configurationContext, (AxisServiceGroup) anonymousService.getParent());
    ServiceContext serviceCtx = serviceGroupContext.getServiceContext(anonymousService);
    axisOutMsgCtx.setServiceContext(serviceCtx);
    // Invoke
    boolean isOutOnly = isOutOnly(synapseInMsgCtx, axisOutMsgCtx);
    try {
        if (isOutOnly) {
            sendRobust(axisOutMsgCtx, clientOptions, anonymousService, serviceCtx, synapseInMsgCtx);
            final String httpStatusCode = String.valueOf(axisOutMsgCtx.getProperty(SynapseConstants.HTTP_SENDER_STATUSCODE)).trim();
            /*
                 * Though this is OUT_ONLY operation, we need to set the
                 * response Status code so that others can make use of it.
                 */
            axisInMsgCtx.setProperty(SynapseConstants.HTTP_SC, httpStatusCode);
            synapseInMsgCtx.setProperty(SynapseConstants.BLOCKING_SENDER_ERROR, "false");
        } else {
            org.apache.axis2.context.MessageContext result = sendReceive(axisOutMsgCtx, clientOptions, anonymousService, serviceCtx, synapseInMsgCtx);
            synapseInMsgCtx.setEnvelope(result.getEnvelope());
            if (JsonUtil.hasAJsonPayload(result)) {
                JsonUtil.cloneJsonPayload(result, ((Axis2MessageContext) synapseInMsgCtx).getAxis2MessageContext());
            }
            final String statusCode = String.valueOf(result.getProperty(SynapseConstants.HTTP_SENDER_STATUSCODE)).trim();
            /*
                 * We need to set the response status code so that users can
                 * fetch it later.
                 */
            axisInMsgCtx.setProperty(SynapseConstants.HTTP_SC, statusCode);
            if ("false".equals(synapseInMsgCtx.getProperty(SynapseConstants.BLOCKING_SENDER_PRESERVE_REQ_HEADERS))) {
                axisInMsgCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, result.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));
            }
            synapseInMsgCtx.setProperty(SynapseConstants.BLOCKING_SENDER_ERROR, "false");
            this.invokeHandlers(synapseInMsgCtx);
        }
    } catch (Exception ex) {
        /*
             * Extract the HTTP status code from the Exception message.
             */
        final String errorStatusCode = extractStatusCodeFromException(ex);
        axisInMsgCtx.setProperty(SynapseConstants.HTTP_SC, errorStatusCode);
        synapseInMsgCtx.setProperty(SynapseConstants.BLOCKING_SENDER_ERROR, "true");
        synapseInMsgCtx.setProperty(SynapseConstants.ERROR_EXCEPTION, ex);
        if (ex instanceof AxisFault) {
            AxisFault fault = (AxisFault) ex;
            int errorCode = SynapseConstants.BLOCKING_SENDER_OPERATION_FAILED;
            if (fault.getFaultCode() != null && fault.getFaultCode().getLocalPart() != null && !"".equals(fault.getFaultCode().getLocalPart())) {
                try {
                    errorCode = Integer.parseInt(fault.getFaultCode().getLocalPart());
                } catch (NumberFormatException e) {
                    errorCode = SynapseConstants.BLOCKING_SENDER_OPERATION_FAILED;
                }
            }
            synapseInMsgCtx.setProperty(SynapseConstants.ERROR_CODE, errorCode);
            synapseInMsgCtx.setProperty(SynapseConstants.ERROR_MESSAGE, fault.getMessage());
            synapseInMsgCtx.setProperty(SynapseConstants.ERROR_DETAIL, fault.getDetail() != null ? fault.getDetail().getText() : "");
            if (!isOutOnly) {
                org.apache.axis2.context.MessageContext faultMC = fault.getFaultMessageContext();
                if (faultMC != null) {
                    Object statusCode = faultMC.getProperty(SynapseConstants.HTTP_SENDER_STATUSCODE);
                    synapseInMsgCtx.setProperty(SynapseConstants.HTTP_SC, statusCode);
                    axisInMsgCtx.setProperty(SynapseConstants.HTTP_SC, statusCode);
                    synapseInMsgCtx.setEnvelope(faultMC.getEnvelope());
                }
            }
        }
    }
    // get the original message context that went through the OAuth Configured HTTP endpoint
    // this is used to retry the call when there is any oauth related issue
    org.apache.synapse.MessageContext originalMC = MessageCache.getInstance().removeMessageContext(synapseInMsgCtx.getMessageID());
    // Check fault occure when send the request to endpoint
    if ("true".equals(synapseInMsgCtx.getProperty(SynapseConstants.BLOCKING_SENDER_ERROR))) {
        // Handle the fault
        synapseInMsgCtx.getFaultStack().pop().handleFault(synapseInMsgCtx, (Exception) synapseInMsgCtx.getProperty(SynapseConstants.ERROR_EXCEPTION));
    } else {
        // If a message was successfully processed to give it a chance to clear up or reset its state to active
        Stack<FaultHandler> faultStack = synapseInMsgCtx.getFaultStack();
        if (faultStack != null && !faultStack.isEmpty()) {
            AbstractEndpoint successfulEndpoint = null;
            if (faultStack.peek() instanceof AbstractEndpoint) {
                successfulEndpoint = (AbstractEndpoint) faultStack.pop();
                successfulEndpoint.onSuccess();
            }
            if (successfulEndpoint instanceof OAuthConfiguredHTTPEndpoint) {
                OAuthConfiguredHTTPEndpoint httpEndpoint = (OAuthConfiguredHTTPEndpoint) successfulEndpoint;
                if (originalMC != null && OAuthUtils.retryOnOAuthFailure(httpEndpoint, synapseInMsgCtx, synapseInMsgCtx)) {
                    MessageContext messageContext = httpEndpoint.retryCallWithNewToken(originalMC);
                    ((Axis2MessageContext) synapseInMsgCtx).setAxis2MessageContext(((Axis2MessageContext) messageContext).getAxis2MessageContext());
                }
            }
            // Remove all endpoint related fault handlers if any
            while (!faultStack.empty() && faultStack.peek() instanceof AbstractEndpoint) {
                faultStack.pop();
            }
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) ServiceContext(org.apache.axis2.context.ServiceContext) AxisService(org.apache.axis2.description.AxisService) OAuthConfiguredHTTPEndpoint(org.apache.synapse.endpoints.OAuthConfiguredHTTPEndpoint) SynapseException(org.apache.synapse.SynapseException) EndpointReference(org.apache.axis2.addressing.EndpointReference) ServiceGroupContext(org.apache.axis2.context.ServiceGroupContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) MessageContext(org.apache.synapse.MessageContext) FaultHandler(org.apache.synapse.FaultHandler) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 25 with ConfigurationContext

use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.

the class BlockingMsgSender method send.

public MessageContext send(Endpoint endpoint, MessageContext synapseInMsgCtx) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("Start Sending the Message ");
    }
    if (endpoint instanceof IndirectEndpoint) {
        String endpointKey = ((IndirectEndpoint) endpoint).getKey();
        endpoint = synapseInMsgCtx.getEndpoint(endpointKey);
    }
    if (endpoint instanceof TemplateEndpoint) {
        endpoint = ((TemplateEndpoint) endpoint).getRealEndpoint();
    }
    // get the correct endpoint definition
    if (endpoint instanceof ResolvingEndpoint) {
        SynapseXPath keyExpression = ((ResolvingEndpoint) endpoint).getKeyExpression();
        String key = keyExpression.stringValueOf(synapseInMsgCtx);
        endpoint = ((ResolvingEndpoint) endpoint).loadAndInitEndpoint(((Axis2MessageContext) synapseInMsgCtx).getAxis2MessageContext().getConfigurationContext(), key);
    }
    AbstractEndpoint abstractEndpoint = (AbstractEndpoint) endpoint;
    if (!abstractEndpoint.isLeafEndpoint()) {
        handleException("Endpoint Type not supported");
    }
    // clear the message context properties related to endpoint in last service invocation
    Set keySet = synapseInMsgCtx.getPropertyKeySet();
    if (keySet != null) {
        keySet.remove(EndpointDefinition.DYNAMIC_URL_VALUE);
    }
    abstractEndpoint.executeEpTypeSpecificFunctions(synapseInMsgCtx);
    EndpointDefinition endpointDefinition = abstractEndpoint.getDefinition();
    org.apache.axis2.context.MessageContext axisInMsgCtx = ((Axis2MessageContext) synapseInMsgCtx).getAxis2MessageContext();
    org.apache.axis2.context.MessageContext axisOutMsgCtx = new org.apache.axis2.context.MessageContext();
    String endpointReferenceValue = null;
    if (endpointDefinition.getAddress() != null) {
        endpointReferenceValue = endpointDefinition.getAddress();
    } else if (axisInMsgCtx.getTo() != null) {
        endpointReferenceValue = axisInMsgCtx.getTo().getAddress();
    } else {
        handleException("Service url, Endpoint or 'To' header is required");
    }
    EndpointReference epr = new EndpointReference(endpointReferenceValue);
    axisOutMsgCtx.setTo(epr);
    AxisService anonymousService;
    if (endpointReferenceValue != null && endpointReferenceValue.startsWith(Constants.TRANSPORT_LOCAL)) {
        configurationContext = axisInMsgCtx.getConfigurationContext();
        anonymousService = AnonymousServiceFactory.getAnonymousService(configurationContext.getAxisConfiguration(), LOCAL_ANON_SERVICE);
    } else {
        anonymousService = AnonymousServiceFactory.getAnonymousService(null, configurationContext.getAxisConfiguration(), endpointDefinition.isAddressingOn() | endpointDefinition.isReliableMessagingOn(), endpointDefinition.isReliableMessagingOn(), endpointDefinition.isSecurityOn(), false);
    }
    axisOutMsgCtx.setConfigurationContext(configurationContext);
    axisOutMsgCtx.setEnvelope(axisInMsgCtx.getEnvelope());
    axisOutMsgCtx.setProperty(HTTPConstants.NON_ERROR_HTTP_STATUS_CODES, axisInMsgCtx.getProperty(HTTPConstants.NON_ERROR_HTTP_STATUS_CODES));
    axisOutMsgCtx.setProperty(HTTPConstants.ERROR_HTTP_STATUS_CODES, axisInMsgCtx.getProperty(HTTPConstants.ERROR_HTTP_STATUS_CODES));
    axisOutMsgCtx.setProperty(SynapseConstants.DISABLE_CHUNKING, axisInMsgCtx.getProperty(SynapseConstants.DISABLE_CHUNKING));
    axisOutMsgCtx.setProperty(SynapseConstants.NO_KEEPALIVE, axisInMsgCtx.getProperty(SynapseConstants.NO_KEEPALIVE));
    // Can't refer to the Axis2 constant 'NO_DEFAULT_CONTENT_TYPE' defined in 1.6.1.wso2v23-SNAPSHOT until
    // an API change is done.
    axisOutMsgCtx.setProperty(SynapseConstants.NO_DEFAULT_CONTENT_TYPE, axisInMsgCtx.getProperty(SynapseConstants.NO_DEFAULT_CONTENT_TYPE));
    // Fill MessageContext
    BlockingMsgSenderUtils.fillMessageContext(endpointDefinition, axisOutMsgCtx, synapseInMsgCtx);
    if (JsonUtil.hasAJsonPayload(axisInMsgCtx)) {
        JsonUtil.cloneJsonPayload(axisInMsgCtx, axisOutMsgCtx);
    }
    Options clientOptions;
    if (initClientOptions) {
        clientOptions = new Options();
    } else {
        clientOptions = axisInMsgCtx.getOptions();
        clientOptions.setTo(epr);
    }
    // Fill Client options
    BlockingMsgSenderUtils.fillClientOptions(endpointDefinition, clientOptions, synapseInMsgCtx);
    anonymousService.getParent().addParameter(SynapseConstants.HIDDEN_SERVICE_PARAM, "true");
    ServiceGroupContext serviceGroupContext = new ServiceGroupContext(configurationContext, (AxisServiceGroup) anonymousService.getParent());
    ServiceContext serviceCtx = serviceGroupContext.getServiceContext(anonymousService);
    axisOutMsgCtx.setServiceContext(serviceCtx);
    // Invoke
    boolean isOutOnly = isOutOnly(synapseInMsgCtx, axisOutMsgCtx);
    try {
        if (isOutOnly) {
            sendRobust(axisOutMsgCtx, clientOptions, anonymousService, serviceCtx, synapseInMsgCtx);
            final String httpStatusCode = String.valueOf(axisOutMsgCtx.getProperty(SynapseConstants.HTTP_SENDER_STATUSCODE)).trim();
            /*
                 * Though this is OUT_ONLY operation, we need to set the
                 * response Status code so that others can make use of it.
                 */
            axisInMsgCtx.setProperty(SynapseConstants.HTTP_SC, httpStatusCode);
        } else {
            org.apache.axis2.context.MessageContext result = sendReceive(axisOutMsgCtx, clientOptions, anonymousService, serviceCtx, synapseInMsgCtx);
            if (result.getEnvelope() != null) {
                synapseInMsgCtx.setEnvelope(result.getEnvelope());
                if (JsonUtil.hasAJsonPayload(result)) {
                    JsonUtil.cloneJsonPayload(result, ((Axis2MessageContext) synapseInMsgCtx).getAxis2MessageContext());
                }
            }
            final String statusCode = String.valueOf(result.getProperty(SynapseConstants.HTTP_SENDER_STATUSCODE)).trim();
            /*
                 * We need to set the response status code so that users can
                 * fetch it later.
                 */
            axisInMsgCtx.setProperty(SynapseConstants.HTTP_SC, statusCode);
            if ("false".equals(synapseInMsgCtx.getProperty(SynapseConstants.BLOCKING_SENDER_PRESERVE_REQ_HEADERS))) {
                axisInMsgCtx.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, result.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));
            }
            synapseInMsgCtx.setProperty(SynapseConstants.BLOCKING_SENDER_ERROR, "false");
            this.invokeHandlers(synapseInMsgCtx);
            return synapseInMsgCtx;
        }
    } catch (Exception ex) {
        /*
             * Extract the HTTP status code from the Exception message.
             */
        final String errorStatusCode = extractStatusCodeFromException(ex);
        axisInMsgCtx.setProperty(SynapseConstants.HTTP_SC, errorStatusCode);
        if (!isOutOnly) {
            // axisOutMsgCtx.getTransportOut().getSender().cleanup(axisOutMsgCtx);
            synapseInMsgCtx.setProperty(SynapseConstants.BLOCKING_SENDER_ERROR, "true");
            synapseInMsgCtx.setProperty(SynapseConstants.ERROR_EXCEPTION, ex);
            if (ex instanceof AxisFault) {
                AxisFault fault = (AxisFault) ex;
                setErrorDetails(synapseInMsgCtx, fault);
                org.apache.axis2.context.MessageContext faultMC = fault.getFaultMessageContext();
                if (faultMC != null) {
                    Object statusCode = faultMC.getProperty(SynapseConstants.HTTP_SENDER_STATUSCODE);
                    synapseInMsgCtx.setProperty(SynapseConstants.HTTP_SC, statusCode);
                    axisInMsgCtx.setProperty(SynapseConstants.HTTP_SC, statusCode);
                    synapseInMsgCtx.setEnvelope(faultMC.getEnvelope());
                }
            }
            return synapseInMsgCtx;
        } else {
            if (ex instanceof AxisFault) {
                AxisFault fault = (AxisFault) ex;
                setErrorDetails(synapseInMsgCtx, fault);
            }
        }
        handleException("Error sending Message to url : " + ((AbstractEndpoint) endpoint).getDefinition().getAddress(), ex);
    }
    return null;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ResolvingEndpoint(org.apache.synapse.endpoints.ResolvingEndpoint) SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) Options(org.apache.axis2.client.Options) IndirectEndpoint(org.apache.synapse.endpoints.IndirectEndpoint) Set(java.util.Set) ServiceContext(org.apache.axis2.context.ServiceContext) AxisService(org.apache.axis2.description.AxisService) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) SynapseException(org.apache.synapse.SynapseException) EndpointReference(org.apache.axis2.addressing.EndpointReference) ServiceGroupContext(org.apache.axis2.context.ServiceGroupContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) TemplateEndpoint(org.apache.synapse.endpoints.TemplateEndpoint) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Aggregations

ConfigurationContext (org.apache.axis2.context.ConfigurationContext)184 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)119 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)70 Test (org.junit.Test)64 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)62 Parameter (org.apache.axis2.description.Parameter)56 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)48 OMElement (org.apache.axiom.om.OMElement)43 AxisFault (org.apache.axis2.AxisFault)34 MessageContext (org.apache.synapse.MessageContext)34 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 AxisService (org.apache.axis2.description.AxisService)26 EndpointReference (org.apache.axis2.addressing.EndpointReference)24 MessageContext (org.apache.axis2.context.MessageContext)23 Options (org.apache.axis2.client.Options)22 HashMap (java.util.HashMap)20 ServiceContext (org.apache.axis2.context.ServiceContext)19 Map (java.util.Map)18 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)16