use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class CloneMediator method init.
public void init(SynapseEnvironment se) {
synapseEnv = se;
for (Target target : targets) {
ManagedLifecycle seq = target.getSequence();
if (seq != null) {
seq.init(se);
} else if (target.getSequenceRef() != null) {
SequenceMediator targetSequence = (SequenceMediator) se.getSynapseConfiguration().getSequence(target.getSequenceRef());
if (targetSequence == null || targetSequence.isDynamic()) {
se.addUnavailableArtifactRef(target.getSequenceRef());
}
}
Endpoint endpoint = target.getEndpoint();
if (endpoint != null) {
endpoint.init(se);
}
}
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class ForwardingService method validateResponse.
/**
* Validate if response can be considered as a successful Back-end invocation
*
* @param responseMessage MessageContext of response
* @return true if it is a successful invocation
*/
private boolean validateResponse(MessageContext responseMessage) {
boolean isSuccessful;
String responseSc = ((Axis2MessageContext) responseMessage).getAxis2MessageContext().getProperty(SynapseConstants.HTTP_SC).toString();
// Some events where response code is null (i.e. sender socket timeout
// when there is no response from endpoint)
int sc = 0;
try {
sc = Integer.parseInt(responseSc.trim());
isSuccessful = getHTTPStatusCodeFamily(sc).equals(HTTPStatusCodeFamily.SUCCESSFUL) || isNonRetryErrorCode(responseSc);
} catch (NumberFormatException nfe) {
isSuccessful = false;
}
if (!isSuccessful) {
String statusCode = " ";
if (sc != 0) {
statusCode = Integer.toString(sc);
}
log.info("Message processor [" + this.messageProcessor.getName() + "] received a response with HTTP_SC: " + statusCode + " from backend " + targetEndpoint + ". Message forwarding failed.");
}
return isSuccessful;
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class EndpointDeployer method undeploySynapseArtifact.
@Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Endpoint Undeployment of the endpoint named : " + artifactName + " : Started");
}
try {
Endpoint ep = getSynapseConfiguration().getDefinedEndpoints().get(artifactName);
if (ep != null) {
CustomLogSetter.getInstance().setLogAppender((ep != null) ? ep.getArtifactContainerName() : "");
getSynapseConfiguration().removeEndpoint(artifactName);
if (log.isDebugEnabled()) {
log.debug("Destroying the endpoint named : " + artifactName);
}
ep.destroy();
if (log.isDebugEnabled()) {
log.debug("Endpoint Undeployment of the endpoint named : " + artifactName + " : Completed");
}
log.info("Endpoint named '" + ep.getName() + "' has been undeployed");
} else if (log.isDebugEnabled()) {
log.debug("Endpoint " + artifactName + " has already been undeployed");
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Endpoint Undeployement of endpoint named : " + artifactName + " : Failed", e);
}
}
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, SessionCookie cookie) {
if (cookie == null || "".equals(cookie.getSessionId())) {
if (log.isDebugEnabled()) {
log.debug("Cannot find Session ID from the cookie.");
}
return;
}
String sessionId = cookie.getSessionId();
String path = cookie.getPath();
boolean createSession = false;
if (log.isDebugEnabled()) {
log.debug("Starting to update the session for : " + cookie);
}
// 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 corresponds to: " + cookie);
}
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();
// This assumes that there can only be one path
if (!sessionId.equals(oldSessionID) && pathMatches(path, oldSession.getPath())) {
if (log.isDebugEnabled()) {
log.debug("Renew the session : previous session id :" + oldSessionID + " new session :" + cookie);
}
removeSession(oldSessionID);
endpoints = oldSession.getEndpointList();
currentMember = oldSession.getMember();
createSession = true;
} else {
SessionInformation information = getSessionInformation(oldSessionID);
if (information == null) {
// 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;
List<String> paths = new ArrayList<String>();
// add the new path
paths.add(path);
if (currentMember == null) {
newInformation = createSessionInformation(synCtx, sessionId, endpoints, paths);
} else {
newInformation = createSessionInformation(synCtx, sessionId, currentMember, paths);
}
if (log.isDebugEnabled()) {
log.debug("Establishing a session for :" + cookie + " and it's endpoint sequence : " + endpoints);
}
if (isClustered) {
Replicator.setAndReplicateState(SESSION_IDS + sessionId, newInformation, configCtx);
} else {
establishedSessions.put(sessionId, newInformation);
}
}
}
use of org.apache.synapse.endpoints.Endpoint in project wso2-synapse by wso2.
the class SALSessions method fillMap.
/*
* Helper method to get a map from a list - This is for clustered env.
*/
private void fillMap(List<Endpoint> endpoints, Map<String, Endpoint> endpointsMap) {
if (endpoints != null) {
for (Endpoint endpoint : endpoints) {
String endpointName = getEndpointName(endpoint);
if (endpointsMap.containsKey(endpointName)) {
handleException("Endpoint Name with ' " + endpointName + "' already there. " + "Endpoint name must be unique.");
}
endpointsMap.put(endpointName, endpoint);
fillMap(endpoint.getChildren(), endpointsMap);
}
}
}
Aggregations