use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class EndpointDeployer method restoreSynapseArtifact.
@Override
public void restoreSynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Restoring the Endpoint with name : " + artifactName + " : Started");
}
try {
Endpoint ep = getSynapseConfiguration().getDefinedEndpoints().get(artifactName);
CustomLogSetter.getInstance().setLogAppender((ep != null) ? ep.getArtifactContainerName() : "");
OMElement epElem = EndpointSerializer.getElementFromEndpoint(ep);
if (ep.getFileName() != null) {
String fileName = getServerConfigurationInformation().getSynapseXMLLocation() + File.separator + MultiXMLConfigurationBuilder.ENDPOINTS_DIR + File.separator + ep.getFileName();
writeToFile(epElem, fileName);
if (log.isDebugEnabled()) {
log.debug("Restoring the Endpoint with name : " + artifactName + " : Completed");
}
log.info("Endpoint named '" + artifactName + "' has been restored");
} else {
handleSynapseArtifactDeploymentError("Couldn't restore the endpoint named '" + artifactName + "', filename cannot be found");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Restoring of the endpoint named '" + artifactName + "' has failed", e);
}
}
use of org.apache.synapse.endpoints.Endpoint 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);
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class SynapseConfiguration method destroy.
public synchronized void destroy(boolean preserverState) {
if (log.isDebugEnabled()) {
log.debug("Destroying the Synapse Configuration");
}
// clear the timer tasks of Synapse
synapseTimer.cancel();
synapseTimer = null;
// stop and shutdown all the proxy services
for (ProxyService p : getProxyServices()) {
if (p.getTargetInLineInSequence() != null) {
p.getTargetInLineInSequence().destroy();
}
if (p.getTargetInLineOutSequence() != null) {
p.getTargetInLineOutSequence().destroy();
}
}
// destroy the managed mediators
for (ManagedLifecycle seq : getDefinedSequences().values()) {
seq.destroy();
}
// destroy sequence templates
for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
seqTemplate.destroy();
}
// destroy inbound endpoint
for (InboundEndpoint endpoint : getInboundEndpoints()) {
// This path trigger from server shutdown hook. So we don't want to remove scheduled inbound tasks
// from registry. Only un-deployment should remove task from registry. Ref product-ei#1206
endpoint.destroy(false);
}
// destroy the managed endpoints
for (Endpoint endpoint : getDefinedEndpoints().values()) {
endpoint.destroy();
}
// destroy the startups
for (ManagedLifecycle stp : startups.values()) {
stp.destroy();
}
// clear session information used for SA load balancing
try {
SALSessions.getInstance().reset();
DataSourceRepositoryHolder.getInstance().getDataSourceRepositoryManager().clear();
} catch (Throwable ignored) {
}
// destroy the priority executors.
for (PriorityExecutor pe : executors.values()) {
pe.destroy();
}
// destroy the Message Stores
for (MessageStore ms : messageStores.values()) {
if (ms instanceof AbstractMessageProcessor) {
((AbstractMessageProcessor) ms).destroy(preserverState);
} else {
ms.destroy();
}
}
// destroy the Message processors
for (MessageProcessor mp : messageProcessors.values()) {
mp.destroy();
}
for (API api : apiTable.values()) {
api.destroy();
}
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class Target method mediate.
/**
* process the message through this target (may be to mediate
* using the target sequence, send message to the target endpoint or both)
*
* @param synCtx - MessageContext to be mediated
* @return <code>false</code> if the target is mediated as synchronous and the sequence
* mediation returns <code>false</code>, <code>true</code> otherwise
*/
public boolean mediate(MessageContext synCtx) {
boolean returnValue = true;
if (log.isDebugEnabled()) {
log.debug("Target mediation : START");
}
if (soapAction != null) {
if (log.isDebugEnabled()) {
log.debug("Setting the SOAPAction as : " + soapAction);
}
synCtx.setSoapAction(soapAction);
}
if (toAddress != null) {
if (log.isDebugEnabled()) {
log.debug("Setting the To header as : " + toAddress);
}
if (synCtx.getTo() != null) {
synCtx.getTo().setAddress(toAddress);
} else {
synCtx.setTo(new EndpointReference(toAddress));
}
}
// through a sequence and then again with an endpoint
if (sequence != null) {
if (asynchronous) {
if (log.isDebugEnabled()) {
log.debug("Asynchronously mediating using the in-lined anonymous sequence");
}
synCtx.getEnvironment().injectAsync(synCtx, sequence);
} else {
if (log.isDebugEnabled()) {
log.debug("Synchronously mediating using the in-lined anonymous sequence");
}
returnValue = sequence.mediate(synCtx);
}
} else if (sequenceRef != null) {
SequenceMediator refSequence = (SequenceMediator) synCtx.getSequence(sequenceRef);
// if target directs the message to a defined sequence, ReliantContState added by
// Clone/Iterate mediator is no longer needed as defined sequence can be directly
// referred from a SeqContinuationState
ContinuationStackManager.removeReliantContinuationState(synCtx);
if (refSequence != null) {
if (asynchronous) {
if (log.isDebugEnabled()) {
log.debug("Asynchronously mediating using the sequence " + "named : " + sequenceRef);
}
synCtx.getEnvironment().injectAsync(synCtx, refSequence);
} else {
if (log.isDebugEnabled()) {
log.debug("Synchronously mediating using the sequence " + "named : " + sequenceRef);
}
try {
returnValue = refSequence.mediate(synCtx);
} catch (SynapseException syne) {
if (!synCtx.getFaultStack().isEmpty()) {
log.warn("Executing fault handler due to exception encountered");
((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
} else {
log.warn("Exception encountered but no fault handler found - message dropped");
}
} catch (Exception e) {
String msg = "Unexpected error occurred executing the Target";
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);
} else {
log.warn("Exception encountered but no fault handler found - message dropped");
}
}
}
} else {
handleException("Couldn't find the sequence named : " + sequenceRef);
}
} else if (endpoint != null) {
if (log.isDebugEnabled()) {
log.debug("Sending using the in-lined anonymous endpoint");
}
ContinuationStackManager.removeReliantContinuationState(synCtx);
endpoint.send(synCtx);
} else if (endpointRef != null) {
ContinuationStackManager.removeReliantContinuationState(synCtx);
Endpoint epr = synCtx.getConfiguration().getEndpoint(endpointRef);
if (epr != null) {
if (log.isDebugEnabled()) {
log.debug("Sending using the endpoint named : " + endpointRef);
}
if (!epr.isInitialized()) {
// initializing registry
epr.init(synCtx.getEnvironment());
// base endpoint configuration
}
epr.send(synCtx);
// epr.destroy();
} else {
handleException("Couldn't find the endpoint named : " + endpointRef);
}
}
if (log.isDebugEnabled()) {
log.debug("Target mediation : END");
}
return returnValue;
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class SALSessions method updateSession.
/**
* Update or establish a session
*
* @param synCtx Synapse MessageContext
* @param sessionID session id
*/
public void updateSession(MessageContext synCtx, String sessionID) {
if (sessionID == null || "".equals(sessionID)) {
if (log.isDebugEnabled()) {
log.debug("Cannot find session ID .Returing null");
}
return;
}
boolean createSession = false;
// if this is related to the already established session
SessionInformation oldSession = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
List<Endpoint> endpoints = null;
Member currentMember = null;
if (oldSession == null) {
if (log.isDebugEnabled()) {
log.debug("Going to create a New session with id " + sessionID);
}
endpoints = (List<Endpoint>) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST);
currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
createSession = true;
} else {
String oldSessionID = oldSession.getId();
if (!sessionID.equals(oldSessionID)) {
if (log.isDebugEnabled()) {
log.debug("Renew the session : previous session id :" + oldSessionID + " new session id :" + sessionID);
}
removeSession(oldSessionID);
endpoints = oldSession.getEndpointList();
currentMember = oldSession.getMember();
createSession = true;
} else {
SessionInformation information = getSessionInformation(oldSessionID);
if (information == null) {
// Therefore, it is recovered using session information in the message context
if (log.isDebugEnabled()) {
log.debug("Recovering lost session information for session id " + sessionID);
}
endpoints = oldSession.getEndpointList();
currentMember = oldSession.getMember();
createSession = true;
} else {
if (log.isDebugEnabled()) {
log.debug("Session with id : " + sessionID + " is still live.");
}
}
}
}
if (createSession) {
SessionInformation newInformation;
if (currentMember == null) {
newInformation = createSessionInformation(synCtx, sessionID, endpoints);
} else {
newInformation = createSessionInformation(synCtx, sessionID, currentMember, null);
}
if (log.isDebugEnabled()) {
log.debug("Establishing a session with id :" + sessionID + " and it's endpoint sequence : " + endpoints);
}
if (isClustered) {
Replicator.setAndReplicateState(SESSION_IDS + sessionID, newInformation, configCtx);
} else {
establishedSessions.put(sessionID, newInformation);
}
}
}
Aggregations