You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by ml...@apache.org on 2007/05/22 14:23:46 UTC
svn commit: r540557 - in /webservices/sandesha/trunk/java: ./
modules/core/src/main/java/org/apache/sandesha2/
modules/core/src/main/java/org/apache/sandesha2/context/
modules/core/src/main/java/org/apache/sandesha2/i18n/
modules/core/src/main/java/org...
Author: mlovett
Date: Tue May 22 05:23:45 2007
New Revision: 540557
URL: http://svn.apache.org/viewvc?view=rev&rev=540557
Log:
Create a plug point to allow application context to be moved onto the InvokerWorker threads.
Added:
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/ContextManager.java (with props)
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/DummyContextManager.java (with props)
webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/scenarios/UnitTestContextManager.java (with props)
Modified:
webservices/sandesha/trunk/java/maven.xml
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/Sandesha2Constants.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/i18n/SandeshaMessageKeys.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/SequenceProcessor.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/SandeshaPolicyBean.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/builders/RMAssertionBuilder.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/storage/beans/InvokerBean.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SandeshaUtil.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/Invoker.java
webservices/sandesha/trunk/java/modules/core/src/main/resources/org/apache/sandesha2/i18n/resource.properties
webservices/sandesha/trunk/java/modules/mar/module.xml
Modified: webservices/sandesha/trunk/java/maven.xml
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/maven.xml?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/maven.xml (original)
+++ webservices/sandesha/trunk/java/maven.xml Tue May 22 05:23:45 2007
@@ -277,11 +277,14 @@
</fileset>
</copy>
- <!-- Switch on serialization in the module.xml file -->
+ <!-- Switch on serialization in the module.xml file, and use the unit test context plugin -->
<ant:unjar src="${maven.build.dir}/${mar.name}" dest="${serialize.temp.path}"/>
<ant:replace file="${serialize.temp.path}/META-INF/module.xml"
token="<!-- <sandesha2:UseMessageSerialization>true</sandesha2:UseMessageSerialization> -->"
value="<sandesha2:UseMessageSerialization>true</sandesha2:UseMessageSerialization>"/>
+ <ant:replace file="${serialize.temp.path}/META-INF/module.xml"
+ token="context.DummyContextManager"
+ value="scenarios.UnitTestContextManager"/>
<ant:jar jarfile="${serialize.client.path}/modules/${test.module.name}.mar" basedir="${serialize.temp.path}"/>
<ant:jar jarfile="${serialize.server.path}/modules/${test.module.name}.mar" basedir="${serialize.temp.path}"/>
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/Sandesha2Constants.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/Sandesha2Constants.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/Sandesha2Constants.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/Sandesha2Constants.java Tue May 22 05:23:45 2007
@@ -419,6 +419,8 @@
public static final String SecurityManager = "SecurityManager";
+ public static final String ContextManager = "ContextManager";
+
public static final String EnableMakeConnection = "EnableMakeConnection";
public static final String EnableRMAnonURI = "EnableRMAnonURI";
@@ -457,6 +459,8 @@
public static final String SecurityManager = "org.apache.sandesha2.security.dummy.DummySecurityManager";
+ public static final String ContextManager = "org.apache.sandesha2.context.DummyContextManager";
+
public static final boolean EnableMakeConnection = true;
public static final boolean EnableRMAnonURI = true;
@@ -539,6 +543,8 @@
static final String SECURITY_MANAGER = "Sandesha2SecurityManager";
+ static final String CONTEXT_MANAGER = "Sandesha2ContextManager";
+
static final String RETRANSMITTABLE_PHASES = "RMRetransmittablePhases";
static final String propertiesToCopyFromReferenceMessage = "propertiesToCopyFromReferenceMessage";
@@ -597,6 +603,7 @@
public static final String ELEM_MSG_TYPES_TO_DROP = "MessageTypesToDrop";
public static final String ELEM_STORAGE_MGR = "StorageManagers";
public static final String ELEM_SEC_MGR = "SecurityManager";
+ public static final String ELEM_CONTEXT_MGR = "ContextManager";
public static final String ELEM_INMEMORY_STORAGE_MGR = "InMemoryStorageManager";
public static final String ELEM_PERMANENT_STORAGE_MGR = "PermanentStorageManager";
public static final String ELEM_MAKE_CONNECTION = "MakeConnection";
@@ -620,6 +627,7 @@
public static final QName Q_ELEM_MSG_TYPES_TO_DROP = new QName(URI_RM_POLICY_NS, ELEM_MSG_TYPES_TO_DROP, ATTR_WSRM);
public static final QName Q_ELEM_STORAGE_MGR =new QName(URI_RM_POLICY_NS, ELEM_STORAGE_MGR, ATTR_WSRM);
public static final QName Q_ELEM_SEC_MGR = new QName(URI_RM_POLICY_NS, ELEM_SEC_MGR, ATTR_WSRM);
+ public static final QName Q_ELEM_CONTEXT_MGR = new QName(URI_RM_POLICY_NS, ELEM_CONTEXT_MGR, ATTR_WSRM);
public static final QName Q_ELEM_INMEMORY_STORAGE_MGR =new QName(URI_RM_POLICY_NS, ELEM_INMEMORY_STORAGE_MGR, ATTR_WSRM);
public static final QName Q_ELEM_PERMANENT_STORAGE_MGR =new QName(URI_RM_POLICY_NS, ELEM_PERMANENT_STORAGE_MGR, ATTR_WSRM);
public static final QName Q_ELEM_MAKE_CONNECTION = new QName(URI_RM_POLICY_NS, ELEM_MAKE_CONNECTION, ATTR_WSRM);
Added: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/ContextManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/ContextManager.java?view=auto&rev=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/ContextManager.java (added)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/ContextManager.java Tue May 22 05:23:45 2007
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * Copyright 2007 International Business Machines Corp.
+ *
+ * Licensed 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.sandesha2.context;
+
+import java.io.Serializable;
+
+/**
+ * This interface allows the context surrounding an invocation to be saved and
+ * restored. This is useful when we are doing inOrder processing, as the service
+ * will be dispatched by the InvokerWorker (not the original transport thread),
+ * and context may have been lost by that switch.
+ *
+ * Each ContextManager implementation should have a constructor that takes a
+ * Axis ConfigurationContext object.
+ */
+
+public interface ContextManager {
+
+ /**
+ * Store the current threads execution context. When embedded in an appserver,
+ * this provides a hook point to store classloaders, security context, JNDI, etc.
+ */
+ public Serializable storeContext();
+
+ /**
+ * Wrap the provided runnable with execution context that was previously stored.
+ * We expect the resulting runnable to be dispatched by a thread pool or other
+ * worker, and the wrapper ensures that the correct execution context will be
+ * applied.
+ */
+ public Runnable wrapWithContext(Runnable work, Serializable context);
+
+}
Propchange: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/ContextManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/DummyContextManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/DummyContextManager.java?view=auto&rev=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/DummyContextManager.java (added)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/DummyContextManager.java Tue May 22 05:23:45 2007
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * Copyright 2007 International Business Machines Corp.
+ *
+ * Licensed 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.sandesha2.context;
+
+import java.io.Serializable;
+
+import org.apache.axis2.context.ConfigurationContext;
+
+public class DummyContextManager implements ContextManager {
+
+ public DummyContextManager(ConfigurationContext context) {
+
+ }
+
+ public Serializable storeContext() {
+ return null;
+ }
+
+ public Runnable wrapWithContext(Runnable work, Serializable context) {
+ return work;
+ }
+
+}
Propchange: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/context/DummyContextManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/i18n/SandeshaMessageKeys.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/i18n/SandeshaMessageKeys.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/i18n/SandeshaMessageKeys.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/i18n/SandeshaMessageKeys.java Tue May 22 05:23:45 2007
@@ -28,6 +28,8 @@
public static final String storageManagerMustImplement="storageManagerMustImplement";
public static final String cannotInitSecurityManager="cannotInitSecurityManager";
public static final String securityManagerMustImplement="securityManagerMustImplement";
+ public static final String cannotInitContextManager="cannotInitContextManager";
+ public static final String contextManagerMustImplement="contextManagerMustImplement";
public static final String cannotFindModulePolicies="cannotFindModulePolicies";
public static final String cannotPauseThread = "cannotPauseThread";
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/SequenceProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/SequenceProcessor.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/SequenceProcessor.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/SequenceProcessor.java Tue May 22 05:23:45 2007
@@ -35,6 +35,7 @@
import org.apache.sandesha2.RMMsgContext;
import org.apache.sandesha2.Sandesha2Constants;
import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.context.ContextManager;
import org.apache.sandesha2.i18n.SandeshaMessageHelper;
import org.apache.sandesha2.i18n.SandeshaMessageKeys;
import org.apache.sandesha2.msgreceivers.RMMessageReceiver;
@@ -362,7 +363,12 @@
InvokerBeanMgr storageMapMgr = storageManager.getInvokerBeanMgr();
storageManager.storeMessageContext(key, rmMsgCtx.getMessageContext());
- storageMapMgr.insert(new InvokerBean(key, msgNo, sequenceId));
+ InvokerBean invokerBean = new InvokerBean(key, msgNo, sequenceId);
+
+ ContextManager contextMgr = SandeshaUtil.getContextManager(configCtx);
+ if(contextMgr != null) invokerBean.setContext(contextMgr.storeContext());
+
+ storageMapMgr.insert(invokerBean);
// This will avoid performing application processing more than once.
rmMsgCtx.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE, "true");
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/SandeshaPolicyBean.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/SandeshaPolicyBean.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/SandeshaPolicyBean.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/SandeshaPolicyBean.java Tue May 22 05:23:45 2007
@@ -51,6 +51,8 @@
private String permanentStorageManagerClass = null;
private String securityManagerClass = null;
+
+ private String contextManagerClass = null;
private long inactiveTimeoutValue;
private boolean inactiveTimeoutValueSet = false;
@@ -203,7 +205,15 @@
public void setSecurityManagerClass(String className) {
this.securityManagerClass = className;
}
+
+ public String getContextManagerClass() {
+ return contextManagerClass;
+ }
+ public void setContextManagerClass(String className) {
+ this.contextManagerClass = className;
+ }
+
public QName getName() {
return Sandesha2Constants.Assertions.Q_ELEM__RMBEAN;
}
@@ -320,6 +330,11 @@
writer.writeCharacters(getSecurityManagerClass());
writer.writeEndElement();
+ //<wsrm:ContextManager />
+ writer.writeStartElement(prefix, Sandesha2Constants.Assertions.Q_ELEM_CONTEXT_MGR.getLocalPart(), namespaceURI);
+ writer.writeCharacters(getContextManagerClass());
+ writer.writeEndElement();
+
// <wsrm:MakeConnection>
writer.writeStartElement(prefix, Sandesha2Constants.Assertions.Q_ELEM_MAKE_CONNECTION.getLocalPart(), namespaceURI);
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/builders/RMAssertionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/builders/RMAssertionBuilder.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/builders/RMAssertionBuilder.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/policy/builders/RMAssertionBuilder.java Tue May 22 05:23:45 2007
@@ -143,6 +143,10 @@
}
}
+
+ } else if (Sandesha2Constants.Assertions.ELEM_CONTEXT_MGR.equals(name)) {
+ propertyBean.setContextManagerClass (element.getText().trim());
+
} else if(Sandesha2Constants.Assertions.ELEM_MAKE_CONNECTION.equals(name)) {
if (element!=null) {
// Read the nested assertions
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/storage/beans/InvokerBean.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/storage/beans/InvokerBean.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/storage/beans/InvokerBean.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/storage/beans/InvokerBean.java Tue May 22 05:23:45 2007
@@ -17,6 +17,8 @@
package org.apache.sandesha2.storage.beans;
+import java.io.Serializable;
+
/**
* This bean is used at the receiving side (of both server and client)
* There is one object for each application message to be invoked.
@@ -40,6 +42,12 @@
private String sequenceID;
/**
+ * The runtime context that needs to be applied to the invoker thread before
+ * the message is run through the invoker.
+ */
+ private Serializable context;
+
+ /**
* Comment for <code>msgNo</code>
* The message number of the message.
*/
@@ -107,6 +115,14 @@
*/
public void setSequenceID(String sequenceId) {
this.sequenceID = sequenceId;
+ }
+
+ public Serializable getContext() {
+ return context;
+ }
+
+ public void setContext(Serializable context) {
+ this.context = context;
}
public String toString() {
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java Tue May 22 05:23:45 2007
@@ -66,7 +66,7 @@
loadMessageTypesToDrop(msgTypesToDrop, propertyBean);
propertyBean.setSecurityManagerClass(Sandesha2Constants.Properties.DefaultValues.SecurityManager);
-
+ propertyBean.setContextManagerClass(Sandesha2Constants.Properties.DefaultValues.ContextManager);
propertyBean.setEnableMakeConnection(Sandesha2Constants.Properties.DefaultValues.EnableMakeConnection);
propertyBean.setEnableRMAnonURI(Sandesha2Constants.Properties.DefaultValues.EnableRMAnonURI);
propertyBean.setUseMessageSerialization(Sandesha2Constants.Properties.DefaultValues.UseMessageSerialization);
@@ -134,6 +134,10 @@
String securityManagerClassStr = properties
.getProperty(Sandesha2Constants.Properties.SecurityManager);
loadSecurityManagerClass(securityManagerClassStr,propertyBean);
+
+ String contextManagerClassStr = properties.getProperty(Sandesha2Constants.Properties.ContextManager);
+ loadContextManagerClass(contextManagerClassStr,propertyBean);
+
} catch (IOException e) {
throw new SandeshaException(e);
}
@@ -504,6 +508,13 @@
if (securityManagerClassStr != null) {
securityManagerClassStr = securityManagerClassStr.trim();
propertyBean.setSecurityManagerClass(securityManagerClassStr);
+ }
+ }
+
+ private static void loadContextManagerClass(String contextManagerClassStr, SandeshaPolicyBean propertyBean) {
+ if (contextManagerClassStr != null) {
+ contextManagerClassStr = contextManagerClassStr.trim();
+ propertyBean.setContextManagerClass(contextManagerClassStr);
}
}
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SandeshaUtil.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SandeshaUtil.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SandeshaUtil.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SandeshaUtil.java Tue May 22 05:23:45 2007
@@ -65,6 +65,7 @@
import org.apache.sandesha2.Sandesha2Constants;
import org.apache.sandesha2.SandeshaException;
import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.context.ContextManager;
import org.apache.sandesha2.i18n.SandeshaMessageHelper;
import org.apache.sandesha2.i18n.SandeshaMessageKeys;
import org.apache.sandesha2.policy.SandeshaPolicyBean;
@@ -764,6 +765,54 @@
}
}
+ public static ContextManager getContextManager(ConfigurationContext context) throws SandeshaException {
+ ContextManager mgr = null;
+ AxisConfiguration config = context.getAxisConfiguration();
+ Parameter p = config.getParameter(Sandesha2Constants.CONTEXT_MANAGER);
+ if(p != null) mgr = (ContextManager) p.getValue();
+ if (mgr != null) return mgr;
+
+ try {
+ //Currently module policies are used to find the context impl. These cant be overriden
+ String securityManagerClassStr = getDefaultPropertyBean(context.getAxisConfiguration()).getContextManagerClass();
+ mgr = getContextManagerInstance(securityManagerClassStr,context);
+ p = new Parameter(Sandesha2Constants.CONTEXT_MANAGER,mgr);
+ config.addParameter(p);
+ } catch(AxisFault e) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotInitContextManager, e.toString());
+ throw new SandeshaException(message,e);
+ }
+ return mgr;
+ }
+
+ private static ContextManager getContextManagerInstance(String className,ConfigurationContext context) throws SandeshaException {
+ try {
+ ClassLoader classLoader = null;
+ AxisConfiguration config = context.getAxisConfiguration();
+ Parameter classLoaderParam = config.getParameter(Sandesha2Constants.MODULE_CLASS_LOADER);
+ if(classLoaderParam != null) classLoader = (ClassLoader) classLoaderParam.getValue();
+
+ if (classLoader==null)
+ throw new SandeshaException (SandeshaMessageHelper.getMessage(SandeshaMessageKeys.classLoaderNotFound));
+
+ Class c = classLoader.loadClass(className);
+ Class configContextClass = context.getClass();
+
+ Constructor constructor = c.getConstructor(new Class[] { configContextClass });
+ Object obj = constructor.newInstance(new Object[] {context});
+
+ if (!(obj instanceof ContextManager)) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.contextManagerMustImplement, className);
+ throw new SandeshaException(message);
+ }
+ return (ContextManager) obj;
+
+ } catch (Exception e) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotInitContextManager, e.toString());
+ throw new SandeshaException(message,e);
+ }
+ }
+
public static boolean isWSRMAnonymous(String address) {
if (address!=null && address.startsWith(Sandesha2Constants.SPEC_2007_02.ANONYMOUS_URI_PREFIX))
return true;
Modified: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/Invoker.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/Invoker.java?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/Invoker.java (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/workers/Invoker.java Tue May 22 05:23:45 2007
@@ -26,6 +26,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.sandesha2.Sandesha2Constants;
import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.context.ContextManager;
import org.apache.sandesha2.i18n.SandeshaMessageHelper;
import org.apache.sandesha2.i18n.SandeshaMessageKeys;
import org.apache.sandesha2.storage.StorageManager;
@@ -112,9 +113,14 @@
worker.setLock(getWorkerLock());
worker.setWorkId(workId);
- //before we execute we need to set the
+ // Wrap the invoker worker with the correct context, if needed.
+ Runnable work = worker;
+ ContextManager contextMgr = SandeshaUtil.getContextManager(context);
+ if(contextMgr != null) {
+ work = contextMgr.wrapWithContext(work, invoker.getContext());
+ }
- threadPool.execute(worker);
+ threadPool.execute(work);
//adding the workId to the lock after assigning it to a thread makes sure
//that all the workIds in the Lock are handled by threads.
@@ -319,7 +325,13 @@
worker.setLock(getWorkerLock());
worker.setWorkId(workId);
- threadPool.execute(worker);
+ // Wrap the invoker worker with the correct context, if needed.
+ Runnable work = worker;
+ ContextManager contextMgr = SandeshaUtil.getContextManager(context);
+ if(contextMgr != null) {
+ work = contextMgr.wrapWithContext(work, bean.getContext());
+ }
+ threadPool.execute(work);
//adding the workId to the lock after assigning it to a thread makes sure
//that all the workIds in the Lock are handled by threads.
Modified: webservices/sandesha/trunk/java/modules/core/src/main/resources/org/apache/sandesha2/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/resources/org/apache/sandesha2/i18n/resource.properties?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/resources/org/apache/sandesha2/i18n/resource.properties (original)
+++ webservices/sandesha/trunk/java/modules/core/src/main/resources/org/apache/sandesha2/i18n/resource.properties Tue May 22 05:23:45 2007
@@ -28,6 +28,8 @@
storageManagerMustImplement=StorageManager {0} must implement the org.apache.sandesha2.storage.StorageManager interface.
cannotInitSecurityManager=Cannot initialize the given security manager due to exception {0}.
securityManagerMustImplement=SecurityManager {0} must implement the org.apache.sandesha2.storage.StorageManager interface.
+cannotInitContextManager=Cannot initialize the given context manager due to exception {0}.
+contextManagerMustImplement=ContextManager {0} must implement the org.apache.sandesha2.context.ContextManager interface.
cannotFindModulePolicies=No policies were found in the module.xml at the module initiation time.
cannotPauseThread=Cannot pause a non-running thread.
Modified: webservices/sandesha/trunk/java/modules/mar/module.xml
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/mar/module.xml?view=diff&rev=540557&r1=540556&r2=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/mar/module.xml (original)
+++ webservices/sandesha/trunk/java/modules/mar/module.xml Tue May 22 05:23:45 2007
@@ -125,6 +125,7 @@
<!-- This will not be overriden by service level policies -->
<sandesha2:SecurityManager>org.apache.sandesha2.security.dummy.DummySecurityManager</sandesha2:SecurityManager>
+ <sandesha2:ContextManager>org.apache.sandesha2.context.DummyContextManager</sandesha2:ContextManager>
<sandesha2:MakeConnection>
<sandesha2:Enabled>true</sandesha2:Enabled>
Added: webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/scenarios/UnitTestContextManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/scenarios/UnitTestContextManager.java?view=auto&rev=540557
==============================================================================
--- webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/scenarios/UnitTestContextManager.java (added)
+++ webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/scenarios/UnitTestContextManager.java Tue May 22 05:23:45 2007
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ * Copyright 2007 International Business Machines Corp.
+ *
+ * Licensed 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.sandesha2.scenarios;
+
+import java.io.Serializable;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.sandesha2.context.ContextManager;
+
+public class UnitTestContextManager implements ContextManager {
+
+ private static final String id = "UNIT_TEST_CONTEXT";
+
+ public UnitTestContextManager(ConfigurationContext context) {
+
+ }
+
+ public Serializable storeContext() {
+ return id;
+ }
+
+ public Runnable wrapWithContext(final Runnable work,
+ final Serializable context) {
+
+ Runnable result = new Runnable() {
+ public void run() {
+ if(!id.equals(context)) throw new RuntimeException("Unexpected context " + context);
+ System.out.println("Switching to " + context);
+ work.run();
+ }
+ };
+
+ return result;
+ }
+
+}
Propchange: webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/scenarios/UnitTestContextManager.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org