use of org.apache.synapse.inbound.InboundEndpoint 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);
}
}
}
use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.
the class InboundEndpointDeployer method updateSynapseArtifact.
@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
if (log.isDebugEnabled()) {
log.debug("Inbound Endpoint update from file : " + fileName + " has started");
}
try {
/*properties are ignored*/
InboundEndpoint inboundEndpoint = InboundEndpointFactory.createInboundEndpoint(artifactConfig, getSynapseConfiguration());
if (inboundEndpoint == null) {
handleSynapseArtifactDeploymentError("Inbound Endpoint update failed. The artifact " + "defined in the file: " + fileName + " is not a valid Inbound Endpoint.");
return null;
}
CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
inboundEndpoint.setFileName(new File(fileName).getName());
inboundEndpoint.setArtifactContainerName(customLogContent);
if (log.isDebugEnabled()) {
log.debug("Inbound Endpoint: " + inboundEndpoint.getName() + " has been built from the file: " + fileName);
}
InboundEndpoint existingInboundEndpoint = getSynapseConfiguration().getInboundEndpoint(existingArtifactName);
existingInboundEndpoint.destroy();
inboundEndpoint.init(getSynapseEnvironment());
if (existingArtifactName.equals(inboundEndpoint.getName())) {
getSynapseConfiguration().updateInboundEndpoint(existingArtifactName, inboundEndpoint);
} else {
// The user has changed the name of the Inbound Endpoint
// We should add the updated Inbound Endpoint as a new Inbound Endpoint and remove the old one
getSynapseConfiguration().addInboundEndpoint(inboundEndpoint.getName(), inboundEndpoint);
getSynapseConfiguration().removeInboundEndpoint(existingArtifactName);
log.info("Inbound Endpoint: " + existingArtifactName + " has been undeployed");
}
log.info("Inbound Endpoint: " + inboundEndpoint.getName() + " has been updated from the file: " + fileName);
waitForCompletion();
return inboundEndpoint.getName();
} catch (DeploymentException e) {
handleSynapseArtifactDeploymentError("Error while updating the Inbound Endpoint from the " + "file: " + fileName);
}
return null;
}
use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.
the class InboundEndpointDeployer method undeploySynapseArtifact.
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Undeployment of the Inbound Endpoint named : " + artifactName + " : Started");
}
try {
InboundEndpoint inboundEndpoint = getSynapseConfiguration().getInboundEndpoint(artifactName);
if (inboundEndpoint != null) {
CustomLogSetter.getInstance().setLogAppender(inboundEndpoint.getArtifactContainerName());
inboundEndpoint.destroy();
getSynapseConfiguration().removeInboundEndpoint(artifactName);
if (log.isDebugEnabled()) {
log.debug("Undeployment of the Inbound Endpoint named : " + artifactName + " : Completed");
}
log.info("Inbound Endpoint named '" + inboundEndpoint.getName() + "' has been undeployed");
} else if (log.isDebugEnabled()) {
log.debug("Inbound Endpoint " + artifactName + " has already been undeployed");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Undeployment of Inbound Endpoint named : " + artifactName + " : Failed", e);
}
}
use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.
the class InboundEndpointDebugUtil method registerInboundSequenceMediationFlowSkip.
/**
* Registers/Un-registers a skip, point where mediator disables from mediation flow
*
* @param synCfg Synapse configuration
* @param seqType Synapse sequence type
* @param inboundKey name of the Inbound Endpoint
* @param position array of integers that uniquely specifies a point in mediation route
* @param registerMode specify whether register or un register
*/
public static void registerInboundSequenceMediationFlowSkip(SynapseConfiguration synCfg, String seqType, String inboundKey, int[] position, boolean registerMode) {
SynapseSequenceType synapseSequenceType = SynapseSequenceType.valueOf(seqType.toUpperCase());
SequenceMediationFlowPoint skipPoint = new SequenceMediationFlowPoint();
skipPoint.setSynapseMediationComponent(SynapseMediationComponent.SEQUENCE);
skipPoint.setKey(inboundKey);
skipPoint.setMediatorPosition(position);
skipPoint.setSequenceBaseType(SynapseDebugCommandConstants.DEBUG_COMMAND_MEDIATION_COMPONENT_SEQUENCE_INBOUND);
skipPoint.setSynapseSequenceType(synapseSequenceType);
Mediator seqMediator = null;
InboundEndpoint inbound = null;
inbound = synCfg.getInboundEndpoint(inboundKey);
if (inbound != null) {
if (synapseSequenceType.equals(SynapseSequenceType.INBOUND_SEQ)) {
seqMediator = synCfg.getSequence(inbound.getInjectingSeq());
} else if (synapseSequenceType.equals(SynapseSequenceType.INBOUND_FAULTSEQ)) {
seqMediator = synCfg.getSequence(inbound.getOnErrorSeq());
}
} else {
if (log.isDebugEnabled()) {
log.debug("Non existing Inbound Endpoint for key " + skipPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_INBOUND_NOT_FOUND).toString());
return;
}
if (seqMediator != null) {
Mediator current_mediator = null;
current_mediator = MediatorTreeTraverseUtil.getMediatorReference(synCfg, seqMediator, position);
if (current_mediator != null) {
skipPoint.setMediatorReference(current_mediator);
if (registerMode) {
if (!((AbstractMediator) current_mediator).isSkipEnabled()) {
((AbstractMediator) current_mediator).setSkipEnabled(true);
((AbstractMediator) current_mediator).registerMediationFlowPoint(skipPoint);
if (log.isDebugEnabled()) {
log.debug("Registered skip at mediator position " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Already skip enabled at mediator position " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_ENABLED).toString());
}
} else {
if (((AbstractMediator) current_mediator).isSkipEnabled()) {
((AbstractMediator) current_mediator).unregisterMediationFlowPoint();
((AbstractMediator) current_mediator).setSkipEnabled(false);
if (log.isDebugEnabled()) {
log.debug("Unregistered skip at mediator position " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(true, null).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Already skip disabled at mediator position " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_ALREADY_SKIP_DISABLED).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Non existing mediator position at " + logMediatorPosition(skipPoint) + " for Inbound Endpoint key " + skipPoint.getKey() + " sequence " + skipPoint.getSynapseSequenceType().toString());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_MEDIATOR_POSITION).toString());
}
}
} else {
if (registerMode) {
if (log.isDebugEnabled()) {
log.debug("Failed register skip. Non existing sequence " + skipPoint.getSynapseSequenceType().toString() + " for Inbound Endpoint key " + skipPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
} else {
if (log.isDebugEnabled()) {
log.debug("Failed unregister skip. Non existing sequence " + skipPoint.getSynapseSequenceType().toString() + " for Inbound Endpoint key " + skipPoint.getKey());
}
debugManager.advertiseCommandResponse(debugManager.createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_NON_EXISTING_SEQUENCE).toString());
}
}
}
use of org.apache.synapse.inbound.InboundEndpoint in project wso2-synapse by wso2.
the class SynapseConfiguration method init.
/**
* This method will be called in the startup of Synapse or in an initiation
* and will initialize all the managed parts of the Synapse Configuration
*
* @param se SynapseEnvironment specifying the env to be initialized
*/
public synchronized void init(SynapseEnvironment se) {
SynapseConfiguration previouseConfiguration = null;
if (log.isDebugEnabled()) {
log.debug("Initializing the Synapse Configuration using the SynapseEnvironment");
}
// initialize registry
if (registry != null && registry instanceof ManagedLifecycle) {
((ManagedLifecycle) registry).init(se);
}
// we initialize xpath extensions here since synapse environment is available
initXpathExtensions(se);
initCarbonTenantConfigurator(se);
// initialize endpoints
for (Endpoint endpoint : getDefinedEndpoints().values()) {
try {
endpoint.init(se);
} catch (Exception e) {
log.error(" Error in initializing endpoint [" + endpoint.getName() + "] " + e.getMessage());
}
}
// initialize sequence templates
for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
try {
seqTemplate.init(se);
} catch (Exception e) {
log.error(" Error in initializing Sequence Template [" + seqTemplate.getName() + "] " + e.getMessage());
}
}
String tenantDomain = getTenantDomain(se);
if (tenantDomain != null) {
previouseConfiguration = SynapseConfigUtils.getSynapseConfiguration(tenantDomain);
SynapseConfigUtils.addSynapseConfiguration(tenantDomain, this);
}
if (previouseConfiguration != null) {
destroyExistingInbounds(previouseConfiguration);
}
for (InboundEndpoint endpoint : getInboundEndpoints()) {
try {
endpoint.init(se);
} catch (Exception e) {
inboundEndpointMap.remove(endpoint.getName());
log.error(" Error in initializing inbound endpoint [" + endpoint.getName() + "] " + e.getMessage());
}
}
// initialize managed mediators
for (ManagedLifecycle seq : getDefinedSequences().values()) {
if (seq != null) {
try {
seq.init(se);
} catch (Exception e) {
log.error(" Error in initializing Sequence " + e.getMessage());
}
}
}
// initialize all the proxy services
for (ProxyService proxy : getProxyServices()) {
try {
if (proxy.getTargetInLineEndpoint() != null) {
proxy.getTargetInLineEndpoint().init(se);
}
if (proxy.getTargetInLineInSequence() != null) {
proxy.getTargetInLineInSequence().init(se);
}
if (proxy.getTargetInLineOutSequence() != null) {
proxy.getTargetInLineOutSequence().init(se);
}
if (proxy.getTargetInLineFaultSequence() != null) {
proxy.getTargetInLineFaultSequence().init(se);
}
} catch (Exception e) {
log.error(" Error in initializing Proxy Service [ " + proxy.getName() + "] " + e.getMessage());
}
}
// initialize the startups
for (ManagedLifecycle stp : getStartups()) {
if (stp != null) {
try {
stp.init(se);
} catch (Exception e) {
log.error(" Error in initializing Stratups " + e.getMessage());
}
}
}
// initialize sequence executors
for (PriorityExecutor executor : getPriorityExecutors().values()) {
try {
executor.init();
} catch (Exception e) {
log.error(" Error in initializing Executor [ " + executor.getName() + "] " + e.getMessage());
}
}
// initialize message stores
for (MessageStore messageStore : messageStores.values()) {
try {
messageStore.init(se);
} catch (Exception e) {
log.error(" Error in initializing Message Store [ " + messageStore.getName() + "] " + e.getMessage());
}
}
// initialize message processors
for (MessageProcessor messageProcessor : messageProcessors.values()) {
try {
messageProcessor.init(se);
} catch (Exception e) {
log.error(" Error in initializing Message Processor [ " + messageProcessor.getName() + "] " + e.getMessage());
}
}
for (API api : apiTable.values()) {
try {
api.init(se);
} catch (Exception e) {
log.error(" Error in initializing API [ " + api.getName() + "] " + e.getMessage());
}
}
initImportedLibraries(se);
}
Aggregations