Search in sources :

Example 11 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class InboundEndpointFactory method createInboundEndpoint.

public static InboundEndpoint createInboundEndpoint(OMElement inboundEndpointElem, SynapseConfiguration config) {
    InboundEndpoint inboundEndpoint = new InboundEndpoint();
    if (inboundEndpointElem.getAttributeValue(ATT_NAME) != null) {
        inboundEndpoint.setName(inboundEndpointElem.getAttributeValue(ATT_NAME));
    } else {
        String msg = "Inbound Endpoint name cannot be null";
        log.error(msg);
        throw new SynapseException(msg);
    }
    if (inboundEndpointElem.getAttributeValue(ATT_PROTOCOL) != null) {
        inboundEndpoint.setProtocol(inboundEndpointElem.getAttributeValue(ATT_PROTOCOL));
    }
    if (inboundEndpointElem.getAttributeValue(ATT_ENDPOINT_CLASS) != null) {
        inboundEndpoint.setClassImpl(inboundEndpointElem.getAttributeValue(ATT_ENDPOINT_CLASS));
    }
    if (inboundEndpointElem.getAttributeValue(ATT_ENDPOINT_SUSPEND) != null) {
        inboundEndpoint.setSuspend(Boolean.parseBoolean(inboundEndpointElem.getAttributeValue(ATT_ENDPOINT_SUSPEND)));
    } else {
        inboundEndpoint.setSuspend(false);
    }
    if (inboundEndpointElem.getAttributeValue(ATT_SEQUENCE) != null) {
        inboundEndpoint.setInjectingSeq(inboundEndpointElem.getAttributeValue(ATT_SEQUENCE));
    }
    if (inboundEndpointElem.getAttributeValue(ATT_ERROR_SEQUENCE) != null) {
        inboundEndpoint.setOnErrorSeq(inboundEndpointElem.getAttributeValue(ATT_ERROR_SEQUENCE));
    }
    String nameString = inboundEndpoint.getName();
    if (nameString == null || "".equals(nameString)) {
        nameString = SynapseConstants.INBOUND_ENDPOINT_NAME;
    }
    AspectConfiguration aspectConfiguration = new AspectConfiguration(nameString);
    inboundEndpoint.configure(aspectConfiguration);
    OMAttribute statistics = inboundEndpointElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.STATISTICS_ATTRIB_NAME));
    if (statistics != null) {
        String statisticsValue = statistics.getAttributeValue();
        if (statisticsValue != null) {
            if (XMLConfigConstants.STATISTICS_ENABLE.equals(statisticsValue)) {
                aspectConfiguration.enableStatistics();
            }
        }
    }
    OMAttribute tracing = inboundEndpointElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.TRACE_ATTRIB_NAME));
    if (tracing != null) {
        String tracingValue = tracing.getAttributeValue();
        if (tracingValue != null) {
            if (XMLConfigConstants.TRACE_ENABLE.equals(tracingValue)) {
                aspectConfiguration.enableTracing();
            }
        }
    }
    // Set parameters
    OMElement parametersElt = inboundEndpointElem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETERS));
    if (parametersElt != null) {
        Iterator parameters = parametersElt.getChildrenWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER));
        while (parameters.hasNext()) {
            OMElement parameter = (OMElement) parameters.next();
            String paramName = parameter.getAttributeValue(new QName(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER_NAME));
            String paramKey = parameter.getAttributeValue(new QName(InboundEndpointConstants.INBOUND_ENDPOINT_PARAMETER_KEY));
            if (paramKey != null) {
                Object obj = config.getEntry(paramKey);
                if (obj == null) {
                    obj = config.getEntryDefinition(paramKey);
                    obj = config.getEntry(paramKey);
                }
                if (obj != null && obj instanceof OMTextImpl) {
                    OMText objText = (OMText) obj;
                    inboundEndpoint.addParameter(paramName, objText.getText(), paramKey);
                } else {
                    String msg = "Error while deploying inbound endpoint " + inboundEndpoint.getName() + ".Registry entry defined with key: " + paramKey + " not found.";
                    log.error(msg);
                    throw new SynapseException(msg);
                }
            } else if (parameter.getFirstElement() != null) {
                inboundEndpoint.addParameter(paramName, parameter.getFirstElement().toString());
            } else {
                inboundEndpoint.addParameter(paramName, parameter.getText());
            }
        }
    }
    inboundEndpoint.setFileName(inboundEndpointElem.getAttributeValue(new QName(InboundEndpointConstants.INBOUND_ENDPOINT_NAME)) + ".xml");
    return inboundEndpoint;
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText) OMTextImpl(org.apache.axiom.om.impl.llom.OMTextImpl) OMElement(org.apache.axiom.om.OMElement) AspectConfiguration(org.apache.synapse.aspects.AspectConfiguration) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 12 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class SynapseXMLConfigurationFactory method defineInboundEndpoint.

