Search in sources :

Example 1 with ServiceGroupContext

use of org.apache.axis2.context.ServiceGroupContext 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));
    // 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");
            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)

Example 2 with ServiceGroupContext

use of org.apache.axis2.context.ServiceGroupContext in project pentaho-platform by pentaho.

the class AxisServiceExecutor method createServiceContent.

@Override
public void createServiceContent(AxisService axisService, String operationName, AxisConfiguration axisConfiguration, ConfigurationContext context, OutputStream out) throws Exception {
    // $NON-NLS-1$
    IParameterProvider pathParams = parameterProviders.get("path");
    // get the HTTP objects from the 'path' parameter provider
    // $NON-NLS-1$
    HttpServletRequest request = (HttpServletRequest) pathParams.getParameter("httprequest");
    @SuppressWarnings("unchecked") Enumeration names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (name.equalsIgnoreCase("wsdl")) {
            // $NON-NLS-1$
            axisService.printWSDL(out, AxisUtil.getWebServiceExecuteUrl());
            return;
        }
    }
    // $NON-NLS-1$
    HttpServletResponse response = (HttpServletResponse) pathParams.getParameter("httpresponse");
    // $NON-NLS-1$
    ServletConfig servletConfig = (ServletConfig) pathParams.getParameter("servletconfig");
    // create a service group and group context for this service
    AxisServiceGroup axisServiceGroup = new AxisServiceGroup(context.getAxisConfiguration());
    axisServiceGroup.addService(axisService);
    ServiceGroupContext serviceGroupContext = new ServiceGroupContext(context, axisServiceGroup);
    // create a service context
    ServiceContext serviceContext = serviceGroupContext.getServiceContext(axisService);
    // get an operation by name, if possible
    AxisOperation axisOperation = axisService.getOperationByAction(operationName);
    OperationContext operationContext = serviceContext.createOperationContext(axisOperation);
    // create an object to hook into Axis and give it everything we have
    AxisServletHooks hooks = new AxisServletHooks();
    hooks.setContext(context);
    hooks.setServletConfig(servletConfig);
    hooks.setConfiguration(axisConfiguration);
    hooks.initContextRoot(request);
    hooks.setAxisService(axisService);
    hooks.setAxisOperation(axisOperation);
    hooks.setOperationContext(operationContext);
    hooks.setServiceContext(serviceContext);
    hooks.setAxisOperation(axisOperation);
    hooks.setOperationContext(operationContext);
    // now execute the operation
    if (request != null && response != null) {
        try {
            PentahoSessionHolder.setSession(userSession);
            String method = request.getMethod();
            if ("GET".equalsIgnoreCase(method)) {
                // $NON-NLS-1$
                hooks.handleGet(method, request, response);
            } else if ("POST".equalsIgnoreCase(request.getMethod())) {
                // $NON-NLS-1$
                hooks.handlePost(method, request, response);
            } else if ("PUT".equalsIgnoreCase(request.getMethod())) {
                // $NON-NLS-1$
                hooks.handlePut(method, request, response);
            }
        } catch (Exception e) {
            processAxisFault(hooks.getMessageContext(), out, e);
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("RunService.ERROR_0001_ERROR_DURING_EXECUTION"), e);
        }
    }
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) Enumeration(java.util.Enumeration) AxisOperation(org.apache.axis2.description.AxisOperation) ServiceContext(org.apache.axis2.context.ServiceContext) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) AxisServiceGroup(org.apache.axis2.description.AxisServiceGroup) HttpServletRequest(javax.servlet.http.HttpServletRequest) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) ServiceGroupContext(org.apache.axis2.context.ServiceGroupContext) AxisServletHooks(org.pentaho.platform.plugin.services.webservices.AxisServletHooks)

Example 3 with ServiceGroupContext

use of org.apache.axis2.context.ServiceGroupContext in project carbon-business-process by wso2.

the class AxisServiceUtils method getOperationClient.

