use of org.apache.synapse.aspects.AspectConfiguration in project wso2-synapse by wso2.
the class DefaultEndpointFactory method processAuditStatus.
protected void processAuditStatus(EndpointDefinition definition, String name, OMElement epOmElement) {
if (name == null || "".equals(name)) {
name = SynapseConstants.ANONYMOUS_ENDPOINT;
}
AspectConfiguration aspectConfiguration = new AspectConfiguration(name);
definition.configure(aspectConfiguration);
OMAttribute statistics = epOmElement.getAttribute(new QName(XMLConfigConstants.STATISTICS_ATTRIB_NAME));
if (statistics != null) {
String statisticsValue = statistics.getAttributeValue();
if (statisticsValue != null) {
if (XMLConfigConstants.STATISTICS_ENABLE.equals(statisticsValue)) {
aspectConfiguration.enableStatistics();
}
}
}
OMAttribute tracing = epOmElement.getAttribute(new QName(XMLConfigConstants.TRACE_ATTRIB_NAME));
if (tracing != null) {
String tracingValue = tracing.getAttributeValue();
if (tracingValue != null) {
if (XMLConfigConstants.TRACE_ENABLE.equals(tracingValue)) {
aspectConfiguration.enableTracing();
}
}
}
}
use of org.apache.synapse.aspects.AspectConfiguration 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.aspects.AspectConfiguration in project wso2-synapse by wso2.
the class APIFactory method createAPI.
public static API createAPI(OMElement apiElt, Properties properties) {
OMAttribute nameAtt = apiElt.getAttribute(new QName("name"));
if (nameAtt == null || "".equals(nameAtt.getAttributeValue())) {
handleException("Attribute 'name' is required for an API definition");
}
OMAttribute contextAtt = apiElt.getAttribute(new QName("context"));
if (contextAtt == null || "".equals(contextAtt.getAttributeValue())) {
handleException("Attribute 'context' is required for an API definition");
}
API api = new API(nameAtt.getAttributeValue(), contextAtt.getAttributeValue());
OMAttribute hostAtt = apiElt.getAttribute(new QName("hostname"));
if (hostAtt != null && !"".equals(hostAtt.getAttributeValue())) {
api.setHost(hostAtt.getAttributeValue());
}
VersionStrategy vStrategy = VersionStrategyFactory.createVersioningStrategy(api, apiElt);
api.setVersionStrategy(vStrategy);
OMAttribute portAtt = apiElt.getAttribute(new QName("port"));
if (portAtt != null && !"".equals(portAtt.getAttributeValue())) {
api.setPort(Integer.parseInt(portAtt.getAttributeValue()));
}
Iterator resources = apiElt.getChildrenWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "resource"));
boolean noResources = true;
while (resources.hasNext()) {
OMElement resourceElt = (OMElement) resources.next();
api.addResource(ResourceFactory.createResource(resourceElt, properties));
noResources = false;
}
if (noResources) {
handleException("An API must contain at least one resource definition");
}
OMElement handlersElt = apiElt.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "handlers"));
if (handlersElt != null) {
Iterator handlers = handlersElt.getChildrenWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "handler"));
while (handlers.hasNext()) {
OMElement handlerElt = (OMElement) handlers.next();
defineHandler(api, handlerElt);
}
}
OMAttribute trans = apiElt.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "transports"));
if (trans != null) {
String transports = trans.getAttributeValue();
if (!"".equals(transports)) {
if (Constants.TRANSPORT_HTTP.equals(transports)) {
api.setProtocol(RESTConstants.PROTOCOL_HTTP_ONLY);
} else if (Constants.TRANSPORT_HTTPS.equals(transports)) {
api.setProtocol(RESTConstants.PROTOCOL_HTTPS_ONLY);
} else {
handleException("Invalid protocol name: " + transports);
}
}
}
String nameString = api.getName();
if (nameString == null || "".equals(nameString)) {
nameString = SynapseConstants.ANONYMOUS_API;
}
AspectConfiguration aspectConfiguration = new AspectConfiguration(nameString);
api.configure(aspectConfiguration);
OMAttribute statistics = apiElt.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 = apiElt.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();
}
}
}
return api;
}
use of org.apache.synapse.aspects.AspectConfiguration 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();
}
}
}
use of org.apache.synapse.aspects.AspectConfiguration in project wso2-synapse by wso2.
the class Axis2SynapseEnvironment method injectMessage.
public boolean injectMessage(MessageContext smc, SequenceMediator seq) {
AspectConfiguration inboundAspectConfiguration = null;
String inboundName = null;
boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
Integer statisticReportingIndex = null;
/*
* If the method is invoked by the inbound endpoint
* Then check for the endpoint name and then set the Log Appender Content
*/
if (smc.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME) != null) {
InboundEndpoint inboundEndpoint = smc.getConfiguration().getInboundEndpoint((String) smc.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME));
if (inboundEndpoint != null) {
CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
inboundName = (String) smc.getProperty(SynapseConstants.INBOUND_ENDPOINT_NAME);
if (inboundEndpoint.getAspectConfiguration() != null) {
inboundAspectConfiguration = inboundEndpoint.getAspectConfiguration();
}
}
}
if (seq == null) {
log.error("Please provide existing sequence");
return false;
}
if (log.isDebugEnabled()) {
log.debug("Injecting MessageContext for asynchronous mediation using the : " + (seq.getName() == null ? "Anonymous" : seq.getName()) + " Sequence");
}
smc.setEnvironment(this);
if (!invokeHandlers(smc)) {
return false;
}
try {
if (isStatisticsEnabled && inboundName != null) {
statisticReportingIndex = OpenEventCollector.reportEntryEvent(smc, inboundName, inboundAspectConfiguration, ComponentType.INBOUNDENDPOINT);
}
seq.mediate(smc);
return true;
} catch (SynapseException syne) {
if (!smc.getFaultStack().isEmpty()) {
warn(false, "Executing fault handler due to exception encountered", smc);
smc.getFaultStack().pop().handleFault(smc, syne);
} else {
warn(false, "Exception encountered but no fault handler found - " + "message dropped", smc);
}
return false;
} catch (Exception e) {
String msg = "Unexpected error executing injecting message to sequence ," + seq;
log.error(msg, e);
if (smc.getServiceLog() != null) {
smc.getServiceLog().error(msg, e);
}
if (!smc.getFaultStack().isEmpty()) {
warn(false, "Executing fault handler due to exception encountered", smc);
smc.getFaultStack().pop().handleFault(smc, e);
} else {
warn(false, "Exception encountered but no fault handler found - " + "message dropped", smc);
}
return false;
} catch (Throwable e) {
String msg = "Unexpected error executing injecting message to sequence ," + seq + " message dropped";
log.error(msg, e);
if (smc.getServiceLog() != null) {
smc.getServiceLog().error(msg, e);
}
return false;
} finally {
if (isStatisticsEnabled && inboundName != null) {
CloseEventCollector.tryEndFlow(smc, inboundName, ComponentType.INBOUNDENDPOINT, statisticReportingIndex, false);
}
}
}
Aggregations