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;
}
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;
}
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());
}
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\""));
}
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();
}
}
}
Aggregations