You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by as...@apache.org on 2008/10/07 20:38:47 UTC
svn commit: r702579 [5/6] - in /synapse/trunk/java/modules:
core/src/main/java/org/apache/synapse/
core/src/main/java/org/apache/synapse/config/
core/src/main/java/org/apache/synapse/config/xml/
core/src/main/java/org/apache/synapse/config/xml/endpoint...
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SALSessions.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SALSessions.java?rev=702579&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SALSessions.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SALSessions.java Tue Oct 7 11:38:44 2008
@@ -0,0 +1,554 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.endpoints.dispatch;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.MessageContext;
+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 org.apache.synapse.util.Replicator;
+
+import java.util.*;
+
+/**
+ * Keeps the states of the sessions
+ */
+public class SALSessions {
+
+ private static final SALSessions INSTANCE = new SALSessions();
+
+ private static final Log log = LogFactory.getLog(SALSessions.class);
+
+ private String SESSION_IDS = "synapse.salep.sessionids.";
+
+ private static ConfigurationContext configCtx;
+
+ /* Is this env. support clustering*/
+ private static boolean isClustered = false;
+
+ private static boolean initialized = false;
+
+ /*Cache all path with its endpoint sequence. This is only need for a clustered environment */
+ private final Map<List<String>, List<Endpoint>> namesToEndpointsMap =
+ new HashMap<List<String>, List<Endpoint>>();
+
+ /* Non- clustered environment , all the established sessions*/
+ private final Map<String, SessionInformation> establishedSessions =
+ new HashMap<String, SessionInformation>();
+ /* all child endpoints . This is only need for a clustered environment*/
+ private final Map<String, Map<String, Endpoint>> childEndpoints =
+ new HashMap<String, Map<String, Endpoint>>();
+
+ private SALSessions() {
+ }
+
+ public static SALSessions getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Initialize SALSessions instance
+ *
+ * @param isClusteringEnable is this a clustered environment
+ * @param cc Axis config context
+ */
+ public void initialize(boolean isClusteringEnable, ConfigurationContext cc) {
+
+ if (!initialized) {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing SALSessions instance. Environment : " +
+ (isClusteringEnable ? " clustered" : " local"));
+ }
+ if (isClusteringEnable) {
+ isClustered = isClusteringEnable;
+ configCtx = cc;
+ }
+ initialized = true;
+ }
+ }
+
+ /**
+ * This method only use in a clustered environment.
+ *
+ * @param endpoint Root endpoint name
+ * @param endpoints children
+ */
+ public void registerChildren(Endpoint endpoint, List<Endpoint> endpoints) {
+
+ if (isClustered) {
+
+ String endpointName = endpoint.getName();
+
+ validateInput(endpointName);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Registering endpoints " + endpoints + " of " + endpointName);
+ }
+
+ if (!childEndpoints.containsKey(endpointName)) {
+
+ Map<String, Endpoint> children = new HashMap<String, Endpoint>();
+ children.put(endpointName, endpoint);
+ fillMap(endpoints, children);
+ childEndpoints.put(endpointName, children);
+
+ }
+ }
+
+ }
+
+ /**
+ * 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;
+
+ 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);
+ 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();
+ createSession = true;
+
+ } else {
+
+ SessionInformation information = getSessionInformation(oldSessionID);
+ if (information == null) {
+ // This means , our session information has been removed during getting response.
+ // 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();
+ createSession = true;
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Session with id : " + sessionID + " is still live.");
+ }
+ }
+ }
+ }
+
+ if (createSession) {
+
+ SessionInformation newInformation = createSessionInformation(
+ synCtx, sessionID, endpoints);
+
+ 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);
+ }
+ }
+ }
+
+ /**
+ * return the endpoint for the given session.
+ * Null will be returned , if there is no endpoint for given session.
+ *
+ * @param sessionID The session identifier
+ * @return Returns the endpoint for the given session.
+ */
+ public SessionInformation getSession(String sessionID) {
+
+ if (sessionID == null || "".equals(sessionID)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Cannot find session ID .Returing null");
+ }
+ return null;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Retrieving the endpoint from the session id " + sessionID);
+ }
+
+ SessionInformation information = getSessionInformation(sessionID);
+ if (information == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Session information cannot be found for session id " + sessionID);
+ }
+ return null;
+ }
+
+ if (information.isExpired()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Session has been expired for session with id: " + sessionID);
+ }
+ removeSession(sessionID);
+ return null;
+ }
+
+ return information;
+ }
+
+ /**
+ * Returns endpoint sequence related to the given session
+ *
+ * @param information Session information
+ * @return endpoint sequence
+ */
+ public List<Endpoint> getChildEndpoints(SessionInformation information) {
+
+ List<Endpoint> endpoints;
+ if (isClustered) {
+ endpoints =
+ getEndpoints(information.getPath(), information.getRootEndpointName());
+ } else {
+ endpoints = information.getEndpointList();
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Retrieving endpoint sequence : " + endpoints +
+ " for session " + information.getId());
+ }
+
+ if (endpoints == null || endpoints.isEmpty()) {
+ handleException("Session with id " + information.getId() + " is invalid ." +
+ " A session must have a endpoint sequence associated with it");
+ }
+
+ List<Endpoint> toBeSent = new ArrayList<Endpoint>();
+ toBeSent.addAll(endpoints);
+ //remove the root as only expect children
+ toBeSent.remove(0);
+
+ return toBeSent;
+ }
+
+ /**
+ * Removes the endpoint for the given session.
+ *
+ * @param sessionId The session identifier
+ */
+ public void removeSession(String sessionId) {
+
+ if (sessionId == null || "".equals(sessionId)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Session Id cannot be found.The session will not be removed.");
+ }
+ return;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Removing the session with the session Id " + sessionId);
+ }
+
+ if (isClustered) {
+ Replicator.removeAndReplicateState(SESSION_IDS + sessionId, configCtx);
+
+ } else {
+ establishedSessions.remove(sessionId);
+ }
+ }
+
+ /**
+ * Clear all the expired sessions
+ */
+ public synchronized void clearSessions() {
+
+ if (!initialized) {
+ return;
+ }
+
+ try {
+ if (isClustered) {
+
+ List<String> toBeRemoved = new ArrayList<String>();
+ for (Iterator props = configCtx.getPropertyNames(); props.hasNext();) {
+ Object name = props.next();
+
+ if (name instanceof String && ((String) name).startsWith(SESSION_IDS)) {
+ String key = (String) name;
+ SessionInformation info = (SessionInformation) configCtx.getProperty(key);
+
+ if (info != null && info.isExpired()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Clustered Environment :" +
+ "Expired session with id :" + key);
+ }
+
+ toBeRemoved.add(key);
+ }
+ }
+ }
+
+ if (!toBeRemoved.isEmpty()) {
+ log.info("Clearing expired sessions");
+
+ for (String key : toBeRemoved) {
+ Replicator.removeAndReplicateState(key, configCtx);
+ }
+ }
+
+ } else {
+
+ List<String> toBeRemoved = new ArrayList<String>();
+ for (SessionInformation information : establishedSessions.values()) {
+
+ if (information != null && information.isExpired()) {
+ String id = information.getId();
+ if (log.isDebugEnabled()) {
+ log.debug("Expired session with id :" + id);
+ }
+ toBeRemoved.add(id);
+ }
+ }
+
+ if (!toBeRemoved.isEmpty()) {
+ log.info("Clearing expired sessions");
+ establishedSessions.keySet().removeAll(toBeRemoved);
+ }
+ }
+ } catch (Throwable ignored) {
+ log.debug("Ignored error clearing sessions : Error " + ignored);
+ }
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
+ /**
+ * Helper methods for handle errors.
+ *
+ * @param msg The error message
+ */
+ private static void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ public void reset() {
+ log.info("Clearing all states ");
+ initialized = false;
+ establishedSessions.clear();
+ namesToEndpointsMap.clear();
+ childEndpoints.clear();
+ }
+ /*
+ * 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);
+ }
+ }
+ }
+
+ /*
+ * Helper method to get a name of endpoints from a endpoint list - This is for clustered env.
+ */
+ private List<String> getEndpointNames(List<Endpoint> endpoints) {
+
+ List<String> endpointNames = new ArrayList<String>();
+ for (Endpoint endpoint : endpoints) {
+ endpointNames.add(getEndpointName(endpoint));
+ }
+ return endpointNames;
+ }
+
+ /*
+ * Helper method to get a list of endpoints from a list of endpoint name maps - This is for clustered env.
+ */
+ private List<Endpoint> getEndpoints(List<String> endpointNames, String root) {
+
+ if (endpointNames == null || endpointNames.isEmpty()) {
+ handleException("Invalid session - path cannot be null.");
+
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Retrieving endpoint sequence for path " + endpointNames);
+ }
+ List<Endpoint> endpoints = new ArrayList<Endpoint>();
+ // First looking at cache - we cache path -> endpoint list . o.w It is a cost
+ // to each time calculate
+ if (namesToEndpointsMap.containsKey(endpointNames)) {
+ endpoints.addAll(namesToEndpointsMap.get(endpointNames));
+ return endpoints;
+ }
+
+ Map<String, Endpoint> map = childEndpoints.get(root);
+ for (String endpointName : endpointNames) {
+ Endpoint endpoint = null;
+ if (map != null) {
+ endpoint = map.get(endpointName);
+ if (endpoint == null || endpoints.contains(endpoint)) {
+ map = childEndpoints.get(endpointName);
+ if (map != null) {
+ endpoint = map.get(endpointName);
+ }
+ }
+ }
+ if (endpoint == null) {
+ handleException("Invalid session. Endpoint with name '" +
+ endpointName + "' cannot found");
+ }
+ endpoints.add(endpoint);
+ }
+ //cache path(endpoint names) vs endpoint (instance) sequence
+ namesToEndpointsMap.put(endpointNames, endpoints);
+
+ return endpoints;
+ }
+
+ /*
+ * Validate endpoint name
+ */
+ private void validateInput(String endpointName) {
+
+ if (endpointName == null) {
+ handleException("For proper clustered mode operation, " +
+ "all endpoints should be uniquely named");
+ }
+ }
+
+ /*
+ * Returns an endpoint name for the endpoint object - This is for clustered env.
+ */
+ private String getEndpointName(Endpoint endpoint) {
+
+ if (endpoint == null) {
+ handleException("Endpoint cannot be null.");
+ }
+
+ String endpointName = endpoint.getName();
+ if (endpointName == null && endpoint instanceof IndirectEndpoint) {
+ endpointName = ((IndirectEndpoint) endpoint).getKey();
+ }
+ validateInput(endpointName);
+ return endpointName;
+ }
+
+ /*
+ * Returns a session information for given session id
+ */
+ private SessionInformation getSessionInformation(String sessionID) {
+
+ if (isClustered) {
+ return (SessionInformation)
+ configCtx.getPropertyNonReplicable(SESSION_IDS + sessionID);
+ } else {
+ return establishedSessions.get(sessionID);
+ }
+ }
+
+ /*
+ * Factory method to create a session information using given endpoint list , session id and other informations
+ */
+ private SessionInformation createSessionInformation(MessageContext synCtx, String id, List<Endpoint> endpoints) {
+
+ if (endpoints == null || endpoints.isEmpty()) {
+ handleException("Invalid request to create sessions . Cannot find a endpoint sequence.");
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Creating a session information for given session id " + id
+ + " with endpoint sequence " + endpoints);
+ }
+
+ long expireTimeWindow = -1;
+ for (Endpoint endpoint : endpoints) {
+
+ if (endpoint instanceof SALoadbalanceEndpoint) {
+ long sessionsTimeout = ((SALoadbalanceEndpoint) endpoint).getSessionTimeout();
+
+ if (expireTimeWindow == -1) {
+ expireTimeWindow = sessionsTimeout;
+ } else if (expireTimeWindow > sessionsTimeout) {
+ expireTimeWindow = sessionsTimeout;
+ }
+ }
+ }
+
+ if (expireTimeWindow == -1) {
+ expireTimeWindow = synCtx.getConfiguration().getProperty(
+ SynapseConstants.PROP_SAL_ENDPOINT_DEFAULT_SESSION_TIMEOUT,
+ SynapseConstants.SAL_ENDPOINTS_DEFAULT_SESSION_TIMEOUT);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("For session with id " + id + " : expiry time interval : " + expireTimeWindow);
+ }
+
+ long expiryTime = System.currentTimeMillis() + expireTimeWindow;
+
+ Endpoint rootEndpoint = endpoints.get(0);
+
+ SessionInformation information = new SessionInformation(id,
+ endpoints, expiryTime);
+
+ if (isClustered) {
+ List<String> epNameList = getEndpointNames(endpoints);
+ information.setPath(epNameList);
+ information.setRootEndpointName(getEndpointName(rootEndpoint));
+ }
+ return information;
+ }
+}
\ No newline at end of file
Propchange: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SALSessions.java
------------------------------------------------------------------------------
svn:executable = *
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SessionInformation.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SessionInformation.java?rev=702579&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SessionInformation.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SessionInformation.java Tue Oct 7 11:38:44 2008
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.endpoints.dispatch;
+
+
+import org.apache.synapse.endpoints.Endpoint;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * DataStructure for session information
+ */
+public class SessionInformation implements Serializable {
+
+ private static final long serialVersionUID = -3771579091940569938L;
+ private String id;
+ private String rootEndpointName;
+ private List<String> path;
+ private long expiryTime;
+ private transient List<Endpoint> endpointList;
+
+ public SessionInformation(String id, List<Endpoint> endpointList, long expiryTime) {
+ this.id = id;
+ this.endpointList = endpointList;
+ this.expiryTime = expiryTime;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public List<String> getPath() {
+ return path;
+ }
+
+ public void setPath(List<String> path) {
+ this.path = path;
+ }
+
+ public long getExpiryTime() {
+ return expiryTime;
+ }
+
+ public void setExpiryTime(long expiryTime) {
+ this.expiryTime = expiryTime;
+ }
+
+ public List<Endpoint> getEndpointList() {
+ return endpointList;
+ }
+
+ public void setEndpointList(List<Endpoint> endpointList) {
+ this.endpointList = endpointList;
+ }
+
+ public String getRootEndpointName() {
+ return rootEndpointName;
+ }
+
+ public void setRootEndpointName(String rootEndpointName) {
+ this.rootEndpointName = rootEndpointName;
+ }
+
+ public boolean isExpired() {
+ return expiryTime < System.currentTimeMillis();
+ }
+
+}
+
Propchange: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SessionInformation.java
------------------------------------------------------------------------------
svn:executable = *
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SimpleClientSessionDispatcher.java Tue Oct 7 11:38:44 2008
@@ -19,12 +19,7 @@
package org.apache.synapse.endpoints.dispatch;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.soap.SOAPHeader;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
-import org.apache.synapse.endpoints.Endpoint;
import javax.xml.namespace.QName;
@@ -34,105 +29,33 @@
* 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.
*/
-public class SimpleClientSessionDispatcher implements Dispatcher {
+public class SimpleClientSessionDispatcher extends AbstractDispatcher {
- 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");
+ private static final QName CSID_QNAME = new QName("http://ws.apache.org/ns/synapse",
+ "ClientID", "syn");
- public Endpoint getEndpoint(MessageContext synCtx, DispatcherContext dispatcherContext) {
+ public SessionInformation getSession(MessageContext synCtx) {
- SOAPHeader header = synCtx.getEnvelope().getHeader();
-
- if (header != null) {
- 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;
+ return SALSessions.getInstance().getSession(
+ extractSessionID(synCtx.getEnvelope().getHeader(), CSID_QNAME));
}
- public void updateSession(MessageContext synCtx, DispatcherContext dispatcherContext,
- Endpoint endpoint) {
-
- if (endpoint == null || dispatcherContext == null) {
- return;
- }
-
- SOAPHeader header = synCtx.getEnvelope().getHeader();
-
- if (header != null) {
- 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");
- }
- }
+ public void updateSession(MessageContext synCtx) {
+ SALSessions.getInstance().updateSession(synCtx,
+ extractSessionID(synCtx.getEnvelope().getHeader(), CSID_QNAME));
}
-
- public void unbind(MessageContext synCtx, DispatcherContext dispatcherContext) {
-
- if (dispatcherContext == null) {
- return;
- }
-
- SOAPHeader header = synCtx.getEnvelope().getHeader();
-
- if (header != null) {
- 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");
- }
- }
+ public void unbind(MessageContext synCtx) {
+ SALSessions.getInstance().removeSession(
+ extractSessionID(synCtx.getEnvelope().getHeader(), CSID_QNAME));
}
public boolean isServerInitiatedSession() {
return false;
}
+
+ public void removeSessionID(MessageContext syCtx) {
+ // no need to remove
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/dispatch/SoapSessionDispatcher.java Tue Oct 7 11:38:44 2008
@@ -22,16 +22,12 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.SOAPHeader;
import org.apache.axis2.addressing.AddressingConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
-import org.apache.synapse.endpoints.Endpoint;
import javax.xml.namespace.QName;
-public class SoapSessionDispatcher implements Dispatcher {
+public class SoapSessionDispatcher extends AbstractDispatcher {
- private static final Log log = LogFactory.getLog(SoapSessionDispatcher.class);
private static final QName QNAME_SERVICE_GROUP_ID
= new QName("http://ws.apache.org/namespaces/axis2", "ServiceGroupId", "axis2");
@@ -44,31 +40,9 @@
* message and if current message is not the first message of the session. Returns null,
* if an Endpoint could not be found for the session.
*/
- public Endpoint getEndpoint(MessageContext synCtx, DispatcherContext dispatcherContext) {
-
- Endpoint endpoint = null;
- SOAPHeader header = synCtx.getEnvelope().getHeader();
-
- if (header != null) {
- OMElement sgcElm = header.getFirstChildWithName(QNAME_SERVICE_GROUP_ID);
-
- if (sgcElm != null) {
- String sgcID = sgcElm.getText();
-
- if (sgcID != null) {
- if (log.isDebugEnabled()) {
- log.debug("Using the ServiceGroupId SOAP header value "
- + sgcID + " to retrieve endpoint on the session");
- }
- endpoint = dispatcherContext.getEndpoint(sgcID);
- }
- } else if (log.isDebugEnabled()) {
- log.debug("Couldn't find the ServiceQroupId SOAP " +
- "header to retrieve the endpoint on the session");
- }
- }
-
- return endpoint;
+ public SessionInformation getSession(MessageContext synCtx) {
+ return SALSessions.getInstance().getSession(
+ extractSessionID(synCtx.getEnvelope().getHeader(), QNAME_SERVICE_GROUP_ID));
}
/**
@@ -76,20 +50,14 @@
* It extracts the service group context ID (if available) from the message and updates the
* session (service group context ID) -> endpoint map.
*
- * @param synCtx MessageContext of the response message.
- * @param endpoint Endpoint to associate with the session.
+ * @param synCtx MessageContext of the response message.
*/
- public void updateSession(MessageContext synCtx, DispatcherContext dispatcherContext,
- Endpoint endpoint) {
+ public void updateSession(MessageContext synCtx) {
- if (endpoint == null || dispatcherContext == null) {
- return;
- }
// get the service group context id
// check if service group context id is a key of any entry
// if not, add an entry <service group context id, endpoint>
-
SOAPHeader header = synCtx.getEnvelope().getHeader();
if (header != null) {
@@ -101,24 +69,9 @@
"http://www.w3.org/2005/08/addressing", "ReferenceParameters", "wsa"));
if (referenceParameters != null) {
- OMElement sgcElm
- = referenceParameters.getFirstChildWithName(QNAME_SERVICE_GROUP_ID);
+ SALSessions.getInstance().updateSession(synCtx,
+ extractSessionID(referenceParameters, QNAME_SERVICE_GROUP_ID));
- if (sgcElm != null) {
- // synchronized to avoid possible replacement of sessions
- String sgcID = sgcElm.getText();
-
- if (sgcID != null) {
- if (log.isDebugEnabled()) {
- log.debug("Using the ServiceGroupId value "
- + sgcID + " to update the endpoint session");
- }
- dispatcherContext.setEndpoint(sgcID, endpoint);
- }
- } else if (log.isDebugEnabled()) {
- log.debug("Couldn't find the WSA ServiceQroupId on the " +
- "ReferenceParameters of the Reply-To header to update the session");
- }
} else if (log.isDebugEnabled()) {
log.debug("Couldn't find the WSA ReferenceParameters in the Reply-To " +
"header to retrieve the ServiceQroupId");
@@ -129,27 +82,9 @@
}
}
- public void unbind(MessageContext synCtx, DispatcherContext dispatcherContext) {
-
- SOAPHeader header = synCtx.getEnvelope().getHeader();
-
- if (header != null) {
- OMElement sgcIDElm = header.getFirstChildWithName(QNAME_SERVICE_GROUP_ID);
-
- if (sgcIDElm != null) {
- String sgcID = sgcIDElm.getText();
-
- if (sgcID != null) {
- if (log.isDebugEnabled()) {
- log.debug("Using the ServiceGroupId value "
- + sgcID + " to unbind session");
- }
- dispatcherContext.removeSession(sgcID);
- }
- } else if (log.isDebugEnabled()) {
- log.debug("Couldn't find the ServiceQroupId SOAP header to unbind the session");
- }
- }
+ public void unbind(MessageContext synCtx) {
+ SALSessions.getInstance().removeSession(extractSessionID(synCtx.getEnvelope().getHeader(),
+ QNAME_SERVICE_GROUP_ID));
}
/**
@@ -160,4 +95,8 @@
public boolean isServerInitiatedSession() {
return true;
}
+
+ public void removeSessionID(MessageContext syCtx) {
+ removeSessionID(syCtx.getEnvelope().getHeader(), QNAME_SERVICE_GROUP_ID);
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java Tue Oct 7 11:38:44 2008
@@ -23,6 +23,7 @@
import org.apache.synapse.Mediator;
import org.apache.synapse.MessageContext;
import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.axis2.context.ConfigurationContext;
import java.util.ArrayList;
import java.util.List;
@@ -123,4 +124,13 @@
}
}
}
+
+ public void init(ConfigurationContext cc) {
+
+ for (Mediator m : mediators) {
+ if (m instanceof AbstractMediator) {
+ ((AbstractMediator) m).init(cc);
+ }
+ }
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java Tue Oct 7 11:38:44 2008
@@ -28,6 +28,7 @@
import org.apache.synapse.audit.AuditConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.context.ConfigurationContext;
/**
* This is the superclass of all mediators, and defines common logging, tracing other aspects
@@ -256,4 +257,13 @@
public void setAuditId(String id) {
this.auditConfigurable.setAuditId(id);
}
+
+ /**
+ * Initialize mediator with configuration context.
+ * By default nothing to initiate and let it to decide each mediator itself
+ *
+ * @param cc ConfigurationContext instance
+ */
+ public void init(ConfigurationContext cc) {
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java Tue Oct 7 11:38:44 2008
@@ -73,5 +73,5 @@
* Return the list of mediators of this List mediator instance
* @return the child/sub mediator list
*/
- public List getList();
+ public List<Mediator> getList();
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CacheMediator.java Tue Oct 7 11:38:44 2008
@@ -481,4 +481,11 @@
public void setMaxMessageSize(int maxMessageSize) {
this.maxMessageSize = maxMessageSize;
}
+
+ public void init(ConfigurationContext cc) {
+
+ if (onCacheHitSequence != null) {
+ onCacheHitSequence.init(cc);
+ }
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java Tue Oct 7 11:38:44 2008
@@ -57,76 +57,6 @@
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
- if (synCtx.isResponse()) {
-
- Axis2MessageContext axis2MsgCtx = (Axis2MessageContext) synCtx;
- OperationContext opCtx = axis2MsgCtx.getAxis2MessageContext().getOperationContext();
-
- boolean isClusteringEnable = false;
-
- // get Axis2 MessageContext and ConfigurationContext
- org.apache.axis2.context.MessageContext axisMC =
- axis2MsgCtx.getAxis2MessageContext();
- ConfigurationContext cc = axisMC.getConfigurationContext();
-
- //The heck for clustering environment
-
- ClusterManager clusterManager = cc.getAxisConfiguration().getClusterManager();
- if (clusterManager != null &&
- clusterManager.getContextManager() != null) {
- isClusteringEnable = true;
- }
-
- if (isClusteringEnable) {
- // if this is a clustering env.
- // Only keeps endpoint names , because , it is heavy task to
- // replicate endpoint itself
- Object epNames = opCtx.getPropertyNonReplicable(SALoadbalanceEndpoint.ENDPOINT_NAME_LIST);
- if (epNames != null && epNames instanceof List) {
-
- List epNameList = (List) epNames;
- Object obj = epNameList.remove(0);
- if (obj != null && obj instanceof String) {
- Object rootEPObj = opCtx.getPropertyNonReplicable(
- SALoadbalanceEndpoint.ROOT_ENDPOINT);
-
- if (rootEPObj != null && rootEPObj instanceof Endpoint) {
- String name = ((Endpoint) rootEPObj).getName();
-
- if (name != null && name.equals(obj)) {
- Endpoint rootEP = ((Endpoint) rootEPObj);
-
- if (rootEP instanceof SALoadbalanceEndpoint) {
- SALoadbalanceEndpoint salEP = (SALoadbalanceEndpoint) rootEP;
- salEP.updateSession(synCtx, epNameList,
- isClusteringEnable);
- }
- }
- }
-
- }
- opCtx.setProperty(SALoadbalanceEndpoint.ENDPOINT_NAME_LIST, epNames);
- }
-
- } else {
- Object o = opCtx.getProperty(SALoadbalanceEndpoint.ENDPOINT_LIST);
- if (o != null && o instanceof List) {
- // we are in the response of the first message of a server initiated session
- // so update all session maps
- List epList = (List) o;
- Object e = epList.remove(0);
-
- if (e != null) {
- if (e instanceof SALoadbalanceEndpoint) {
- SALoadbalanceEndpoint salEP = (SALoadbalanceEndpoint) e;
- salEP.updateSession(synCtx, epList, isClusteringEnable);
- }
- }
- }
- }
-
- }
-
// if no endpoints are defined, send where implicitly stated
if (endpoint == null) {
@@ -162,4 +92,11 @@
public void setEndpoint(Endpoint endpoint) {
this.endpoint = endpoint;
}
+
+ public void init(ConfigurationContext cc) {
+
+ if (endpoint != null) {
+ endpoint.init(cc);
+ }
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/Aggregate.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/Aggregate.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/Aggregate.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/Aggregate.java Tue Oct 7 11:38:44 2008
@@ -21,6 +21,7 @@
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.mediators.eip.EIPConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -52,6 +53,7 @@
private List<MessageContext> messages = new ArrayList<MessageContext>();
private boolean locked = false;
private boolean completed = false;
+ private SynapseEnvironment synEnv = null;
/**
* Save aggregation properties and timeout
@@ -62,9 +64,10 @@
* @param max the maximum number of messages to be aggregated
* @param mediator
*/
- public Aggregate(String corelation, long timeoutMillis, int min,
+ public Aggregate(SynapseEnvironment synEnv, String corelation, long timeoutMillis, int min,
int max, AggregateMediator mediator) {
-
+
+ this.synEnv = synEnv;
this.correlation = corelation;
if (timeoutMillis > 0) {
expiryTimeMillis = System.currentTimeMillis() + timeoutMillis;
@@ -244,12 +247,23 @@
log.debug("Time : " + System.currentTimeMillis() + " and this aggregator " +
"expired at : " + expiryTimeMillis);
}
- aggregateMediator.completeAggregate(this);
+ synEnv.getExecutorService().execute(new AggregateTimeout(this));
break;
}
}
}
+ private class AggregateTimeout implements Runnable {
+ private Aggregate aggregate = null;
+ AggregateTimeout(Aggregate aggregate) {
+ this.aggregate = aggregate;
+ }
+
+ public void run() {
+ aggregateMediator.completeAggregate(aggregate);
+ }
+ }
+
public synchronized boolean getLock() {
return !locked;
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java Tue Oct 7 11:38:44 2008
@@ -32,6 +32,7 @@
import org.apache.synapse.mediators.eip.EIPConstants;
import org.apache.synapse.mediators.eip.EIPUtils;
import org.apache.synapse.util.xpath.SynapseXPath;
+import org.apache.axis2.context.ConfigurationContext;
import org.jaxen.JaxenException;
import java.util.Collections;
@@ -162,6 +163,7 @@
}
aggregate = new Aggregate(
+ synCtx.getEnvironment(),
correlateExpression.toString(),
completionTimeoutMillis,
minMessagesToComplete,
@@ -208,14 +210,19 @@
}
aggregate = new Aggregate(
+ synCtx.getEnvironment(),
correlation,
completionTimeoutMillis,
minMessagesToComplete,
maxMessagesToComplete, this);
if (completionTimeoutMillis > 0) {
- synCtx.getConfiguration().getSynapseTimer().
- schedule(aggregate, completionTimeoutMillis);
+ synchronized(aggregate) {
+ if (!aggregate.isCompleted()) {
+ synCtx.getConfiguration().getSynapseTimer().
+ schedule(aggregate, completionTimeoutMillis);
+ }
+ }
}
aggregate.getLock();
activeAggregates.put(correlation, aggregate);
@@ -292,16 +299,31 @@
* itself
* @param aggregate the timed out Aggregate that holds collected messages and properties
*/
- public synchronized void completeAggregate(Aggregate aggregate) {
+ public void completeAggregate(Aggregate aggregate) {
+
+ boolean markedCompletedNow = false;
+ boolean wasComplete = aggregate.isCompleted();
+ if (wasComplete) {
+ return;
+ }
if (log.isDebugEnabled()) {
log.debug("Aggregation completed or timed out");
}
// cancel the timer
- aggregate.cancel();
- aggregate.setCompleted(true);
+ synchronized(this) {
+ if (!aggregate.isCompleted()) {
+ aggregate.cancel();
+ aggregate.setCompleted(true);
+ markedCompletedNow = true;
+ }
+ }
+ if (!markedCompletedNow) {
+ return;
+ }
+
MessageContext newSynCtx = getAggregatedMessage(aggregate);
if (newSynCtx == null) {
log.warn("An aggregation of messages timed out with no aggregated messages", null);
@@ -430,4 +452,11 @@
public Map getActiveAggregates() {
return activeAggregates;
}
+
+ public void init(ConfigurationContext cc) {
+
+ if (onCompleteSequence != null) {
+ onCompleteSequence.init(cc);
+ }
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java Tue Oct 7 11:38:44 2008
@@ -21,6 +21,7 @@
import org.apache.synapse.MessageContext;
import org.apache.synapse.ManagedLifecycle;
+import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.util.MessageHelper;
@@ -31,6 +32,7 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.ConfigurationContext;
import java.util.ArrayList;
import java.util.List;
@@ -175,4 +177,21 @@
}
}
+ public void init(ConfigurationContext cc) {
+
+ for (Target target : targets) {
+
+ if (target != null) {
+
+ Endpoint endpoint = target.getEndpoint();
+ if (endpoint != null) {
+ endpoint.init(cc);
+ }
+ SequenceMediator seq = target.getSequence();
+ if (seq != null) {
+ seq.init(cc);
+ }
+ }
+ }
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java Tue Oct 7 11:38:44 2008
@@ -25,11 +25,14 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.ConfigurationContext;
import org.apache.synapse.ManagedLifecycle;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.synapse.mediators.eip.EIPConstants;
import org.apache.synapse.mediators.eip.EIPUtils;
import org.apache.synapse.mediators.eip.Target;
@@ -265,4 +268,18 @@
target.getSequence().destroy();
}
}
+
+ public void init(ConfigurationContext cc) {
+
+ if (target != null) {
+ Endpoint endpoint = target.getEndpoint();
+ if (endpoint != null) {
+ endpoint.init(cc);
+ }
+ SequenceMediator seq = target.getSequence();
+ if (seq != null) {
+ seq.init(cc);
+ }
+ }
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java Tue Oct 7 11:38:44 2008
@@ -72,12 +72,14 @@
traceOrDebug(traceOn, "invoking : " + mediator.getClass() + ".mediate()");
}
- boolean result = false;
+ boolean result;
try {
result = mediator.mediate(synCtx);
} catch (Exception e) {
- handleException(e.getMessage(), e, synCtx);
+ // throw Synapse Exception for any exception in class meditor
+ // so that the fault handler will be invoked
+ throw new SynapseException("Error occured in the mediation of the class mediator", e);
}
if (traceOrDebugOn) {
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java Tue Oct 7 11:38:44 2008
@@ -24,7 +24,6 @@
import org.apache.axiom.om.OMNode;
import org.apache.synapse.Command;
import org.apache.synapse.MessageContext;
-import org.apache.synapse.SynapseException;
import org.apache.synapse.mediators.AbstractMediator;
import org.apache.synapse.mediators.eip.EIPUtils;
import org.apache.synapse.util.xpath.SynapseXPath;
@@ -147,7 +146,8 @@
try {
((Command) commandObject).execute();
} catch (Exception e) {
- handleException(e.getMessage(), e, synCtx);
+ handleException("Error invoking POJO command class : "
+ + command.getClass(), e, synCtx);
}
} else {
@@ -160,7 +160,8 @@
handleException("Cannot locate an execute() method on POJO class : " +
command.getClass(), e, synCtx);
} catch (Exception e) {
- handleException(e.getMessage(), e, synCtx);
+ handleException("Error invoking the execute() method on POJO class : " +
+ command.getClass(), e, synCtx);
}
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java Tue Oct 7 11:38:44 2008
@@ -24,7 +24,9 @@
import org.apache.synapse.config.xml.SwitchCase;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.ListMediator;
import org.apache.synapse.util.xpath.SynapseXPath;
+import org.apache.axis2.context.ConfigurationContext;
import java.util.ArrayList;
import java.util.List;
@@ -189,4 +191,22 @@
public void setDefaultCase(SwitchCase defaultCase) {
this.defaultCase = defaultCase;
}
+
+ public void init(ConfigurationContext cc) {
+
+ for (SwitchCase aCase : cases) {
+ initCase(aCase, cc);
+ }
+ initCase(defaultCase, cc);
+ }
+
+ private void initCase(SwitchCase aCase, ConfigurationContext cc) {
+
+ if (aCase != null) {
+ ListMediator listMediator = aCase.getCaseMediator();
+ if (listMediator instanceof AbstractMediator) {
+ ((AbstractMediator) listMediator).init(cc);
+ }
+ }
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java Tue Oct 7 11:38:44 2008
@@ -54,8 +54,11 @@
return result;
}
- registry = JNDIBasedDataSourceRegistry.getInstance(null);
- return registry.lookUp(name);
+ registry = JNDIBasedDataSourceRegistry.getInstance();
+ if (registry.isInitialized()) {
+ return registry.lookUp(name);
+ }
+ return null;
}
/**
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java Tue Oct 7 11:38:44 2008
@@ -113,10 +113,14 @@
DataSourceRegistry dataSourceRegistry;
if (PROP_REGISTRY_JNDI.equals(registry)) {
+
if (jndiEvn == null) {
jndiEvn = createJNDIEnvironment(dsProperties, rootPrefix);
}
- dataSourceRegistry = JNDIBasedDataSourceRegistry.getInstance(jndiEvn);
+ dataSourceRegistry = JNDIBasedDataSourceRegistry.getInstance();
+ if (!dataSourceRegistry.isInitialized()) {
+ dataSourceRegistry.init(jndiEvn);
+ }
} else {
dataSourceRegistry = InMemoryDataSourceRegistry.getInstance();
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java Tue Oct 7 11:38:44 2008
@@ -19,6 +19,7 @@
package org.apache.synapse.util.datasource;
import javax.sql.DataSource;
+import java.util.Properties;
/**
* Keep all DataSources defined in the Synapse
@@ -26,6 +27,20 @@
public interface DataSourceRegistry {
/**
+ * Initialization with given properties
+ *
+ * @param properties configuration properties
+ */
+ public void init(Properties properties);
+
+ /**
+ * Explicitly check for init
+ *
+ * @return True , if has already initialized
+ */
+ public boolean isInitialized();
+
+ /**
* Register a DataSource based on given information
* Information is encapsulated in a DataSourceInformation instance
*
@@ -41,4 +56,9 @@
*/
DataSource lookUp(String name);
+ /**
+ * Clear already registered datasources
+ */
+ public void clear();
+
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java Tue Oct 7 11:38:44 2008
@@ -29,6 +29,7 @@
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
/**
* Keeps all DataSources in the memory
@@ -91,6 +92,21 @@
return dataSources.get(name);
}
+ public void init(Properties properties) {
+ // nothing
+ }
+
+ public boolean isInitialized() {
+ return true;
+ }
+
+ public void clear() {
+ if (!dataSources.isEmpty()) {
+ log.info("Clearing all in-memory datasources ");
+ dataSources.clear();
+ }
+ }
+
private static void handleException(String msg) {
log.error(msg);
throw new SynapseException(msg);
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java Tue Oct 7 11:38:44 2008
@@ -42,11 +42,15 @@
new JNDIBasedDataSourceRegistry();
private static InitialContext initialContext;
private static final Properties indiEnv = new Properties();
- private static boolean initialize = false;
+ private boolean initialized = false;
- public static JNDIBasedDataSourceRegistry getInstance(Properties jndiEnv) {
+ public static JNDIBasedDataSourceRegistry getInstance() {
+ return ourInstance;
+ }
- if (!initialize) {
+ public void init(Properties jndiEnv) {
+
+ if (!initialized) {
if (jndiEnv == null) {
handleException("JNDI environment properties cannot be found");
@@ -57,19 +61,18 @@
try {
if (log.isDebugEnabled()) {
- log.debug("Initilating a Naming conext with JNDI " +
+ log.debug("Initiating a Naming context with JNDI " +
"environment properties : " + jndiEnv);
}
initialContext = new InitialContext(jndiEnv);
- initialize = true;
+ initialized = true;
} catch (NamingException e) {
handleException("Error creating a InitialConext" +
" with JNDI env properties : " + jndiEnv);
}
}
- return ourInstance;
}
private JNDIBasedDataSourceRegistry() {
@@ -82,6 +85,8 @@
*/
public void register(DataSourceInformation information) {
+ validateInitialized();
+
String dsType = information.getType();
String driver = information.getDriver();
String url = information.getUrl();
@@ -211,12 +216,20 @@
*/
public DataSource lookUp(String dsName) {
+ validateInitialized();
+
if (log.isDebugEnabled()) {
log.debug("Getting a DataSource with name : " + dsName + " from the JNDI tree.");
}
return DataSourceFinder.find(dsName, initialContext);
}
+ public void clear() {
+ initialized = false;
+ initialContext = null;
+ indiEnv.clear();
+ }
+
/**
* Helper method to set all default parameter for naming reference of data source
*
@@ -356,4 +369,14 @@
log.error(msg, e);
throw new SynapseException(msg, e);
}
+
+ private void validateInitialized() {
+ if (!isInitialized()) {
+ handleException("Datasource registry has not been initialized yet");
+ }
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
}
Modified: synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java (original)
+++ synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java Tue Oct 7 11:38:44 2008
@@ -72,12 +72,12 @@
AddressEndpoint ep2 = (AddressEndpoint) send2.getEndpoint();
assertEquals("Address URI is not serialized properly",
- ep1.getEndpoint().getAddress(), ep2.getEndpoint().getAddress());
+ ep1.getDefinition().getAddress(), ep2.getDefinition().getAddress());
assertEquals(
"Addressing information is not serialized properly",
- ep1.getEndpoint().isAddressingOn(),
- ep2.getEndpoint().isAddressingOn());
+ ep1.getDefinition().isAddressingOn(),
+ ep2.getDefinition().isAddressingOn());
}
public void testWSDLEndpointSerialization() {
@@ -113,8 +113,8 @@
assertEquals(
"Addressing information is not serialized properly",
- ep1.getEndpoint().isAddressingOn(),
- ep2.getEndpoint().isAddressingOn());
+ ep1.getDefinition().isAddressingOn(),
+ ep2.getDefinition().isAddressingOn());
}
public void testSimpleLoadbalanceSendSerialization() {
@@ -151,7 +151,7 @@
send2.getEndpoint() instanceof LoadbalanceEndpoint);
LoadbalanceEndpoint endpoint = (LoadbalanceEndpoint) send2.getEndpoint();
- List addresses = endpoint.getEndpoints();
+ List addresses = endpoint.getChildren();
assertEquals("There should be 3 leaf level address endpoints", addresses.size(), 3);
assertTrue("Leaf level endpoints should be address endpoints",
@@ -163,7 +163,7 @@
AddressEndpoint addressEndpoint = (AddressEndpoint) addresses.get(0);
assertTrue("URI of address endpoint is not serialized properly",
- "http://localhost:9001/services/Service1".equals(addressEndpoint.getEndpoint().getAddress()));
+ "http://localhost:9001/services/Service1".equals(addressEndpoint.getDefinition().getAddress()));
}
public void testSimpleFailoverSendSerialization() {
@@ -200,7 +200,7 @@
send2.getEndpoint() instanceof FailoverEndpoint);
FailoverEndpoint endpoint = (FailoverEndpoint) send2.getEndpoint();
- List addresses = endpoint.getEndpoints();
+ List addresses = endpoint.getChildren();
assertEquals("There should be 3 leaf level address endpoints", addresses.size(), 3);
assertTrue("Leaf level endpoints should be address endpoints",
@@ -212,7 +212,7 @@
AddressEndpoint addressEndpoint = (AddressEndpoint) addresses.get(0);
assertTrue("URI of address endpoint is not serialized properly",
- "http://localhost:9001/services/Service1".equals(addressEndpoint.getEndpoint().getAddress()));
+ "http://localhost:9001/services/Service1".equals(addressEndpoint.getDefinition().getAddress()));
}
public void testNestedLoadbalanceFailoverSendSerialization() {
@@ -254,7 +254,7 @@
LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) send2.getEndpoint();
- List children = loadbalanceEndpoint.getEndpoints();
+ List children = loadbalanceEndpoint.getChildren();
assertEquals("Top level endpoint should have 2 child endpoints.", children.size(), 2);
assertTrue("First child should be a address endpoint",
@@ -264,7 +264,7 @@
children.get(1) instanceof FailoverEndpoint);
FailoverEndpoint failoverEndpoint = (FailoverEndpoint) children.get(1);
- List children2 = failoverEndpoint.getEndpoints();
+ List children2 = failoverEndpoint.getChildren();
assertEquals("Fail over endpoint should have 2 children.", children2.size(), 2);
assertTrue("Children of the fail over endpoint should be address endpoints.",
Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java?rev=702579&r1=702578&r2=702579&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java (original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/Axis2HttpRequest.java Tue Oct 7 11:38:44 2008
@@ -61,6 +61,8 @@
private EndpointReference epr = null;
/** the HttpHost that contains the HTTP connection information */
private HttpHost httpHost = null;
+ /** The [socket | connect] timeout */
+ private int timeout = -1;
/** the message context being sent */
private MessageContext msgContext = null;
/** The Axis2 MessageFormatter that will ensure proper serialization as per Axis2 semantics */
@@ -70,7 +72,12 @@
private ContentOutputBuffer outputBuffer = null;
/** ready to begin streaming? */
private boolean readyToStream = false;
- /** for request complete checking */
+ /** The sending of this request has fully completed */
+ private boolean sendingCompleted = false;
+ /**
+ * for request complete checking - request complete means the request has been fully sent
+ * and the response it fully received
+ */
private boolean completed = false;
public Axis2HttpRequest(EndpointReference epr, HttpHost httpHost, MessageContext msgContext) {
@@ -111,6 +118,14 @@
return msgContext;
}
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(int timeout) {
+ this.timeout = timeout;
+ }
+
/**
* Create and return a new HttpPost request to the destination EPR
* @return the HttpRequest to be sent out
@@ -257,10 +272,18 @@
"SessionRequestCallback handles this exception");
}
} else {
- if (e instanceof AxisFault) {
- throw (AxisFault) e;
+ Integer errorCode = msgContext == null ? null :
+ (Integer) msgContext.getProperty(NhttpConstants.ERROR_CODE);
+ if (errorCode == null || errorCode == NhttpConstants.SEND_ABORT) {
+ if (log.isDebugEnabled()) {
+ log.debug("Remote server aborted request being sent, and responded");
+ }
} else {
- handleException("Error streaming message context", e);
+ if (e instanceof AxisFault) {
+ throw (AxisFault) e;
+ } else {
+ handleException("Error streaming message context", e);
+ }
}
}
}
@@ -271,6 +294,7 @@
} catch (IOException e) {
handleException("Error closing outgoing message stream", e);
}
+ setSendingCompleted(true);
}
}
}
@@ -291,4 +315,12 @@
this.notifyAll();
}
}
+
+ public boolean isSendingCompleted() {
+ return sendingCompleted;
+ }
+
+ public void setSendingCompleted(boolean sendingCompleted) {
+ this.sendingCompleted = sendingCompleted;
+ }
}