public static InboundEndpoint defineInboundEndpoint(SynapseConfiguration config, OMElement elem, Properties properties) {
    InboundEndpoint inboundEndpoint = null;
    try {
        inboundEndpoint = InboundEndpointFactory.createInboundEndpoint(elem, config);
        config.addInboundEndpoint(inboundEndpoint.getName(), inboundEndpoint);
    } catch (Exception e) {
        String msg = "Inbound Endpoint configuration cannot be built";
        handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_INBOUND_ENDPOINT, msg, e);
    }
    return inboundEndpoint;
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) SynapseException(org.apache.synapse.SynapseException)

Example 13 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class StatisticSynapseConfigurationObserverTest method testInboundEndpointAdded.

/**
 * Test InboundEndpointAdded by hash generation.
 */
@Test
public void testInboundEndpointAdded() {
    InboundEndpoint inboundEndpoint = new InboundEndpoint();
    observer.inboundEndpointAdded(inboundEndpoint);
    Assert.assertNotNull("New hash must be set by the method", inboundEndpoint.getAspectConfiguration().getHashCode());
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) Test(org.junit.Test)

Example 14 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration10.

/**
 * Test serializeConfigurationMethod with InboundEndpoint added for SynapseConfiguration
 * and assert OMElement returned
 */
