Search in sources :

Example 6 with Integer

use of org.apache.axis2.databinding.types.soapencoding.Integer in project wso2-synapse by wso2.

the class ListenerContextBuilder method parse.

public ListenerContextBuilder parse() throws AxisFault {
    Parameter param = transportIn.getParameter(TransportListener.HOST_ADDRESS);
    if (param != null) {
        host = ((String) param.getValue()).trim();
    } else {
        try {
            host = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            log.warn("Unable to lookup local host name, using 'localhost'");
        }
    }
    param = transportIn.getParameter(TransportListener.PARAM_PORT);
    if (param != null) {
        port = Integer.parseInt((String) param.getValue());
    }
    int portOffset = 0;
    try {
        portOffset = Integer.parseInt(System.getProperty(NhttpConstants.PORT_OFFSET, "0"));
    } catch (NumberFormatException e) {
        handleException("portOffset System property should be a valid Integer", e);
    }
    port = port + portOffset;
    if (param != null) {
        param.setValue(String.valueOf(port));
        param.getParameterElement().setText(String.valueOf(port));
    }
    param = transportIn.getParameter(NhttpConstants.BIND_ADDRESS);
    if (param != null) {
        String s = ((String) param.getValue()).trim();
        try {
            bindAddress = InetAddress.getByName(s);
        } catch (UnknownHostException ex) {
            throw AxisFault.makeFault(ex);
        }
    }
    // create the priority based executor and parser
    param = transportIn.getParameter(NhttpConstants.PRIORITY_CONFIG_FILE_NAME);
    if (param != null && param.getValue() != null) {
        String fileName = param.getValue().toString();
        OMElement definitions = null;
        try {
            FileInputStream fis = new FileInputStream(fileName);
            definitions = new StAXOMBuilder(fis).getDocumentElement();
            definitions.build();
        } catch (FileNotFoundException e) {
            handleException("Priority configuration file cannot be found : " + fileName, e);
        } catch (XMLStreamException e) {
            handleException("Error parsing priority configuration xml file " + fileName, e);
        }
        executor = createPriorityExecutor(definitions);
        parser = createParser(definitions);
        if (log.isInfoEnabled()) {
            log.info(name + " Created a priority based executor from the configuration: " + fileName);
        }
    }
    param = transportIn.getParameter(NhttpConstants.DISABLE_REST_SERVICE_DISPATCHING);
    if (param != null && param.getValue() != null) {
        if (param.getValue().equals("true")) {
            restDispatching = false;
        }
    }
    // create http Get processor
    param = transportIn.getParameter(NhttpConstants.HTTP_GET_PROCESSOR);
    if (param != null && param.getValue() != null) {
        httpGetRequestProcessor = createHttpGetProcessor(param.getValue().toString());
        if (httpGetRequestProcessor == null) {
            handleException("Cannot create HttpGetRequestProcessor");
        }
    } else {
        httpGetRequestProcessor = new DefaultHttpGetProcessor();
    }
    return this;
}
Also used : UnknownHostException(java.net.UnknownHostException) XMLStreamException(javax.xml.stream.XMLStreamException) FileNotFoundException(java.io.FileNotFoundException) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) FileInputStream(java.io.FileInputStream)

Example 7 with Integer

use of org.apache.axis2.databinding.types.soapencoding.Integer in project wso2-synapse by wso2.

the class SynapseCallbackReceiver method handleMessage.

/**
 * Handle the response or error (during a failed send) message received for an outgoing request
 *
 * @param messageID        Request message ID
 * @param response         the Axis2 MessageContext that has been received and has to be handled
 * @param synapseOutMsgCtx the corresponding (outgoing) Synapse MessageContext for the above
 *                         Axis2 MC, that holds Synapse specific information such as the error
 *                         handler stack and local properties etc.
 * @throws AxisFault       if the message cannot be processed
 */