public static OperationClient getOperationClient(BPELMessageContext partnerMessageContext, ConfigurationContext clientConfigCtx) throws AxisFault {
    AxisService anonymousService = AnonymousServiceFactory.getAnonymousService(partnerMessageContext.getService(), partnerMessageContext.getPort(), clientConfigCtx.getAxisConfiguration(), partnerMessageContext.getCaller());
    anonymousService.engageModule(clientConfigCtx.getAxisConfiguration().getModule("UEPModule"));
    anonymousService.getParent().addParameter(BPELConstants.HIDDEN_SERVICE_PARAM, "true");
    ServiceGroupContext sgc = new ServiceGroupContext(clientConfigCtx, (AxisServiceGroup) anonymousService.getParent());
    ServiceContext serviceCtx = sgc.getServiceContext(anonymousService);
    // get a reference to the DYNAMIC operation of the Anonymous Axis2 service
    AxisOperation axisAnonymousOperation = anonymousService.getOperation(partnerMessageContext.isTwoWay() ? ServiceClient.ANON_OUT_IN_OP : ServiceClient.ANON_OUT_ONLY_OP);
    Options clientOptions = cloneOptions(partnerMessageContext.getInMessageContext().getOptions());
    clientOptions.setExceptionToBeThrownOnSOAPFault(false);
    /* This value doesn't overrideend point config. */
    clientOptions.setTimeOutInMilliSeconds(60000);
    return axisAnonymousOperation.createClient(serviceCtx, clientOptions);
}
Also used : Options(org.apache.axis2.client.Options) AxisOperation(org.apache.axis2.description.AxisOperation) ServiceGroupContext(org.apache.axis2.context.ServiceGroupContext) ServiceContext(org.apache.axis2.context.ServiceContext) AxisService(org.apache.axis2.description.AxisService)

Example 4 with ServiceGroupContext

use of org.apache.axis2.context.ServiceGroupContext in project carbon-business-process by wso2.

the class ServiceUtils method getOperationClient.

private static OperationClient getOperationClient(MessageContext partnerMessageContext, ConfigurationContext clientConfigCtx) throws AxisFault {
    AxisService anonymousService = AnonymousServiceFactory.getAnonymousService(Constants.registrationService, Constants.REGISTRATION_PORT, clientConfigCtx.getAxisConfiguration(), Constants.HUMANTASK_COORDINATION_MODULE_NAME);
    anonymousService.getParent().addParameter("hiddenService", "true");
    ServiceGroupContext sgc = new ServiceGroupContext(clientConfigCtx, (AxisServiceGroup) anonymousService.getParent());
    ServiceContext serviceCtx = sgc.getServiceContext(anonymousService);
    AxisOperation axisAnonymousOperation = anonymousService.getOperation(ServiceClient.ANON_OUT_IN_OP);
    Options clientOptions = cloneOptions(partnerMessageContext.getOptions());
    clientOptions.setExceptionToBeThrownOnSOAPFault(false);
    /* This value doesn't overrideend point config. */
    clientOptions.setTimeOutInMilliSeconds(60000);
    return axisAnonymousOperation.createClient(serviceCtx, clientOptions);
}
Also used : Options(org.apache.axis2.client.Options) AxisOperation(org.apache.axis2.description.AxisOperation) ServiceGroupContext(org.apache.axis2.context.ServiceGroupContext) ServiceContext(org.apache.axis2.context.ServiceContext) AxisService(org.apache.axis2.description.AxisService)

Example 5 with ServiceGroupContext

use of org.apache.axis2.context.ServiceGroupContext in project MassBank-web by MassBank.

the class AdminActions method viewServiceContext.

@Action(name = "viewServiceContext")
public View viewServiceContext(HttpServletRequest req) throws AxisFault {
    String type = req.getParameter("TYPE");
    String sgID = req.getParameter("PID");
    String ID = req.getParameter("ID");
    ServiceGroupContext sgContext = configContext.getServiceGroupContext(sgID);
    if (sgContext != null) {
        AxisService service = sgContext.getDescription().getService(ID);
        ServiceContext serviceContext = sgContext.getServiceContext(service);
        req.setAttribute("ServiceContext", serviceContext);
        req.setAttribute("TYPE", type);
    } else {
        req.setAttribute("ServiceContext", null);
        req.setAttribute("TYPE", type);
    }
    return new View("viewServiceContext.jsp");
}
Also used : ServiceGroupContext(org.apache.axis2.context.ServiceGroupContext) ServiceContext(org.apache.axis2.context.ServiceContext) AxisService(org.apache.axis2.description.AxisService)

Aggregations

ServiceGroupContext (org.apache.axis2.context.ServiceGroupContext)9 ServiceContext (org.apache.axis2.context.ServiceContext)8 AxisService (org.apache.axis2.description.AxisService)7 AxisOperation (org.apache.axis2.description.AxisOperation)6 Options (org.apache.axis2.client.Options)5 EndpointReference (org.apache.axis2.addressing.EndpointReference)3 SynapseException (org.apache.synapse.SynapseException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 OperationContext (org.apache.axis2.context.OperationContext)2 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 TreeMap (java.util.TreeMap)1 ContentType (javax.mail.internet.ContentType)1