Search in sources :

Example 1 with MutableEndpoint

use of org.apache.ode.bpel.epr.MutableEndpoint in project carbon-business-process by wso2.

the class HTTPBindingHandler method invoke.

public HTTPBindingResponse invoke(final PartnerRoleMessageExchange partnerRoleMessageExchange, final BPELMessageContext bpelMessageContext) throws AxisFault {
    MessageContext messageContext;
    OperationClient operationClient = AxisServiceUtils.getOperationClient(bpelMessageContext, configurationContext);
    operationClient.getOptions().setAction("\"\"");
    operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
    addPropertyToOperationClient(operationClient, WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR, "&");
    addPropertyToOperationClient(operationClient, Constants.Configuration.ENABLE_REST, true);
    addPropertyToOperationClient(operationClient, Constants.Configuration.HTTP_METHOD, getVerb().trim());
    addPropertyToOperationClient(operationClient, WSDL2Constants.ATTR_WHTTP_LOCATION, getHTTPLocation(partnerRoleMessageExchange.getOperationName()));
    addPropertyToOperationClient(operationClient, Constants.Configuration.CONTENT_TYPE, inferContentType(getVerb()));
    addPropertyToOperationClient(operationClient, Constants.Configuration.MESSAGE_TYPE, inferContentType(getVerb()));
    SOAPEnvelope soapEnvelope = getFactory(operationClient.getOptions().getSoapVersionURI()).getDefaultEnvelope();
    messageContext = new MessageContext();
    populateSOAPBody(soapEnvelope, partnerRoleMessageExchange);
    messageContext.setEnvelope(soapEnvelope);
    operationClient.addMessageContext(messageContext);
    String mexEndpointUrl = ((MutableEndpoint) partnerRoleMessageExchange.getEndpointReference()).getUrl();
    if (!mexEndpointUrl.equals(getServiceLocation())) {
        operationClient.getOptions().setTo(new EndpointReference(mexEndpointUrl));
    }
    operationClient.getOptions().setTo(bpelMessageContext.getUep());
    operationClient.execute(true);
    MessageContext responseMessageContext = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    MessageContext faultMessageContext = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);
    return new HTTPBindingResponse(responseMessageContext, faultMessageContext);
}
Also used : OperationClient(org.apache.axis2.client.OperationClient) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MutableEndpoint(org.apache.ode.bpel.epr.MutableEndpoint) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 2 with MutableEndpoint

use of org.apache.ode.bpel.epr.MutableEndpoint 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)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)2 MutableEndpoint (org.apache.ode.bpel.epr.MutableEndpoint)2 Operation (javax.wsdl.Operation)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 HTTPBinding (javax.wsdl.extensions.http.HTTPBinding)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 OperationClient (org.apache.axis2.client.OperationClient)1 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)1