private void handleMessage(String messageID, MessageContext response, org.apache.synapse.MessageContext synapseOutMsgCtx, AsyncCallback callback) throws AxisFault {
    // apply the tenant information to the out message context
    TenantInfoConfigurator configurator = synapseOutMsgCtx.getEnvironment().getTenantInfoConfigurator();
    if (configurator != null) {
        configurator.applyTenantInfo(synapseOutMsgCtx);
    }
    Boolean isConcurrencyThrottleEnabled = (Boolean) synapseOutMsgCtx.getProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE);
    if (isConcurrencyThrottleEnabled != null && isConcurrencyThrottleEnabled) {
        ConcurrentAccessController concurrentAccessController = (ConcurrentAccessController) synapseOutMsgCtx.getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_CONTROLLER);
        int available = concurrentAccessController.incrementAndGet();
        int concurrentLimit = concurrentAccessController.getLimit();
        if (log.isDebugEnabled()) {
            log.debug("Concurrency Throttle : Connection returned" + " :: " + available + " of available of " + concurrentLimit + " connections");
        }
        ConcurrentAccessReplicator concurrentAccessReplicator = (ConcurrentAccessReplicator) synapseOutMsgCtx.getProperty(SynapseConstants.SYNAPSE_CONCURRENT_ACCESS_REPLICATOR);
        String throttleKey = (String) synapseOutMsgCtx.getProperty(SynapseConstants.SYNAPSE_CONCURRENCY_THROTTLE_KEY);
        if (concurrentAccessReplicator != null) {
            concurrentAccessReplicator.replicate(throttleKey, true);
        }
    }
    Object o = response.getProperty(SynapseConstants.SENDING_FAULT);
    if (o != null && Boolean.TRUE.equals(o)) {
        // This path hits with a fault. Sequence mediator threads should not remove faultSequence.
        // SynapseCallbackReceiver thread should handle the faultStack.
        Pipe pipe = (Pipe) ((Axis2MessageContext) synapseOutMsgCtx).getAxis2MessageContext().getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
        if (pipe != null && pipe.isSerializationComplete()) {
            NHttpServerConnection conn = (NHttpServerConnection) ((Axis2MessageContext) synapseOutMsgCtx).getAxis2MessageContext().getProperty("pass-through.Source-Connection");
            SourceConfiguration sourceConfiguration = (SourceConfiguration) ((Axis2MessageContext) synapseOutMsgCtx).getAxis2MessageContext().getProperty("PASS_THROUGH_SOURCE_CONFIGURATION");
            Pipe newPipe = new Pipe(conn, sourceConfiguration.getBufferFactory().getBuffer(), "source", sourceConfiguration);
            ((Axis2MessageContext) synapseOutMsgCtx).getAxis2MessageContext().setProperty(PassThroughConstants.PASS_THROUGH_PIPE, newPipe);
        }
        // there is a sending fault. propagate the fault to fault handlers.
        Stack faultStack = synapseOutMsgCtx.getFaultStack();
        if (faultStack != null && !faultStack.isEmpty()) {
            // fault envelope
            try {
                synapseOutMsgCtx.getEnvelope().build();
            } catch (Exception x) {
                synapseOutMsgCtx.setEnvelope(response.getEnvelope());
            }
            Exception e = (Exception) response.getProperty(SynapseConstants.ERROR_EXCEPTION);
            synapseOutMsgCtx.setProperty(SynapseConstants.SENDING_FAULT, Boolean.TRUE);
            synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_CODE, response.getProperty(SynapseConstants.ERROR_CODE));
            synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_MESSAGE, response.getProperty(SynapseConstants.ERROR_MESSAGE));
            synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_DETAIL, response.getProperty(SynapseConstants.ERROR_DETAIL));
            synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_EXCEPTION, e);
            if (synapseOutMsgCtx.getEnvironment().isContinuationEnabled()) {
                synapseOutMsgCtx.setContinuationEnabled(true);
            }
            if (log.isDebugEnabled()) {
                log.debug("[Failed Request Message ID : " + messageID + "]" + " [New to be Retried Request Message ID : " + synapseOutMsgCtx.getMessageID() + "]");
            }
            int errorCode = (Integer) response.getProperty(SynapseConstants.ERROR_CODE);
            // If a timeout has occured and the timeout action of the callback is to discard the message
            if (errorCode == SynapseConstants.NHTTP_CONNECTION_TIMEOUT && callback.getTimeOutAction() == SynapseConstants.DISCARD) {
                // Do not execute any fault sequences. Discard message
                if (log.isWarnEnabled()) {
                    log.warn("Synapse timed out for the request with Message ID : " + messageID + ". Ignoring fault handlers since the timeout action is DISCARD");
                }
                faultStack.removeAllElements();
            } else {
                ((FaultHandler) faultStack.pop()).handleFault(synapseOutMsgCtx, null);
            }
        }
    } else {
        // there can always be only one instance of an Endpoint in the faultStack of a message
        // if the send was successful, so remove it before we proceed any further
        Stack faultStack = synapseOutMsgCtx.getFaultStack();
        Endpoint successfulEndpoint = null;
        if (faultStack != null && !faultStack.isEmpty() && faultStack.peek() instanceof Endpoint) {
            successfulEndpoint = (Endpoint) faultStack.pop();
        }
        if (log.isDebugEnabled()) {
            log.debug("Synapse received an asynchronous response message");
            log.debug("Received To: " + (response.getTo() != null ? response.getTo().getAddress() : "null"));
            log.debug("SOAPAction: " + (response.getSoapAction() != null ? response.getSoapAction() : "null"));
            log.debug("WSA-Action: " + (response.getWSAAction() != null ? response.getWSAAction() : "null"));
            String[] cids = null;
            try {
                cids = response.getAttachmentMap().getAllContentIDs();
            } catch (Exception ex) {
                // partially read stream could lead to corrupted attachment map and hence this exception
                // corrupted attachment map leads to inconsistent runtime exceptions and behavior
                // discard the attachment map for the fault handler invocation
                // ensure the successful completion for fault handler flow
                response.setAttachmentMap(null);
                log.error("Synapse encountered an exception when reading attachments from bytes stream. " + "Hence Attachments map is dropped from the message context.", ex);
            }
            if (cids != null && cids.length > 0) {
                for (String cid : cids) {
                    log.debug("Attachment : " + cid);
                }
            }
            log.debug("Body : \n" + response.getEnvelope());
        }
        MessageContext axisOutMsgCtx = ((Axis2MessageContext) synapseOutMsgCtx).getAxis2MessageContext();
        // Processes 'Accept-Encoding'
        ResponseAcceptEncodingProcessor.process(response, axisOutMsgCtx);
        response.setServiceContext(null);
        response.setOperationContext(axisOutMsgCtx.getOperationContext());
        response.setAxisMessage(axisOutMsgCtx.getAxisOperation().getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE));
        // set properties on response
        response.setServerSide(true);
        response.setProperty(SynapseConstants.ISRESPONSE_PROPERTY, Boolean.TRUE);
        response.setProperty(MessageContext.TRANSPORT_OUT, axisOutMsgCtx.getProperty(MessageContext.TRANSPORT_OUT));
        response.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, axisOutMsgCtx.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
        response.setTransportIn(axisOutMsgCtx.getTransportIn());
        response.setTransportOut(axisOutMsgCtx.getTransportOut());
        // response.setDoingREST(axisOutMsgCtx.isDoingREST()); This information already present, hence removing
        if (axisOutMsgCtx.isDoingMTOM() && (axisOutMsgCtx.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM) == null || Boolean.getBoolean((String) axisOutMsgCtx.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM)) == true)) {
            response.setDoingMTOM(true);
            response.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM, org.apache.axis2.Constants.VALUE_TRUE);
        }
        if (axisOutMsgCtx.isDoingSwA()) {
            response.setDoingSwA(true);
            response.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA, org.apache.axis2.Constants.VALUE_TRUE);
        }
        // property state to original state.
        if (axisOutMsgCtx.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES) != null) {
            response.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, axisOutMsgCtx.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES));
        } else {
            response.removeProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
        }
        Object messageType = axisOutMsgCtx.getProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE);
        if (!HTTPConstants.MEDIA_TYPE_X_WWW_FORM.equals(messageType)) {
            // copy the message type property that's used by the out message to the
            // response message
            response.setProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE, messageType);
        }
        if (axisOutMsgCtx.getMessageID() != null) {
            response.setRelationships(new RelatesTo[] { new RelatesTo(axisOutMsgCtx.getMessageID()) });
        }
        response.setReplyTo(axisOutMsgCtx.getReplyTo());
        response.setFaultTo(axisOutMsgCtx.getFaultTo());
        if (axisOutMsgCtx.isPropertyTrue(NhttpConstants.IGNORE_SC_ACCEPTED)) {
            response.setProperty(NhttpConstants.FORCE_SC_ACCEPTED, Constants.VALUE_TRUE);
        }
        // axis2 client options still contains properties such as policy files used in
        // outgoing request. Need to remove those.
        removeUnwantedClientOptions(response);
        // create the synapse message context for the response
        Axis2MessageContext synapseInMessageContext = new Axis2MessageContext(response, synapseOutMsgCtx.getConfiguration(), synapseOutMsgCtx.getEnvironment());
        synapseInMessageContext.setResponse(true);
        Object obj = synapseOutMsgCtx.getProperty(SynapseConstants.FORCE_ERROR_PROPERTY);
        String errorOnSOAPFault = (String) obj;
        if (Constants.VALUE_TRUE.equals(errorOnSOAPFault) && successfulEndpoint != null) {
            if (log.isDebugEnabled()) {
                log.debug("FORCE_ERROR_ON_SOAP_FAULT is true, checking for SOAPFault");
            }
            try {
                RelayUtils.buildMessage(((Axis2MessageContext) synapseInMessageContext).getAxis2MessageContext(), true);
            } catch (Exception e) {
            // handleException("Error while building message", e, synapseInMessageContext);
            }
            if ((synapseInMessageContext.getEnvelope() != null) && synapseInMessageContext.getEnvelope().hasFault()) {
                if (log.isDebugEnabled()) {
                    log.debug("SOAPFault found in response message, forcing endpoint " + successfulEndpoint.getName() + " to fail");
                }
                // setup new pipe configuration..if failure happens (this will be setup as the source writer and during the TargetContext
                // clean up operation the writer will be reset and pull to the buffer
                MessageContext axis2OUTMC = ((Axis2MessageContext) synapseOutMsgCtx).getAxis2MessageContext();
                NHttpServerConnection conn = (NHttpServerConnection) axis2OUTMC.getProperty("pass-through.Source-Connection");
                if (conn != null) {
                    SourceConfiguration sourceConfiguration = (SourceConfiguration) axis2OUTMC.getProperty("PASS_THROUGH_SOURCE_CONFIGURATION");
                    Pipe pipe = new Pipe(conn, sourceConfiguration.getBufferFactory().getBuffer(), "source", sourceConfiguration);
                    axis2OUTMC.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, pipe);
                }
                synapseOutMsgCtx.setProperty(SynapseConstants.SENDING_FAULT, Boolean.TRUE);
                synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_CODE, SynapseConstants.ENDPOINT_CUSTOM_ERROR);
                boolean failOver = false;
                if (successfulEndpoint instanceof AbstractEndpoint) {
                    Endpoint endpoint = ((AbstractEndpoint) successfulEndpoint).getParentEndpoint();
                    if (endpoint != null && (endpoint instanceof FailoverEndpoint)) {
                        failOver = true;
                    }
                }
                for (Object key : synapseOutMsgCtx.getPropertyKeySet()) {
                    synapseInMessageContext.setProperty((String) key, synapseOutMsgCtx.getProperty((String) key));
                }
                if (failOver) {
                    // we may required to handle same message for failover cases only other than that
                    // should treat based on the incoming message
                    ((FaultHandler) successfulEndpoint).handleFault(synapseOutMsgCtx, null);
                } else {
                    faultStack = synapseOutMsgCtx.getFaultStack();
                    if (faultStack != null) {
                        synapseInMessageContext.getFaultStack().addAll(faultStack);
                        ((FaultHandler) successfulEndpoint).handleFault(synapseInMessageContext, null);
                    }
                }
                return;
            } else {
                successfulEndpoint.onSuccess();
            }
        } else if (successfulEndpoint != null) {
            successfulEndpoint.onSuccess();
        }
        synapseInMessageContext.setTo(new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL));
        synapseInMessageContext.setTracingState(synapseOutMsgCtx.getTracingState());
        synapseInMessageContext.setMessageFlowTracingState(synapseOutMsgCtx.getMessageFlowTracingState());
        for (Object key : synapseOutMsgCtx.getPropertyKeySet()) {
            synapseInMessageContext.setProperty((String) key, synapseOutMsgCtx.getProperty((String) key));
        }
        // Copy SequenceCallStack from original MC to the new MC
        Boolean isContinuationCall = (Boolean) synapseOutMsgCtx.getProperty(SynapseConstants.CONTINUATION_CALL);
        if (isContinuationCall != null && isContinuationCall) {
            // Set the message direction
            if (!synapseOutMsgCtx.isResponse()) {
                synapseInMessageContext.setResponse(false);
            }
            Stack<ContinuationState> seqContinuationStates = synapseOutMsgCtx.getContinuationStateStack();
            for (int i = 0; i < seqContinuationStates.size(); i++) {
                synapseInMessageContext.pushContinuationState(seqContinuationStates.get(i));
            }
        }
        // If this response is related to session affinity endpoints -Server initiated session
        Dispatcher dispatcher = (Dispatcher) synapseOutMsgCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_DISPATCHER);
        if (dispatcher != null && dispatcher.isServerInitiatedSession()) {
            dispatcher.updateSession(synapseInMessageContext);
        }
        // send the response message through the synapse mediation flow
        try {
            synapseOutMsgCtx.getEnvironment().injectMessage(synapseInMessageContext);
        } catch (Exception syne) {
            // introduced to handle runtime exceptions which are occurred inside Synapse handlers
            // partially read stream could lead to corrupted attachment map and hence this exception
            // corrupted attachment map leads to inconsistent runtime exceptions and behavior
            // discard the attachment map for the fault handler invocation
            // ensure the successful completion for fault handler flow
            // even we drop attachment map for both cases messages which have attachment /
            // messages which do not have attachments it would still not be any impact.
            // However setting attachment map to null for messages which do not have attachments is not required.
            // introduced due to the fact conflicts between Axiom exceptions for attachment/ non attachments cases
            // and performance impact that could cause of regular expression matching of exceptional stack traces.
            Axis2MessageContext axis2smc = (Axis2MessageContext) synapseInMessageContext;
            org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
            // Set correct status code
            axis2MessageCtx.setProperty(PassThroughConstants.HTTP_SC, HttpStatus.SC_INTERNAL_SERVER_ERROR);
            axis2MessageCtx.setAttachmentMap(null);
            Stack stack = synapseInMessageContext.getFaultStack();
            if (stack != null && stack.isEmpty()) {
                registerFaultHandler(synapseInMessageContext);
            }
            if (stack != null && !stack.isEmpty()) {
                ((FaultHandler) stack.pop()).handleFault(synapseInMessageContext, syne);
            } else {
                log.error("Synapse encountered an exception, " + "No error handlers found - [Message Dropped]\n" + syne.getMessage());
            }
        }
    }
}
Also used : Dispatcher(org.apache.synapse.endpoints.dispatch.Dispatcher) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint) RelatesTo(org.apache.axis2.addressing.RelatesTo) NHttpServerConnection(org.apache.http.nio.NHttpServerConnection) Endpoint(org.apache.synapse.endpoints.Endpoint) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint) ConcurrentAccessController(org.apache.synapse.commons.throttle.core.ConcurrentAccessController) MessageContext(org.apache.axis2.context.MessageContext) FaultHandler(org.apache.synapse.FaultHandler) MediatorFaultHandler(org.apache.synapse.mediators.MediatorFaultHandler) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) Pipe(org.apache.synapse.transport.passthru.Pipe) Endpoint(org.apache.synapse.endpoints.Endpoint) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint) ConcurrentAccessReplicator(org.apache.synapse.commons.throttle.core.ConcurrentAccessReplicator) Stack(java.util.Stack) EndpointReference(org.apache.axis2.addressing.EndpointReference) ContinuationState(org.apache.synapse.ContinuationState) TenantInfoConfigurator(org.apache.synapse.carbonext.TenantInfoConfigurator) SourceConfiguration(org.apache.synapse.transport.passthru.config.SourceConfiguration)

