Search in sources :

Example 16 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project carbon-business-process by wso2.

the class PartnerService method invoke.

public void invoke(final PartnerRoleMessageExchange partnerRoleMessageExchange) {
    boolean isTwoWay = (partnerRoleMessageExchange.getMessageExchangePattern() == MessageExchange.MessageExchangePattern.REQUEST_RESPONSE);
    try {
        // Override options are passed to the axis MessageContext so we can
        // retrieve them in our session out changeHandler
        // 
        // Below logic is required only if tenant information from the thread local context is required here.
        // However,
        // it does not seem required, hence commenting out.
        String deployer = processConfiguration.getDeployer();
        if (log.isDebugEnabled()) {
            String msg = "Process Name => " + processConfiguration.getProcessId() + " Deployer =>" + processConfiguration.getDeployer();
            log.debug(msg);
        }
        PrivilegedCarbonContext.startTenantFlow();
        // Assuming that deployer should not be null
        String domain = BPELServerHolder.getInstance().getRealmService().getTenantManager().getDomain(Integer.parseInt(deployer));
        if (domain != null) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(domain);
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(Integer.parseInt(deployer));
        } else {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(Integer.parseInt(deployer));
        }
        final MessageContext mctx = new MessageContext();
        BPELMessageContext partnerInvocationContext = BPELMessageContextFactory.createBPELMessageContext(mctx, this);
        ExtensibilityElement bindingType = WSDLAwareSOAPProcessor.getBindingExtension(binding);
        try {
            if (bindingType instanceof HTTPBinding) {
                // =========================================================
                if (uep.getAddress() == null) {
                    uep.setAddress(endpointUrl);
                }
                partnerInvocationContext.setUep(uep);
                partnerInvocationContext.setTwoWay(isTwoWay);
                partnerInvocationContext.setService(serviceName);
                partnerInvocationContext.setPort(portName);
                partnerInvocationContext.setCaller(partnerRoleMessageExchange.getCaller().getLocalPart());
                partnerInvocationContext.setOperationName(partnerRoleMessageExchange.getOperationName());
                SOAPUtils.createSOAPRequest(partnerInvocationContext, partnerRoleMessageExchange);
                String mexEndpointUrl = ((MutableEndpoint) partnerRoleMessageExchange.getEndpointReference()).getUrl();
                if (!endpointUrl.equals(mexEndpointUrl)) {
                    uep.setAddress(mexEndpointUrl);
                }
                if (messageTraceLog.isDebugEnabled()) {
                    messageTraceLog.debug("Invoking service: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + serviceName + "." + partnerRoleMessageExchange.getOperationName());
                    if (messageTraceLog.isTraceEnabled()) {
                        messageTraceLog.trace("Request message: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + partnerInvocationContext.getInMessageContext().getEnvelope());
                    }
                }
                HTTPBindingHandler httpBindingHandler = new HTTPBindingHandler(clientConfigCtx, serviceName, portName, wsdlDefinition);
                HTTPBindingHandler.HTTPBindingResponse response = httpBindingHandler.invoke(partnerRoleMessageExchange, partnerInvocationContext);
                if (isTwoWay) {
                    MessageContext responseMessageContext = response.getReponseMessageContext();
                    partnerInvocationContext.setOutMessageContext(responseMessageContext);
                    MessageContext fltMessageContext = response.getFaultMessageContext();
                    if (messageTraceLog.isTraceEnabled()) {
                        messageTraceLog.trace("Response message: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + responseMessageContext.getEnvelope());
                    }
                    if (fltMessageContext != null) {
                        replyHTTP(partnerInvocationContext, partnerRoleMessageExchange, true);
                    } else {
                        replyHTTP(partnerInvocationContext, partnerRoleMessageExchange, response.isFault());
                    }
                } else {
                    /* one-way case */
                    partnerRoleMessageExchange.replyOneWayOk();
                }
            } else {
                if (uep.getAddress() == null) {
                    uep.setAddress(endpointUrl);
                }
                partnerInvocationContext.setUep(uep);
                partnerInvocationContext.setTwoWay(isTwoWay);
                partnerInvocationContext.setService(serviceName);
                partnerInvocationContext.setPort(portName);
                partnerInvocationContext.setCaller(partnerRoleMessageExchange.getCaller().getLocalPart());
                partnerInvocationContext.setOperationName(partnerRoleMessageExchange.getOperationName());
                SOAPUtils.createSOAPRequest(partnerInvocationContext, partnerRoleMessageExchange);
                String mexEndpointUrl = ((MutableEndpoint) partnerRoleMessageExchange.getEndpointReference()).getUrl();
                if (!endpointUrl.equals(mexEndpointUrl)) {
                    uep.setAddress(mexEndpointUrl);
                }
                if (messageTraceLog.isDebugEnabled()) {
                    messageTraceLog.debug("Invoking service: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + serviceName + "." + partnerRoleMessageExchange.getOperationName());
                    if (messageTraceLog.isTraceEnabled()) {
                        messageTraceLog.trace("Request message: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + partnerInvocationContext.getInMessageContext().getEnvelope());
                    }
                }
                AxisServiceUtils.invokeService(partnerInvocationContext, clientConfigCtx);
                if (messageTraceLog.isDebugEnabled()) {
                    messageTraceLog.debug("Service invocation completed: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + serviceName + "." + partnerRoleMessageExchange.getOperationName());
                }
                if (isTwoWay) {
                    final Operation operation = partnerRoleMessageExchange.getOperation();
                    MessageContext response = partnerInvocationContext.getOutMessageContext();
                    MessageContext flt = partnerInvocationContext.getFaultMessageContext();
                    if (messageTraceLog.isTraceEnabled()) {
                        messageTraceLog.trace("Response message: MEXId: " + partnerRoleMessageExchange.getMessageExchangeId() + " :: " + response.getEnvelope());
                    }
                    if (flt != null) {
                        reply(partnerInvocationContext, partnerRoleMessageExchange, operation, flt, true);
                    } else {
                        reply(partnerInvocationContext, partnerRoleMessageExchange, operation, response, response.isFault());
                    }
                } else {
                    /* one-way case */
                    partnerRoleMessageExchange.replyOneWayOk();
                }
            }
        } finally {
            // make sure the HTTP connection is released to the pool!
            TransportOutDescription out = mctx.getTransportOut();
            if (out != null && out.getSender() != null) {
                out.getSender().cleanup(mctx);
            }
        }
    } catch (Exception e) {
        String errmsg = Messages.msgErrorSendingMessageToAxisForODEMex(partnerRoleMessageExchange.toString());
        log.error(errmsg, e);
        replyWithFailure(partnerRoleMessageExchange, MessageExchange.FailureType.COMMUNICATION_ERROR, errmsg);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) Operation(javax.wsdl.Operation) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) HTTPBinding(javax.wsdl.extensions.http.HTTPBinding) MutableEndpoint(org.apache.ode.bpel.epr.MutableEndpoint) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 17 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project carbon-apimgt by wso2.

the class TestUtils method initConfigurationContextService.

/**
 * To initialize the (@link {@link ConfigurationContextService}} for testing.
 *
 * @return initialized configuration context service.
 */
public static ConfigurationContextService initConfigurationContextService(boolean initAPIMConfigurationService) throws XMLStreamException {
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    AxisConfiguration axisConfiguration = Mockito.mock(AxisConfiguration.class);
    Mockito.doReturn(axisConfiguration).when(configurationContext).getAxisConfiguration();
    TransportInDescription transportInDescription = Mockito.mock(TransportInDescription.class);
    Mockito.doReturn(transportInDescription).when(axisConfiguration).getTransportIn(Mockito.anyString());
    Parameter dynamicSSLProfilesConfigParameter = Mockito.mock(Parameter.class);
    Mockito.when(dynamicSSLProfilesConfigParameter.getParameterElement()).thenReturn(getDynamicSSLElement());
    Mockito.when(transportInDescription.getParameter("dynamicSSLProfilesConfig")).thenReturn(dynamicSSLProfilesConfigParameter);
    TransportOutDescription transportOutDescription = Mockito.mock(TransportOutDescription.class);
    Mockito.doReturn(transportOutDescription).when(axisConfiguration).getTransportOut(Mockito.anyString());
    Mockito.when(transportOutDescription.getParameter("dynamicSSLProfilesConfig")).thenReturn(dynamicSSLProfilesConfigParameter);
    Mockito.doReturn(configurationContext).when(configurationContextService).getServerConfigContext();
    if (initAPIMConfigurationService) {
        APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
        APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
        Mockito.doReturn("true").when(apiManagerConfiguration).getFirstProperty(APIConstants.ENABLE_MTLS_FOR_APIS);
        Mockito.doReturn(apiManagerConfiguration).when(apiManagerConfigurationService).getAPIManagerConfiguration();
        ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
    }
    ServiceReferenceHolder.setContextService(configurationContextService);
    System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
    System.setProperty("javax.net.ssl.trustStore", ".");
    return configurationContextService;
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Parameter(org.apache.axis2.description.Parameter) TransportInDescription(org.apache.axis2.description.TransportInDescription) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 18 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-axis2-transports by wso2.

the class JMSTransportDescriptionFactory method createTransportOutDescription.

public TransportOutDescription createTransportOutDescription() throws Exception {
    TransportOutDescription trpOutDesc = new TransportOutDescription(JMSSender.TRANSPORT_NAME);
    if (cfOnSender) {
        setupTransport(trpOutDesc);
    }
    trpOutDesc.setSender(new JMSSender());
    return trpOutDesc;
}
Also used : TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 19 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-axis2-transports by wso2.

the class SimpleTransportDescriptionFactory method createTransportOutDescription.

public TransportOutDescription createTransportOutDescription() throws Exception {
    TransportOutDescription trpOutDesc = new TransportOutDescription(name);
    trpOutDesc.setSender(senderClass.newInstance());
    return trpOutDesc;
}
Also used : TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 20 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-axis2-transports by wso2.

the class AxisTestClientContext method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(TransportDescriptionFactory tdf, AxisTestClientContextConfigurator[] configurators) throws Exception {
    cfgCtx = ConfigurationContextFactory.createConfigurationContext(new CustomAxisConfigurator());
    AxisConfiguration axisCfg = cfgCtx.getAxisConfiguration();
    TransportOutDescription trpOutDesc = tdf.createTransportOutDescription();
    axisCfg.addTransportOut(trpOutDesc);
    sender = trpOutDesc.getSender();
    sender.init(cfgCtx, trpOutDesc);
    boolean useListener = false;
    for (AxisTestClientContextConfigurator configurator : configurators) {
        if (configurator.isTransportListenerRequired()) {
            useListener = true;
            break;
        }
    }
    TransportInDescription trpInDesc;
    if (useListener) {
        trpInDesc = tdf.createTransportInDescription();
    } else {
        trpInDesc = null;
    }
    for (AxisTestClientContextConfigurator configurator : configurators) {
        configurator.setupTransport(trpInDesc, trpOutDesc);
    }
    if (useListener) {
        listenerManager = new ListenerManager();
        listenerManager.init(cfgCtx);
        cfgCtx.setTransportManager(listenerManager);
        listenerManager.addListener(trpInDesc, false);
        listenerManager.start();
    }
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) CustomAxisConfigurator(org.apache.axis2.transport.CustomAxisConfigurator) TransportInDescription(org.apache.axis2.description.TransportInDescription) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) ListenerManager(org.apache.axis2.engine.ListenerManager) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Aggregations

TransportOutDescription (org.apache.axis2.description.TransportOutDescription)28 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)20 Parameter (org.apache.axis2.description.Parameter)17 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)16 MessageContext (org.apache.axis2.context.MessageContext)11 AxisFault (org.apache.axis2.AxisFault)9 QName (javax.xml.namespace.QName)7 OMElement (org.apache.axiom.om.OMElement)6 AxisService (org.apache.axis2.description.AxisService)6 TransportInDescription (org.apache.axis2.description.TransportInDescription)6 IOException (java.io.IOException)4 Map (java.util.Map)4 ServiceContext (org.apache.axis2.context.ServiceContext)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)3 OperationContext (org.apache.axis2.context.OperationContext)3 InOutAxisOperation (org.apache.axis2.description.InOutAxisOperation)3 OutTransportInfo (org.apache.axis2.transport.OutTransportInfo)3 VFSOutTransportInfo (org.apache.synapse.commons.vfs.VFSOutTransportInfo)3