@Test
public void testSerializeConfiguration10() {
    SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    InboundEndpoint inboundEndpoint = new InboundEndpoint();
    inboundEndpoint.setName("test_inbound_1");
    inboundEndpoint.setProtocol("http");
    synapseConfiguration.addInboundEndpoint(inboundEndpoint.getName(), inboundEndpoint);
    OMElement element = serializer.serializeConfiguration(synapseConfiguration);
    Assert.assertNotNull("OMElement is not returned", element);
    Assert.assertEquals("definitions", element.getLocalName());
    Assert.assertTrue("InboundEndpoint added is not serialized.", element.getChildren().next().toString().contains("name=\"test_inbound_1\""));
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 15 with InboundEndpoint

use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.

the class Axis2SynapseEnvironment method injectInbound.

/**
 * Used by inbound polling endpoints to inject the message to synapse engine
 *
 * @param synCtx message context
 * @param sequential whether message should be injected in sequential manner
 *                   without spawning new threads
 * @return Boolean - Indicate if were able to inject the message
 * @throws SynapseException
 *             - in case error occured during the mediation
 */
public boolean injectInbound(final MessageContext synCtx, SequenceMediator seq, boolean sequential) throws SynapseException {
    String inboundName = null;
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    AspectConfiguration inboundAspectConfiguration = null;
    Integer statisticReportingIndex = null;
    if (log.isDebugEnabled()) {
        log.debug("Injecting MessageContext for inbound mediation using the : " + (seq.getName() == null ? "Anonymous" : seq.getName()) + " Sequence");
    }
    /*
         * If the method is invoked by the inbound endpoint
         * Then check for the endpoint name and then set the Log Appender Content
         */
    if (synCtx.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME) != null) {
        InboundEndpoint inboundEndpoint = synCtx.getConfiguration().getInboundEndpoint((String) synCtx.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME));
        if (inboundEndpoint != null) {
            CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
            if (inboundEndpoint.getAspectConfiguration() != null) {
                // inboundStatistics = inboundEndpoint.getAspectConfiguration().isStatisticsEnable();
                inboundAspectConfiguration = inboundEndpoint.getAspectConfiguration();
            }
            inboundName = (String) synCtx.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME);
        }
    }
    synCtx.setEnvironment(this);
    if (!invokeHandlers(synCtx)) {
        return false;
    }
    if (!sequential) {
        try {
            if (isStatisticsEnabled) {
                statisticReportingIndex = OpenEventCollector.reportEntryEvent(synCtx, inboundName, inboundAspectConfiguration, ComponentType.INBOUNDENDPOINT);
            }
            executorServiceInbound.execute(new MediatorWorker(seq, synCtx));
            return true;
        } catch (RejectedExecutionException re) {
            // If the pool is full complete the execution with the same thread
            log.warn("Inbound worker pool has reached the maximum capacity and will be processing current message sequentially.");
        } finally {
            if (isStatisticsEnabled) {
                CloseEventCollector.tryEndFlow(synCtx, inboundName, ComponentType.INBOUNDENDPOINT, statisticReportingIndex, false);
            }
        }
    }
    // reached max level
    if (isStatisticsEnabled) {
        statisticReportingIndex = OpenEventCollector.reportEntryEvent(synCtx, inboundName, inboundAspectConfiguration, ComponentType.INBOUNDENDPOINT);
    }
    try {
        if (synCtx.getEnvironment().isDebuggerEnabled()) {
            SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
            debugManager.acquireMediationFlowLock();
            debugManager.advertiseMediationFlowStartPoint(synCtx);
        }
        seq.mediate(synCtx);
        return true;
    } catch (SynapseException syne) {
        if (!synCtx.getFaultStack().isEmpty()) {
            log.warn("Executing fault handler due to exception encountered");
            ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
            return true;
        } else {
            log.warn("Exception encountered but no fault handler found - message dropped");
            throw syne;
        }
    } catch (Exception e) {
        String msg = "Unexpected error executing task/async inject";
        log.error(msg, e);
        if (synCtx.getServiceLog() != null) {
            synCtx.getServiceLog().error(msg, e);
        }
        if (!synCtx.getFaultStack().isEmpty()) {
            log.warn("Executing fault handler due to exception encountered");
            ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, e);
            return true;
        } else {
            log.warn("Exception encountered but no fault handler found - message dropped");
            throw new SynapseException("Exception encountered but no fault handler found - message dropped", e);
        }
    } catch (Throwable e) {
        String msg = "Unexpected error executing inbound/async inject, message dropped";
        log.error(msg, e);
        if (synCtx.getServiceLog() != null) {
            synCtx.getServiceLog().error(msg, e);
        }
        throw new SynapseException(msg, e);
    } finally {
        if (isStatisticsEnabled) {
            CloseEventCollector.tryEndFlow(synCtx, inboundName, ComponentType.INBOUNDENDPOINT, statisticReportingIndex, false);
        }
        if (synCtx.getEnvironment().isDebuggerEnabled()) {
            SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
            debugManager.advertiseMediationFlowTerminatePoint(synCtx);
            debugManager.releaseMediationFlowLock();
        }
    }
}
Also used : InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) SynapseException(org.apache.synapse.SynapseException) AspectConfiguration(org.apache.synapse.aspects.AspectConfiguration) SynapseDebugManager(org.apache.synapse.debug.SynapseDebugManager) MediatorWorker(org.apache.synapse.mediators.MediatorWorker) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SynapseException(org.apache.synapse.SynapseException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)21 SynapseException (org.apache.synapse.SynapseException)6 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)6 OMElement (org.apache.axiom.om.OMElement)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)4 TestMediator (org.apache.synapse.mediators.TestMediator)4 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)4 AspectConfiguration (org.apache.synapse.aspects.AspectConfiguration)3 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)3 Endpoint (org.apache.synapse.endpoints.Endpoint)3 MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 API (org.apache.synapse.rest.API)3 File (java.io.File)2 Iterator (java.util.Iterator)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Mediator (org.apache.synapse.Mediator)2 Entry (org.apache.synapse.config.Entry)2