Example 8 with Integer

use of org.apache.axis2.databinding.types.soapencoding.Integer in project carbon-business-process by wso2.

the class BPELDeployer method init.

public void init(ConfigurationContext configurationContext) {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    log.info("Initializing BPEL Deployer for tenant " + tenantId + ".");
    File bpelRepo = null;
    try {
        BPELDeployerServiceComponent.getTenantRegistryLoader().loadTenantRegistry(tenantId);
        bpelRepo = createBPELRepository(configurationContext);
    } catch (DeploymentException e) {
        log.warn("BPEL repository creation failed.", e);
    } catch (RegistryException e) {
        log.warn("Initialization of tenant process store failed for tenant: " + tenantId + " This can cause issues in deployment of BPEL packages.", e);
    }
    BPELServer bpsServer = BPELDeployerServiceComponent.getBPELServer();
    tenantProcessStore = bpsServer.getMultiTenantProcessStore().createProcessStoreForTenant(configurationContext);
    tenantProcessStore.setBpelArchiveRepo(bpelRepo);
    configurationContext.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, bpsServer.getHttpConnectionManager());
    try {
        tenantProcessStore.init();
    } catch (Exception re) {
        log.warn("Initialization of tenant process store failed for tenant: " + tenantId + " This can cause issues in deployment of BPEL packages.", re);
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) BPELServer(org.wso2.carbon.bpel.core.ode.integration.BPELServer) File(java.io.File) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 9 with Integer

