You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2008/05/25 16:26:58 UTC
svn commit: r659990 - in
/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse:
config/xml/endpoints/ endpoints/ endpoints/algorithms/ endpoints/dispatch/
Author: ruwan
Date: Sun May 25 07:26:57 2008
New Revision: 659990
URL: http://svn.apache.org/viewvc?rev=659990&view=rev
Log:
Fixing the issue SYNAPSE-325 client initiated session on a cluster is working, need to check the other 2
Added logging for the client initiated session, need to add logs to the other 2 sessions
Modified:
synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java
synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/SALoadbalanceEndpoint.java
synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java
synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java
synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/Dispatcher.java
synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java
synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java
Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java?rev=659990&r1=659989&r2=659990&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/SALoadbalanceEndpointFactory.java Sun May 25 07:26:57 2008
@@ -81,7 +81,8 @@
loadbalanceEndpoint.setDispatcher(csDispatcher);
}
} else {
- handleException("Session affinity endpoints should have a session element in the configuration.");
+ handleException("Session affinity endpoints should " +
+ "have a session element in the configuration.");
}
// set endpoint name
@@ -109,8 +110,8 @@
// set abandon time
//long abandonTime = 0;
- //OMAttribute atAttribute = loadbalanceElement.getAttribute
- // (new QName(null, org.apache.synapse.config.xml.Constants.RETRY_AFTER_FAILURE_TIME));
+ //OMAttribute atAttribute = loadbalanceElement.getAttribute(new QName(
+ // null, org.apache.synapse.config.xml.Constants.RETRY_AFTER_FAILURE_TIME));
//if(atAttribute != null) {
// String at = atAttribute.getAttributeValue();
// abandonTime = Long.parseLong(at);
@@ -138,6 +139,6 @@
return loadbalanceEndpoint;
}
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null;
}
}
Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java?rev=659990&r1=659989&r2=659990&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java Sun May 25 07:26:57 2008
@@ -67,7 +67,8 @@
}
if (log.isDebugEnabled()) {
- log.debug("Endpoint '" + getName() + "' is in state ' " + active + " '");
+ log.debug("AddressEndpoint with name '" + getName() + "' is in "
+ + (active ? "active" : "inactive") + " state");
}
return active;
@@ -140,9 +141,7 @@
if (endPointName == null) {
if (traceOrDebugOn && isClusteringEnable) {
- log.warn("In a clustering environment , the endpoint name should be specified" +
- "even for anonymous endpoints. Otherwise , the clustering would not be " +
- "functioned correctly if there are more than one anonymous endpoints. ");
+ log.warn(SALoadbalanceEndpoint.WARN_MESSAGE);
}
endPointName = SynapseConstants.ANONYMOUS_ENDPOINT;
}
Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/SALoadbalanceEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/SALoadbalanceEndpoint.java?rev=659990&r1=659989&r2=659990&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/SALoadbalanceEndpoint.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/SALoadbalanceEndpoint.java Sun May 25 07:26:57 2008
@@ -34,7 +34,6 @@
import org.apache.synapse.endpoints.dispatch.DispatcherContext;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
/**
@@ -64,10 +63,9 @@
public static final String ENDPOINT_LIST = "endpointList";
public static final String ROOT_ENDPOINT = "rootendpoint";
public static final String ENDPOINT_NAME_LIST = "endpointNameList";
- private static final String WARN_MESSAGE = "In a clustering environment , the endpoint " +
- " name should be specified" +
- "even for anonymous endpoints. Otherwise , the clustering would not be " +
- "functional correctly if there are more than one anonymous endpoints. ";
+ public static final String WARN_MESSAGE = "In a clustering environment, the endpoint " +
+ "name should be specified even for anonymous endpoints. Otherwise the clustering " +
+ "would not function properly, if there are more than one anonymous endpoints.";
/**
* Name of the endpoint. Used for named endpoints which can be referred using the key attribute
@@ -100,18 +98,19 @@
private Dispatcher dispatcher = null;
/**
- * The dispatcher context , place holder for keep any runtime states that are used when
+ * The dispatcher context, place holder for keeping any runtime states that are used when
* finding endpoint for the session
*/
private final DispatcherContext dispatcherContext = new DispatcherContext();
+
/**
- * The endpoint context , place holder for keep any runtime states related to the endpoint
+ * The endpoint context, place holder for keeping any runtime states related to the endpoint
*/
private final EndpointContext endpointContext = new EndpointContext();
/**
- * The algorithm context , place holder for keep any runtime states related to the load balance
- * algorithm
+ * The algorithm context, place holder for keeping any runtime states related to the load
+ * balance algorithm
*/
private final AlgorithmContext algorithmContext = new AlgorithmContext();
@@ -119,7 +118,7 @@
public void send(MessageContext synMessageContext) {
if (log.isDebugEnabled()) {
- log.debug("Start : Session Affinity Load-balance Endpoint");
+ log.debug("Start : Session Affinity Load-balance Endpoint " + name);
}
boolean isClusteringEnable = false;
@@ -129,40 +128,66 @@
ConfigurationContext cc = axisMC.getConfigurationContext();
//The check for clustering environment
-
ClusterManager clusterManager = cc.getAxisConfiguration().getClusterManager();
if (clusterManager != null &&
clusterManager.getContextManager() != null) {
isClusteringEnable = true;
}
- String endPointName = this.getName();
- if (endPointName == null) {
-
- if (log.isDebugEnabled() && isClusteringEnable) {
+ String endpointName = this.getName();
+ if (endpointName == null) {
+ if (isClusteringEnable) {
log.warn(WARN_MESSAGE);
}
- endPointName = SynapseConstants.ANONYMOUS_ENDPOINT;
+ if (log.isDebugEnabled()) {
+ log.debug("Using the name for the anonymous endpoint as : '"
+ + SynapseConstants.ANONYMOUS_ENDPOINT + "'");
+ }
+ endpointName = SynapseConstants.ANONYMOUS_ENDPOINT;
}
if (isClusteringEnable) {
- // if this is a cluster environment , then set configuration context to endpoint context
+
+ // if this is a cluster environment, then set configuration context to endpoint context
if (endpointContext.getConfigurationContext() == null) {
- endpointContext.setConfigurationContext(cc);
- endpointContext.setContextID(endPointName);
+ if (log.isDebugEnabled()) {
+ log.debug("Setting the ConfigurationContext to " +
+ "the EndpointContext with the name " + endpointName +
+ " for replicating data on the cluster");
+ }
+ endpointContext.setConfigurationContext(cc);
+ endpointContext.setContextID(endpointName);
}
- // if this is a cluster environment , then set configuration context to load balance
+
+ // if this is a cluster environment, then set configuration context to load balance
// algorithm context
if (algorithmContext.getConfigurationContext() == null) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Setting the ConfigurationContext to " +
+ "the AlgorithmContext with the name " + endpointName +
+ " for replicating data on the cluster");
+ }
algorithmContext.setConfigurationContext(cc);
- algorithmContext.setContextID(endPointName);
+ algorithmContext.setContextID(endpointName);
}
- // if this is a cluster environment , then set configuration context to session based
+
+ // if this is a cluster environment, then set configuration context to session based
// endpoint dispatcher
if (dispatcherContext.getConfigurationContext() == null) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Setting the ConfigurationContext to " +
+ "the DispatcherContext with the name " + endpointName +
+ " for replicating data on the cluster");
+ }
dispatcherContext.setConfigurationContext(cc);
- dispatcherContext.setContextID(endPointName);
+ dispatcherContext.setContextID(endpointName);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Setting the endpoints to the DispatcherContext : " + endpoints);
+ }
dispatcherContext.setEndpoints(endpoints);
}
}
@@ -179,28 +204,34 @@
// this is a start of a new session. so update session map.
if (dispatcher.isServerInitiatedSession()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Creating a new server initiated session for the current message");
+ }
+
// add this endpoint to the endpoint sequence of operation context.
Axis2MessageContext axis2MsgCtx = (Axis2MessageContext) synMessageContext;
OperationContext opCtx = axis2MsgCtx.getAxis2MessageContext().getOperationContext();
- if (isClusteringEnable) { // if this is a clustering env.
- //Only keeps endpoint names , because , it is heavy task to
- // replicate endpoint itself
+ if (isClusteringEnable) {
+ // If running on a cluster keeps endpoint names, because it is heavy task to
+ // replicate endpoint itself
Object o = opCtx.getPropertyNonReplicable(ENDPOINT_NAME_LIST);
- List epNameList;
+ List<String> epNameList;
if (o instanceof List) {
- epNameList = (List) o;
- epNameList.add(endPointName);
+ epNameList = (List<String>) o;
+ // todo : check the following statement : ruwan
+ epNameList.add(endpointName);
} else {
- // this is the first endpoint in the heirachy. so create the queue and insert
- // this as the first element.
- epNameList = new ArrayList();
- epNameList.add(endPointName);
- opCtx.setNonReplicableProperty(ROOT_ENDPOINT,this);
+ // this is the first endpoint in the heirachy. so create the queue and
+ // insert this as the first element.
+ epNameList = new ArrayList<String>();
+ epNameList.add(endpointName);
+ opCtx.setNonReplicableProperty(ROOT_ENDPOINT, this);
}
+
// if the next endpoint is not a session affinity one, endpoint sequence ends
// here. but we have to add the next endpoint to the list.
if (!(endpoint instanceof SALoadbalanceEndpoint)) {
@@ -212,22 +243,27 @@
epNameList.add(name);
}
+ if (log.isDebugEnabled()) {
+ log.debug("Operating on a cluster. Setting the endpoint name list to " +
+ "the OperationContext : " + epNameList);
+ }
opCtx.setProperty(ENDPOINT_NAME_LIST, epNameList);
} else {
+
Object o = opCtx.getProperty(ENDPOINT_LIST);
List<Endpoint> endpointList;
if (o instanceof List) {
endpointList = (List<Endpoint>) o;
endpointList.add(this);
-
} else {
- // this is the first endpoint in the heirachy. so create the queue and insert
- // this as the first element.
- endpointList = new ArrayList();
+ // this is the first endpoint in the heirachy. so create the queue and
+ // insert this as the first element.
+ endpointList = new ArrayList<Endpoint>();
endpointList.add(this);
opCtx.setProperty(ENDPOINT_LIST, endpointList);
}
+
// if the next endpoint is not a session affinity one, endpoint sequence ends
// here. but we have to add the next endpoint to the list.
if (!(endpoint instanceof SALoadbalanceEndpoint)) {
@@ -254,6 +290,12 @@
// endpoints given by session dispatchers may not be active. therefore, we have check
// it here.
if (endpoint.isActive(synMessageContext)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Using the endpoint on the session with "
+ + ((endpoint instanceof IndirectEndpoint) ? "key : "
+ + ((IndirectEndpoint) endpoint).getKey() : "name : "
+ + endpoint.getName()) + " for sending the message");
+ }
endpoint.send(synMessageContext);
} else {
informFailure(synMessageContext);
@@ -262,6 +304,10 @@
} else {
// all child endpoints have failed. so mark this also as failed.
+ if (log.isDebugEnabled()) {
+ log.debug("Marking the Endpoint as failed, " +
+ "because all child endpoints has been failed");
+ }
setActive(false, synMessageContext);
informFailure(synMessageContext);
}
@@ -284,9 +330,16 @@
// Only keeps endpoint names , because , it is heavy task to
// replicate endpoint itself
String epNameObj = (String) endpointList.remove(0);
- for (Endpoint ep :endpoints) {
+ for (Endpoint ep : endpoints) {
if (ep != null) {
- String name = ep.getName();
+
+ String name;
+ if (ep instanceof IndirectEndpoint) {
+ name = ((IndirectEndpoint) ep).getKey();
+ } else {
+ name = ep.getName();
+ }
+
if (name != null && name.equals(epNameObj)) {
endpoint = ep;
break;
@@ -361,6 +414,12 @@
endpointContext.setActive(active);
}
}
+
+ if (log.isDebugEnabled()) {
+ log.debug("SALoadbalanceEndpoint with name '" + getName() + "' is in "
+ + (active ? "active" : "inactive") + " state");
+ }
+
return active;
}
@@ -420,11 +479,11 @@
private void informFailure(MessageContext synMessageContext) {
+ log.warn("Failed to send using the selected endpoint, becasue it is inactive");
+
if (parentEndpoint != null) {
parentEndpoint.onChildEndpointFail(this, synMessageContext);
-
} else {
-
Object o = synMessageContext.getFaultStack().pop();
if (o != null) {
((FaultHandler) o).handleFault(synMessageContext);
Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java?rev=659990&r1=659989&r2=659990&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java Sun May 25 07:26:57 2008
@@ -242,7 +242,8 @@
}
if (log.isDebugEnabled()) {
- log.debug("Endpoint '" + name + "' is in state ' " + active + " '");
+ log.debug("WSDLEndpoint with name '" + name + "' is in "
+ + (active ? "active" : "inactive") + " state");
}
return active;
Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java?rev=659990&r1=659989&r2=659990&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java Sun May 25 07:26:57 2008
@@ -19,17 +19,24 @@
package org.apache.synapse.endpoints.algorithms;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.endpoints.Endpoint;
import java.util.ArrayList;
/**
- * This is the implementation of the round robin load balancing algorithm. It simply iterates through
- * the endpoint list one by one for until an active endpoint is found.
+ * This is the implementation of the round robin load balancing algorithm. It simply iterates
+ * through the endpoint list one by one for until an active endpoint is found.
*/
public class RoundRobin implements LoadbalanceAlgorithm {
+ private static final Log log = LogFactory.getLog(RoundRobin.class);
+
+ /**
+ * Endpoints list for the round robin algorithm
+ */
private ArrayList endpoints = null;
public RoundRobin(ArrayList endpoints) {
@@ -44,7 +51,12 @@
* @param algorithmContext The context in which holds run time states related to the algorithm
* @return endpoint to send the next message
*/
- public Endpoint getNextEndpoint(MessageContext synapseMessageContext, AlgorithmContext algorithmContext) {
+ public Endpoint getNextEndpoint(MessageContext synapseMessageContext,
+ AlgorithmContext algorithmContext) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Using the Round Robin loadbalancing algorithm to select the next endpoint");
+ }
Endpoint nextEndpoint;
int attempts = 0;
@@ -64,6 +76,7 @@
attempts++;
if (attempts > endpoints.size()) {
+ log.warn("Couldn't find an endpoint from the Round Robin loadbalancing algorithm");
return null;
}
@@ -73,6 +86,9 @@
}
public void reset(AlgorithmContext algorithmContext) {
+ if (log.isDebugEnabled()) {
+ log.debug("Resetting the Round Robin loadbalancing algorithm ...");
+ }
algorithmContext.setCurrentEPR(0);
}
}
Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/Dispatcher.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/Dispatcher.java?rev=659990&r1=659989&r2=659990&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/Dispatcher.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/Dispatcher.java Sun May 25 07:26:57 2008
@@ -37,24 +37,28 @@
* synapseMessageContext is not found it should return null.
*
* @param synCtx client -> esb message context.
+ * @param dispatcherContext context for dispatching
* @return Endpoint Endpoint associated with this session.
*/
public Endpoint getEndpoint(MessageContext synCtx, DispatcherContext dispatcherContext);
/**
* Updates the session maps. This will be called in the first client -> synapse -> server flow
- * for client initiated sessions. For server initiated sessions, this will be called in the first
- * server -> synapse -> client flow.
+ * for client initiated sessions. For server initiated sessions, this will be called in the
+ * first server -> synapse -> client flow.
*
* @param synCtx SynapseMessageContext
+ * @param dispatcherContext context for dispatching
* @param endpoint Selected endpoint for this session.
*/
- public void updateSession(MessageContext synCtx, DispatcherContext dispatcherContext, Endpoint endpoint);
+ public void updateSession(MessageContext synCtx, DispatcherContext dispatcherContext,
+ Endpoint endpoint);
/**
* Removes the session belonging to the given message context.
*
* @param synCtx MessageContext containing an session ID.
+ * @param dispatcherContext context for dispatching
*/
public void unbind(MessageContext synCtx, DispatcherContext dispatcherContext);
Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java?rev=659990&r1=659989&r2=659990&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/DispatcherContext.java Sun May 25 07:26:57 2008
@@ -26,6 +26,8 @@
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.endpoints.IndirectEndpoint;
+import org.apache.synapse.endpoints.SALoadbalanceEndpoint;
import java.util.Collections;
import java.util.HashMap;
@@ -110,20 +112,25 @@
public void setEndpoint(String sessionID, Endpoint endpoint) {
if (isClusteringEnable) { // if this is a clustering env.
- String endPointName = endpoint.getName();
- if (endPointName == null) {
+
+ String endpointName;
+ if (endpoint instanceof IndirectEndpoint) {
+ endpointName = ((IndirectEndpoint) endpoint).getKey();
+ } else {
+ endpointName = endpoint.getName();
+ }
+
+ if (endpointName == null && !(endpoint instanceof IndirectEndpoint)) {
if (log.isDebugEnabled() && isClusteringEnable()) {
- log.warn("In a clustering environment , the endpoint name should be" +
- " specified even for anonymous endpoints. Otherwise , the " +
- "clustering would not be functioned correctly if there are" +
- " more than one anonymous endpoints. ");
+ log.warn(SALoadbalanceEndpoint.WARN_MESSAGE);
}
- endPointName = SynapseConstants.ANONYMOUS_ENDPOINT;
+ endpointName = SynapseConstants.ANONYMOUS_ENDPOINT;
}
+
if (keyPrefix != null) {
// replicates the state so that all instances across cluster can see this state
- setAndReplicateState(keyPrefix + sessionID, endPointName);
+ setAndReplicateState(keyPrefix + sessionID, endpointName);
}
} else {
@@ -305,19 +312,22 @@
if (endpoints != null) {
for (Endpoint endpoint : endpoints) {
- String endPointName = endpoint.getName();
- if (endPointName == null) {
+
+ String endpointName;
+ if (endpoint instanceof IndirectEndpoint) {
+ endpointName = ((IndirectEndpoint) endpoint).getKey();
+ } else {
+ endpointName = endpoint.getName();
+ }
+
+ if (endpointName == null) {
if (log.isDebugEnabled() && isClusteringEnable()) {
- log.warn("In a clustering environment , the endpoint name should be" +
- " specified even for anonymous endpoints. Otherwise , the " +
- "clustering would not be functioned correctly if there are" +
- " more than one anonymous endpoints. ");
+ log.warn(SALoadbalanceEndpoint.WARN_MESSAGE);
}
- endPointName = SynapseConstants.ANONYMOUS_ENDPOINT;
+ endpointName = SynapseConstants.ANONYMOUS_ENDPOINT;
}
- endpointsMap.put(endPointName, endpoint);
-
+ endpointsMap.put(endpointName, endpoint);
}
}
}
Modified: synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java
URL: http://svn.apache.org/viewvc/synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java?rev=659990&r1=659989&r2=659990&view=diff
==============================================================================
--- synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java (original)
+++ synapse/branches/1.2/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java Sun May 25 07:26:57 2008
@@ -30,7 +30,7 @@
/**
* This dispatcher is implemented to demonstrate a sample client session. It will detect sessions
- * based on the <syn:ClientID xmlns:syn="http://ws.apache.org/namespaces/synapse"> soap header of the
+ * based on the <syn:ClientID xmlns:syn="http://ws.apache.org/ns/synapse"> soap header of the
* request message. Therefore, above header has to be included in the request soap messages by the
* client who wants to initiate and maintain a session.
*/
@@ -38,31 +38,42 @@
private static final Log log = LogFactory.getLog(SimpleClientSessionDispatcher.class);
+ private static final QName CSID_QNAME
+ = new QName("http://ws.apache.org/ns/synapse", "ClientID", "syn");
+
public Endpoint getEndpoint(MessageContext synCtx, DispatcherContext dispatcherContext) {
SOAPHeader header = synCtx.getEnvelope().getHeader();
if (header != null) {
- OMElement sgcIDElm = header.getFirstChildWithName(
- new QName("http://ws.apache.org/namespaces/synapse", "ClientID", "syn"));
+ OMElement sgcIDElm = header.getFirstChildWithName(CSID_QNAME);
if (sgcIDElm != null) {
String sgcID = sgcIDElm.getText();
if (sgcID != null) {
+ log.debug("Using the client session id : '"
+ + sgcID + "' extracted from current message to retrieve endpoint");
Object o = dispatcherContext.getEndpoint(sgcID);
if (o != null && o instanceof Endpoint) {
return (Endpoint) o;
}
+ } else if (log.isDebugEnabled()) {
+ log.debug("Couldn't find the client session id for the current message " +
+ "to retrieve endpoint");
}
+ } else if (log.isDebugEnabled()) {
+ log.debug("Couldn't find a SOAP header with the QName " + CSID_QNAME +
+ " for the current message to retrieve the endpoint");
}
}
return null;
}
- public void updateSession(MessageContext synCtx, DispatcherContext dispatcherContext, Endpoint endpoint) {
+ public void updateSession(MessageContext synCtx, DispatcherContext dispatcherContext,
+ Endpoint endpoint) {
if (endpoint == null || dispatcherContext == null) {
return;
@@ -71,15 +82,24 @@
SOAPHeader header = synCtx.getEnvelope().getHeader();
if (header != null) {
- OMElement csIDElm = header.getFirstChildWithName(
- new QName("http://ws.apache.org/namespaces/synapse", "ClientID", "syn"));
+ OMElement csIDElm = header.getFirstChildWithName(CSID_QNAME);
if (csIDElm != null) {
String csID = csIDElm.getText();
if (csID != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Using the client session id : '"
+ + csID + "' extracted from current message to update the session");
+ }
dispatcherContext.setEndpoint(csID, endpoint);
+ } else if (log.isDebugEnabled()) {
+ log.debug("Couldn't find the client session id for the current message " +
+ "to update the session");
}
+ } else if (log.isDebugEnabled()) {
+ log.debug("Couldn't find a SOAP header with the QName " + CSID_QNAME +
+ " for the current message to update the session");
}
}
}
@@ -94,15 +114,20 @@
SOAPHeader header = synCtx.getEnvelope().getHeader();
if (header != null) {
- OMElement csIDElm = header.getFirstChildWithName(
- new QName("http://ws.apache.org/namespaces/synapse", "ClientID", "syn"));
+ OMElement csIDElm = header.getFirstChildWithName(CSID_QNAME);
if (csIDElm != null) {
String csID = csIDElm.getText();
if (csID != null) {
dispatcherContext.removeSession(csID);
+ } else if (log.isDebugEnabled()) {
+ log.debug("Couldn't find the client session id for the current message " +
+ "to unbind the session");
}
+ } else if (log.isDebugEnabled()) {
+ log.debug("Couldn't find a SOAP header with the QName " + CSID_QNAME +
+ " for the current message to unbind the session");
}
}
}