Search in sources :

Example 1 with TenantInfoInitiator

use of org.apache.synapse.commons.util.ext.TenantInfoInitiator in project wso2-synapse by wso2.

the class SynapseConfiguration method initCarbonTenantConfigurator.

/**
 * @param se
 */
private void initCarbonTenantConfigurator(SynapseEnvironment se) {
    Axis2SynapseEnvironment axis2SynapseEnvironment = (Axis2SynapseEnvironment) se;
    // Tenant info configurator
    TenantInfoConfigurator configurator = TenantInfoConfigProvider.getConfigurator();
    axis2SynapseEnvironment.setTenantInfoConfigurator(configurator);
    TenantInfoInitiator tenantInfoInitiator = TenantInfoInitiatorProvider.getTenantInfoInitiator();
    axis2SynapseEnvironment.setTenantInfoInitiator(tenantInfoInitiator);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TenantInfoConfigurator(org.apache.synapse.carbonext.TenantInfoConfigurator) TenantInfoInitiator(org.apache.synapse.commons.util.ext.TenantInfoInitiator)

Example 2 with TenantInfoInitiator

use of org.apache.synapse.commons.util.ext.TenantInfoInitiator in project wso2-synapse by wso2.

the class ClientWorker method run.

public void run() {
    CustomLogSetter.getInstance().clearThreadLocalContent();
    TenantInfoInitiator tenantInfoInitiator = TenantInfoInitiatorProvider.getTenantInfoInitiator();
    if (tenantInfoInitiator != null) {
        tenantInfoInitiator.initTenantInfo();
    }
    if (responseMsgCtx == null) {
        cleanup();
        return;
    }
    if (responseMsgCtx.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION) != null) {
        ((NHttpServerConnection) responseMsgCtx.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION)).getContext().setAttribute(PassThroughConstants.CLIENT_WORKER_START_TIME, System.currentTimeMillis());
    }
    try {
        if (expectEntityBody) {
            String cType = response.getHeader(HTTP.CONTENT_TYPE);
            if (cType == null) {
                cType = response.getHeader(HTTP.CONTENT_TYPE.toLowerCase());
            }
            String contentType;
            if (cType != null) {
                // This is the most common case - Most of the time servers send the Content-Type
                contentType = cType;
            } else {
                // Server hasn't sent the header - Try to infer the content type
                contentType = inferContentType();
            }
            responseMsgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
            String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
            if (charSetEnc == null) {
                charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
            }
            if (contentType != null) {
                responseMsgCtx.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, contentType.indexOf("charset") > 0 ? charSetEnc : MessageContext.DEFAULT_CHAR_SET_ENCODING);
                responseMsgCtx.removeProperty(PassThroughConstants.NO_ENTITY_BODY);
            }
            responseMsgCtx.setServerSide(false);
            SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
            SOAPEnvelope envelope = fac.getDefaultEnvelope();
            try {
                responseMsgCtx.setEnvelope(envelope);
            } catch (AxisFault axisFault) {
                log.error("Error setting SOAP envelope", axisFault);
            }
            responseMsgCtx.setServerSide(true);
        } else {
            // there is no response entity-body
            responseMsgCtx.setProperty(PassThroughConstants.NO_ENTITY_BODY, Boolean.TRUE);
            responseMsgCtx.setEnvelope(new SOAP11Factory().getDefaultEnvelope());
        }
        // copy the HTTP status code as a message context property with the key HTTP_SC to be
        // used at the sender to set the proper status code when passing the message
        int statusCode = this.response.getStatus();
        responseMsgCtx.setProperty(PassThroughConstants.HTTP_SC, statusCode);
        responseMsgCtx.setProperty(PassThroughConstants.HTTP_SC_DESC, response.getStatusLine());
        if (statusCode >= 400) {
            responseMsgCtx.setProperty(PassThroughConstants.FAULT_MESSAGE, PassThroughConstants.TRUE);
        }
        /*else if (statusCode == 202 && responseMsgCtx.getOperationContext().isComplete()) {
                // Handle out-only invocation scenario
                responseMsgCtx.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE);
            }*/
        responseMsgCtx.setProperty(PassThroughConstants.NON_BLOCKING_TRANSPORT, true);
        // process response received
        try {
            AxisEngine.receive(responseMsgCtx);
        } catch (AxisFault af) {
            log.error("Fault processing response message through Axis2", af);
        }
    } catch (AxisFault af) {
        log.error("Fault creating response SOAP envelope", af);
    } finally {
        cleanup();
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) TenantInfoInitiator(org.apache.synapse.commons.util.ext.TenantInfoInitiator) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 3 with TenantInfoInitiator

use of org.apache.synapse.commons.util.ext.TenantInfoInitiator in project wso2-synapse by wso2.

the class ServerWorker method cleanup.

/**
 * Perform cleanup of ServerWorker
 */
private void cleanup() {
    // clean threadLocal variables
    MessageContext.destroyCurrentMessageContext();
    // clean tenantInfo
    TenantInfoInitiator tenantInfoInitiator = TenantInfoInitiatorProvider.getTenantInfoInitiator();
    if (tenantInfoInitiator != null) {
        tenantInfoInitiator.cleanTenantInfo();
    }
}
Also used : TenantInfoInitiator(org.apache.synapse.commons.util.ext.TenantInfoInitiator)

Example 4 with TenantInfoInitiator

use of org.apache.synapse.commons.util.ext.TenantInfoInitiator in project wso2-synapse by wso2.

the class ServerWorker method run.

public void run() {
    try {
        CustomLogSetter.getInstance().clearThreadLocalContent();
        TenantInfoInitiator tenantInfoInitiator = TenantInfoInitiatorProvider.getTenantInfoInitiator();
        if (tenantInfoInitiator != null) {
            tenantInfoInitiator.initTenantInfo(request.getUri());
        }
        request.getConnection().getContext().setAttribute(NhttpConstants.SERVER_WORKER_START_TIME, System.currentTimeMillis());
        if (log.isDebugEnabled()) {
            log.debug("Starting a new Server Worker instance");
        }
        String method = request.getRequest() != null ? request.getRequest().getRequestLine().getMethod().toUpperCase() : "";
        processHttpRequestUri(msgContext, method);
        // For requests to fetch wsdl, return the message flow without going through the normal flow
        if (isRequestToFetchWSDL()) {
            return;
        }
        // need special case to handle REST
        boolean isRest = isRESTRequest(msgContext, method);
        // should be process normally
        if (!isRest) {
            if (request.isEntityEnclosing()) {
                processEntityEnclosingRequest(msgContext, true);
            } else {
                processNonEntityEnclosingRESTHandler(null, msgContext, true);
            }
        } else {
            String contentTypeHeader = request.getHeaders().get(HTTP.CONTENT_TYPE);
            SOAPEnvelope soapEnvelope = this.handleRESTUrlPost(contentTypeHeader);
            processNonEntityEnclosingRESTHandler(soapEnvelope, msgContext, true);
        }
        sendAck(msgContext);
    } finally {
        cleanup();
    }
}
Also used : TenantInfoInitiator(org.apache.synapse.commons.util.ext.TenantInfoInitiator) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Aggregations

TenantInfoInitiator (org.apache.synapse.commons.util.ext.TenantInfoInitiator)4 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 SOAPFactory (org.apache.axiom.soap.SOAPFactory)1 SOAP11Factory (org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory)1 AxisFault (org.apache.axis2.AxisFault)1 TenantInfoConfigurator (org.apache.synapse.carbonext.TenantInfoConfigurator)1 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)1