Author: ruchithf
Date: Thu Jul  6 06:47:25 2006
New Revision: 419551

URL: http://svn.apache.org/viewvc?rev=419551&view=rev
Log:
Added the MessageContext parameter to getClassLoader() method

Axis2 handlers will have to hold on to the RequestData  object as an attribute 
of the handler classes if they are to return the ServiceClass loader. This 
causes problems in multi threaded environments and simply breaks the stateless 
handler concept. Therefore we have to pass in the MessageContext object into 
the getClassloader() method to figure out the classloader.



Modified:
    webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSHandler.java

Modified: 
webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSHandler.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSHandler.java?rev=419551&r1=419550&r2=419551&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSHandler.java 
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/handler/WSHandler.java 
Thu Jul  6 06:47:25 2006
@@ -343,7 +343,8 @@
                                       reqData.getMsgContext());
         if (sigPropFile != null) {
             if ((crypto = (Crypto) cryptos.get(sigPropFile)) == null) {
-                crypto = CryptoFactory.getInstance(sigPropFile, 
this.getClassLoader());
+                crypto = CryptoFactory.getInstance(sigPropFile, this
+                        .getClassLoader(reqData.getMsgContext()));
                 cryptos.put(sigPropFile, crypto);
             }
         } else {
@@ -368,7 +369,8 @@
                                       reqData.getMsgContext());
         if (encPropFile != null) {
             if ((crypto = (Crypto) cryptos.get(encPropFile)) == null) {
-                crypto = CryptoFactory.getInstance(encPropFile, 
this.getClassLoader());
+                crypto = CryptoFactory.getInstance(encPropFile, this
+                        .getClassLoader(reqData.getMsgContext()));
                 cryptos.put(encPropFile, crypto);
             }
         } else if ((crypto = reqData.getSigCrypto()) == null) {
@@ -577,7 +579,7 @@
        Object mc = reqData.getMsgContext();
         String callback = getString(clsProp, mc);
         if (callback != null) { // we have a password callback class
-            pwCb = readPwViaCallbackClass(callback, username, doAction);
+            pwCb = readPwViaCallbackClass(callback, username, doAction, 
reqData);
             if ((pwCb.getPassword() == null) && (pwCb.getKey() == null)) {
             throw new WSSecurityException("WSHandler: password callback class "
                                          +err);
@@ -601,13 +603,15 @@
 
     private WSPasswordCallback readPwViaCallbackClass(String callback,
                                                       String username,
-                                                      int doAction)
+                                                      int doAction,
+                                                      RequestData requestData)
             throws WSSecurityException {
 
         Class cbClass = null;
         CallbackHandler cbHandler = null;
         try {
-            cbClass = Loader.loadClass(getClassLoader(), callback);
+            cbClass = Loader.loadClass(getClassLoader(requestData
+                    .getMsgContext()), callback);
         } catch (ClassNotFoundException e) {
             throw new WSSecurityException("WSHandler: cannot load password 
callback class: "
                     + callback,
@@ -764,7 +768,8 @@
                                     reqData.getMsgContext());
         if (decPropFile != null) {
             if ((crypto = (Crypto) cryptos.get(decPropFile)) == null) {
-                crypto = CryptoFactory.getInstance(decPropFile, 
this.getClassLoader());
+                crypto = CryptoFactory.getInstance(decPropFile, this
+                        .getClassLoader(reqData.getMsgContext()));
                 cryptos.put(decPropFile, crypto);
             }
         } else if ((crypto = reqData.getSigCrypto()) == null) {
@@ -812,7 +817,8 @@
         if (callback != null) {
             Class cbClass = null;
             try {
-                cbClass = Loader.loadClass(getClassLoader(), callback);
+                cbClass = Loader.loadClass(getClassLoader(reqData
+                        .getMsgContext()), callback);
             } catch (ClassNotFoundException e) {
                 throw new WSSecurityException(
                        "WSHandler: cannot load password callback class: "
@@ -1070,18 +1076,31 @@
        }
     }
 
-       /**
-        * Returns the classloader to be used for loading the callback class
-        * 
-        * @return class loader
-        */
-       public ClassLoader getClassLoader() {
-               try {
-                       return Loader.getTCL();
-               } catch (Throwable t) {
-                       return null;
-               }
-       }
+//     /**
+//      * Returns the classloader to be used for loading the callback class
+//      * 
+//      * @return class loader
+//      */
+//     public ClassLoader getClassLoader() {
+//             try {
+//                     return Loader.getTCL();
+//             } catch (Throwable t) {
+//                     return null;
+//             }
+//     }
+    
+    /**
+     * Returns the classloader to be used for loading the callback class
+     * @param msgCtx The MessageContext 
+     * @return class loader
+     */
+    public ClassLoader getClassLoader(Object msgCtx) {
+        try {
+            return Loader.getTCL();
+        } catch (Throwable t) {
+            return null;
+        }
+    }
        
     public abstract Object getOption(String key);
     public abstract Object getProperty(Object msgContext, String key);



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to