use of org.apache.axis2.databinding.types.soapencoding.Integer in project carbon-business-process by wso2.

the class BPMNDeployer method deploy.

/**
 * Deploys a given bpmn package in acitiviti bpmn engine.
 * @param deploymentFileData Provide information about the deployment file
 * @throws DeploymentException On failure , deployment exception is thrown
 */
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
    // Worker nodes cannot deploy BPMN packages, hence return
    if (isWorkerNode()) {
        return;
    }
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    log.info("Deploying BPMN archive " + deploymentFileData.getFile().getName() + " for tenant: " + tenantId);
    try {
        BPMNDeploymentContext deploymentContext = new BPMNDeploymentContext(tenantId);
        deploymentContext.setBpmnArchive(deploymentFileData.getFile());
        tenantRepository.deploy(deploymentContext);
    // log.info( "Deployment Status " + deploymentFileData.getFile() + " deployed = " + deployed );
    } catch (DeploymentException e) {
        String errorMessage = "Failed to deploy the archive: " + deploymentFileData.getAbsolutePath();
        throw new DeploymentException(errorMessage, e);
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 10 with Integer

use of org.apache.axis2.databinding.types.soapencoding.Integer in project wso2-synapse by wso2.

the class PassThroughHttpSender method submitResponse.

public void submitResponse(MessageContext msgContext) throws IOException, HttpException {
    SourceConfiguration sourceConfiguration = (SourceConfiguration) msgContext.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONFIGURATION);
    NHttpServerConnection conn = (NHttpServerConnection) msgContext.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION);
    if (conn == null) {
        ServerWorker serverWorker = (ServerWorker) msgContext.getProperty(Constants.OUT_TRANSPORT_INFO);
        if (serverWorker != null) {
            MessageContext requestContext = serverWorker.getRequestContext();
            conn = (NHttpServerConnection) requestContext.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION);
            sourceConfiguration = (SourceConfiguration) requestContext.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONFIGURATION);
        } else {
            throw new IllegalStateException("Unable to correlate the response to a request");
        }
    }
    // Handle ETag caching
    if (msgContext.getProperty(PassThroughConstants.HTTP_ETAG_ENABLED) != null && (Boolean) msgContext.getProperty(PassThroughConstants.HTTP_ETAG_ENABLED)) {
        try {
            RelayUtils.buildMessage(msgContext);
        } catch (IOException e) {
            handleException("IO Error occurred while building the message", e);
        } catch (XMLStreamException e) {
            handleException("XML Error occurred while building the message", e);
        }
        String hash = digestGenerator.getDigest(msgContext);
        Map headers = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
        headers.put(HttpHeaders.ETAG, "\"" + hash + "\"");
    }
    if (msgContext.getProperty(Constants.Configuration.ENABLE_MTOM) != null && !Boolean.TRUE.equals(msgContext.getProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED))) {
        try {
            RelayUtils.buildMessage(msgContext);
        } catch (IOException e) {
            handleException("IO Error occurred while building the message", e);
        } catch (XMLStreamException e) {
            handleException("XML Error occurred while building the message", e);
        }
    }
    SourceRequest sourceRequest = SourceContext.getRequest(conn);
    if (sourceRequest == null) {
        // this is a special case we dropped source connection where message size exceeds the user defined threshold
        if (conn.getContext().getAttribute(PassThroughConstants.SOURCE_CONNECTION_DROPPED) != null && (Boolean) conn.getContext().getAttribute(PassThroughConstants.SOURCE_CONNECTION_DROPPED)) {
            // already submitted response for this case, hence return
            return;
        }
        log.warn("Trying to submit a response to an already closed connection : " + conn);
        return;
    }
    SourceResponse sourceResponse = SourceResponseFactory.create(msgContext, sourceRequest, sourceConfiguration);
    sourceResponse.checkResponseChunkDisable(msgContext);
    SourceContext.setResponse(conn, sourceResponse);
    Boolean noEntityBody = (Boolean) msgContext.getProperty(PassThroughConstants.NO_ENTITY_BODY);
    Pipe pipe = (Pipe) msgContext.getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
    if ((noEntityBody == null || !noEntityBody) || pipe != null) {
        if (pipe == null) {
            pipe = new Pipe(sourceConfiguration.getBufferFactory().getBuffer(), "Test", sourceConfiguration);
            msgContext.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, pipe);
            msgContext.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE);
        }
        pipe.attachConsumer(conn);
        sourceResponse.connect(pipe);
    }
    Integer errorCode = (Integer) msgContext.getProperty(PassThroughConstants.ERROR_CODE);
    if (errorCode != null) {
        sourceResponse.setStatus(HttpStatus.SC_BAD_GATEWAY);
        SourceContext.get(conn).setShutDown(true);
    }
    ProtocolState state = SourceContext.getState(conn);
    if (state != null && state.compareTo(ProtocolState.REQUEST_DONE) <= 0) {
        // start sending the response if we
        boolean noEntityBodyResponse = false;
        if (noEntityBody != null && Boolean.TRUE == noEntityBody && pipe != null) {
            OutputStream out = pipe.getOutputStream();
            out.write(new byte[0]);
            pipe.setRawSerializationComplete(true);
            out.close();
            noEntityBodyResponse = true;
        }
        if (!noEntityBodyResponse && msgContext.isPropertyTrue(PassThroughConstants.MESSAGE_BUILDER_INVOKED) && pipe != null) {
            OutputStream out = pipe.getOutputStream();
            // when there is no SOAPAction.
            if (Constants.VALUE_TRUE.equals(msgContext.getProperty(Constants.Configuration.ENABLE_MTOM)) || Constants.VALUE_TRUE.equals(msgContext.getProperty(Constants.Configuration.ENABLE_SWA))) {
                msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, PassThroughConstants.CONTENT_TYPE_MULTIPART_RELATED);
                msgContext.setProperty(Constants.Configuration.MESSAGE_TYPE, PassThroughConstants.CONTENT_TYPE_MULTIPART_RELATED);
            }
            MessageFormatter formatter = MessageFormatterDecoratorFactory.createMessageFormatterDecorator(msgContext);
            OMOutputFormat format = PassThroughTransportUtils.getOMOutputFormat(msgContext);
            Object contentTypeInMsgCtx = msgContext.getProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE);
            boolean isContentTypeSetFromMsgCtx = false;
            // If ContentType header is set in the axis2 message context, use it.
            if (contentTypeInMsgCtx != null) {
                String contentTypeValueInMsgCtx = contentTypeInMsgCtx.toString();
                // Skip multipart/related as it should be taken from formatter.
                if (!(contentTypeValueInMsgCtx.contains(PassThroughConstants.CONTENT_TYPE_MULTIPART_RELATED) || contentTypeValueInMsgCtx.contains(PassThroughConstants.CONTENT_TYPE_MULTIPART_FORM_DATA))) {
                    // adding charset only if charset is not available,
                    if (contentTypeValueInMsgCtx.indexOf(HTTPConstants.CHAR_SET_ENCODING) == -1 && format != null) {
                        String encoding = format.getCharSetEncoding();
                        if (encoding != null) {
                            sourceResponse.removeHeader(HTTP.CONTENT_TYPE);
                            contentTypeValueInMsgCtx += "; charset=" + encoding;
                        }
                    }
                    sourceResponse.addHeader(HTTP.CONTENT_TYPE, contentTypeValueInMsgCtx);
                    isContentTypeSetFromMsgCtx = true;
                }
            }
            // If ContentType is not set from msg context, get the formatter ContentType
            if (!isContentTypeSetFromMsgCtx) {
                sourceResponse.removeHeader(HTTP.CONTENT_TYPE);
                sourceResponse.addHeader(HTTP.CONTENT_TYPE, formatter.getContentType(msgContext, format, msgContext.getSoapAction()));
            }
            try {
                formatter.writeTo(msgContext, format, out, false);
            } catch (RemoteException fault) {
                IOUtils.closeQuietly(out);
                throw fault;
            } finally {
                // Serialization should be set as complete so that the state of the socket can be
                // reset to readable
                pipe.setSerializationComplete(true);
            }
            out.close();
        }
        conn.requestOutput();
    } else {
        // nothing much to do as we have started the response already
        if (errorCode != null) {
            if (log.isDebugEnabled()) {
                log.warn("A Source connection is closed because of an " + "error in target: " + conn);
            }
        } else {
            log.debug("A Source Connection is closed, because source handler " + "is already in the process of writing a response while " + "another response is submitted: " + conn);
        }
        pipe.consumerError();
        SourceContext.updateState(conn, ProtocolState.CLOSED);
        sourceConfiguration.getSourceConnections().shutDownConnection(conn, true);
    }
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) MessageFormatter(org.apache.axis2.transport.MessageFormatter) NHttpServerConnection(org.apache.http.nio.NHttpServerConnection) XMLStreamException(javax.xml.stream.XMLStreamException) SourceConfiguration(org.apache.synapse.transport.passthru.config.SourceConfiguration) MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) RemoteException(java.rmi.RemoteException) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)4 OMElement (org.apache.axiom.om.OMElement)4 MessageContext (org.apache.axis2.context.MessageContext)4 Parameter (org.apache.axis2.description.Parameter)4 QName (javax.xml.namespace.QName)3 DeploymentException (org.apache.axis2.deployment.DeploymentException)3 Pipe (org.apache.synapse.transport.passthru.Pipe)3 File (java.io.File)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)2 AxisFault (org.apache.axis2.AxisFault)2 TransportInDescription (org.apache.axis2.description.TransportInDescription)2 MessageFormatter (org.apache.axis2.transport.MessageFormatter)2 NHttpServerConnection (org.apache.http.nio.NHttpServerConnection)2 Message (quickfix.Message)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1