hi,
The ListnerManager.defaultConfigurationContext is used as an easy way to
access the configuration context object within any place of the Axis2
container. But this would cause some security issues if we try to run
multiple Axis2 instances in a single JVM. (For an example using Axis2 in an
Multitenancy environment would cause problems with this).
ListnerManager.defaultConfigurationContext is used in two places.
1.
getMyEPR method of the service Context class
This method is only uses in isEquivalent method which does not have any
usage. So it is safe to delete both methods.
2.
At the ServiceClient class to get the server Configuration context
object.
if (ListenerManager.defaultConfigurationContext == null) {
configContext = ConfigurationContextFactory.
createConfigurationContextFromFileSystem(null, null);
ListenerManager.defaultConfigurationContext = configContext;
createConfigCtx = true;
} else {
configContext = ListenerManager.defaultConfigurationContext;
}
This code is to get a server configuration context if a user invokes a
service using service client at the skelton method. But here since
configuration context can be read from the message context it can be
replaced with this code.
if (MessageContext.getCurrentMessageContext() == null) {
configContext = ConfigurationContextFactory.
createConfigurationContextFromFileSystem(null, null);
createConfigCtx = true;
} else {
configContext =
MessageContext.getCurrentMessageContext().getConfigurationContext();
}
Here with I have attach a patch with do the fix.
WDYT?
Thanks,
Amila.
--
Amila Suriarachchi
WSO2 Inc.
blog: http://amilachinthaka.blogspot.com/
Index: kernel/src/org/apache/axis2/context/ServiceContext.java
===================================================================
--- kernel/src/org/apache/axis2/context/ServiceContext.java (revision
919952)
+++ kernel/src/org/apache/axis2/context/ServiceContext.java (working copy)
@@ -224,22 +224,6 @@
this.targetEPR = targetEPR;
}
- public EndpointReference getMyEPR() {
- if (myEPR == null) {
- try {
- if (ListenerManager.defaultConfigurationContext != null) {
- ListenerManager listenerManager =
-
ListenerManager.defaultConfigurationContext.getListenerManager();
- myEPR =
listenerManager.getEPRforService(axisService.getName(), null, null);
- }
- } catch (AxisFault axisFault) {
- // what else I can do
- myEPR = null;
- }
- }
- return myEPR;
- }
-
public void setMyEPR(EndpointReference myEPR) {
this.myEPR = myEPR;
}
@@ -598,64 +582,6 @@
/**
- * Compares key parts of the state from the current instance of
- * this class with the specified instance to see if they are
- * equivalent.
- * <p/>
- * This differs from the java.lang.Object.equals() method in
- * that the equals() method generally looks at both the
- * object identity (location in memory) and the object state
- * (data).
- * <p/>
- *
- * @param ctx
- * @return TRUE if this object is equivalent with the specified object
- * that is, key fields match
- * FALSE, otherwise
- */
- public boolean isEquivalent(ServiceContext ctx) {
- // NOTE: the input object is expected to exist (ie, be non-null)
-
- if (!this.axisService.equals(ctx.getAxisService())) {
- return false;
- }
-
-
- EndpointReference targetEPR2 = ctx.getTargetEPR();
-
- if ((this.targetEPR != null) && (targetEPR2 != null)) {
- if (!this.targetEPR.isEquivalent(targetEPR2)) {
- return false;
- }
- } else if ((this.targetEPR == null) && (targetEPR2 == null)) {
- // keep going
- } else {
- // one of the objects is null
- return false;
- }
-
- EndpointReference myEPR2 = ctx.getMyEPR();
-
- if ((this.myEPR != null) && (myEPR2 != null)) {
- if (!this.myEPR.isEquivalent(myEPR2)) {
- return false;
- }
- } else if ((this.myEPR == null) && (myEPR2 == null)) {
- // keep going
- } else {
- // one of the objects is null
- return false;
- }
-
- // TODO: consider checking the parent objects for equivalency
-
- // TODO: consider checking fields from the super class for equivalency
-
- return true;
- }
-
-
- /**
* Get the ID associated with this object instance.
*
* @return A string that can be output to a log file as an identifier
Index: kernel/src/org/apache/axis2/engine/ListenerManager.java
===================================================================
--- kernel/src/org/apache/axis2/engine/ListenerManager.java (revision
919952)
+++ kernel/src/org/apache/axis2/engine/ListenerManager.java (working copy)
@@ -38,14 +38,8 @@
private static final OnDemandLogger log = new
OnDemandLogger(ListenerManager.class);
- public static ConfigurationContext defaultConfigurationContext;
protected ListenerManagerShutdownThread shutdownHookThread = null;
- public static ListenerManager getDefaultListenerManager() {
- if (defaultConfigurationContext == null) return null;
- return defaultConfigurationContext.getListenerManager();
- }
-
private ConfigurationContext configctx;
private HashMap<String, TransportListener> startedTransports =
new HashMap<String, TransportListener>();
@@ -297,7 +291,6 @@
this.startedTransports.clear();
this.configctx = null;
- defaultConfigurationContext = null;
}
public boolean isShutdownHookRequired() {
Index: kernel/src/org/apache/axis2/client/ServiceClient.java
===================================================================
--- kernel/src/org/apache/axis2/client/ServiceClient.java (revision
919952)
+++ kernel/src/org/apache/axis2/client/ServiceClient.java (working copy)
@@ -147,13 +147,12 @@
private void configureServiceClient(ConfigurationContext configContext,
AxisService axisService)
throws AxisFault {
if (configContext == null) {
- if (ListenerManager.defaultConfigurationContext == null) {
+ if (MessageContext.getCurrentMessageContext() == null) {
configContext = ConfigurationContextFactory.
createConfigurationContextFromFileSystem(null, null);
- ListenerManager.defaultConfigurationContext = configContext;
createConfigCtx = true;
} else {
- configContext = ListenerManager.defaultConfigurationContext;
+ configContext =
MessageContext.getCurrentMessageContext().getConfigurationContext();
}
}
this.configContext = configContext;
Index: integration/test/org/apache/axis2/engine/OperationContextSaveTest.java
===================================================================
--- integration/test/org/apache/axis2/engine/OperationContextSaveTest.java
(revision 919952)
+++ integration/test/org/apache/axis2/engine/OperationContextSaveTest.java
(working copy)
@@ -329,12 +329,7 @@
assertTrue(comparesOk);
ServiceContext restored_srvCtx =
opctx_restored.getServiceContext();
- comparesOk = restored_srvCtx.isEquivalent(serviceContext);
- log.debug(
- "OperationContextSaveTest:testSaveAndRestore():
ServiceContext equivalency [" +
- comparesOk + "]");
- assertTrue(comparesOk);
-
+
ServiceGroupContext restored_sgCtx =
restored_srvCtx.getServiceGroupContext();
comparesOk = restored_sgCtx.isEquivalent(serviceGroupContext);
log.debug(
Index: transport/http/src/org/apache/axis2/transport/http/AxisServlet.java
===================================================================
--- transport/http/src/org/apache/axis2/transport/http/AxisServlet.java
(revision 919952)
+++ transport/http/src/org/apache/axis2/transport/http/AxisServlet.java
(working copy)
@@ -475,7 +475,6 @@
ListenerManager listenerManager = new ListenerManager();
listenerManager.init(configContext);
listenerManager.start();
- ListenerManager.defaultConfigurationContext = configContext;
agent = new ListingAgent(configContext);
initParams();
Index:
osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
===================================================================
---
osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
(revision 919952)
+++
osgi/src/org/apache/axis2/osgi/deployment/OSGiConfigurationContextFactory.java
(working copy)
@@ -94,7 +94,6 @@
ListenerManager listenerManager = new ListenerManager();
listenerManager.init(configCtx);
listenerManager.start();
- ListenerManager.defaultConfigurationContext = configCtx;
}
public void updated(Dictionary dictionary) throws ConfigurationException {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]