You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Peter Royal <pr...@managingpartners.com> on 2002/04/17 19:50:48 UTC

[patch][altrmi] ClassCastException in lookup()

I'm using the AltrmiAuthentication to authenticate users against the altrmi 
server. If an ExceptionReply was returned as part of the lookup, a 
ClassCastException would occur. I have modified lookup() to check the object 
type of the AltrmiReply to see if it is an ExceptionReply (which would occur 
if authorization failed), which is the cause of the CCE.

I also noticed that lookup() was the same between both the ClientClass and 
ServerClass factories so I moved the lookup() implementation into their 
abstract superclass. 

I'm using instanceOf to check the reply type, rather than checking the code 
since the existing code did that for problem replies.
-pete

-- 
peter royal -> proyal@managingpartners.com

Re: [patch][altrmi] ClassCastException in lookup()

Posted by Peter Royal <pr...@managingpartners.com>.
On Wednesday 17 April 2002 06:19 pm, Paul Hammant wrote:
> Cheers dude, we have never tested that or used it :-))

Works great :)

> Are you not a committer yet?

That's why I'm sending patches ;)
-pete

-- 
peter royal -> proyal@managingpartners.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [patch][altrmi] ClassCastException in lookup()

Posted by Paul Hammant <Pa...@yahoo.com>.
Peter,

Cheers dude, we have never tested that or used it :-))
I'll apply your changes ....

Using instanceof is fine and we are only trying to make 'normal' nethod 
calls fast.  Exceptions are rarer, so need no speed.

Are you not a committer yet?

- Paul

>I'm using the AltrmiAuthentication to authenticate users against the altrmi 
>server. If an ExceptionReply was returned as part of the lookup, a 
>ClassCastException would occur. I have modified lookup() to check the object 
>type of the AltrmiReply to see if it is an ExceptionReply (which would occur 
>if authorization failed), which is the cause of the CCE.
>
>I also noticed that lookup() was the same between both the ClientClass and 
>ServerClass factories so I moved the lookup() implementation into their 
>abstract superclass. 
>
>I'm using instanceOf to check the reply type, rather than checking the code 
>since the existing code did that for problem replies.
>-pete
>
>
>------------------------------------------------------------------------
>
>? docs
>Index: src/java/org/apache/excalibur/altrmi/client/impl/AbstractAltrmiFactory.java
>===================================================================
>RCS file: /home/cvspublic/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/AbstractAltrmiFactory.java,v
>retrieving revision 1.2
>diff -u -r1.2 AbstractAltrmiFactory.java
>--- src/java/org/apache/excalibur/altrmi/client/impl/AbstractAltrmiFactory.java	10 Apr 2002 23:36:58 -0000	1.2
>+++ src/java/org/apache/excalibur/altrmi/client/impl/AbstractAltrmiFactory.java	17 Apr 2002 17:45:27 -0000
>@@ -10,23 +10,24 @@
> 
> 
> 
>+import java.io.IOException;
>+import java.lang.ref.WeakReference;
>+import java.util.HashMap;
>+
> import org.apache.excalibur.altrmi.client.AltrmiFactory;
> import org.apache.excalibur.altrmi.client.AltrmiHostContext;
> import org.apache.excalibur.altrmi.client.AltrmiProxy;
>+import org.apache.excalibur.altrmi.common.AltrmiAuthentication;
> import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
> import org.apache.excalibur.altrmi.common.AltrmiReply;
>+import org.apache.excalibur.altrmi.common.ExceptionReply;
>+import org.apache.excalibur.altrmi.common.ListReply;
>+import org.apache.excalibur.altrmi.common.ListRequest;
>+import org.apache.excalibur.altrmi.common.LookupReply;
> import org.apache.excalibur.altrmi.common.LookupRequest;
>-import org.apache.excalibur.altrmi.common.OpenConnectionRequest;
>-import org.apache.excalibur.altrmi.common.AltrmiInvocationException;
>+import org.apache.excalibur.altrmi.common.NotPublishedReply;
> import org.apache.excalibur.altrmi.common.OpenConnectionReply;
>-import org.apache.excalibur.altrmi.common.ListRequest;
>-import org.apache.excalibur.altrmi.common.ListReply;
>-
>-import java.util.HashMap;
>-import java.util.Vector;
>-
>-import java.io.IOException;
>-import java.lang.ref.WeakReference;
>+import org.apache.excalibur.altrmi.common.OpenConnectionRequest;
> 
> 
> /**
>@@ -34,6 +35,7 @@
>  *
>  *
>  * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
>+ * @author Peter Royal <a href="mailto:proyal@managingpartners.com">proyal@managingpartners.com</a>
>  * @version $Revision: 1.2 $
>  */
> public abstract class AbstractAltrmiFactory implements AltrmiFactory {
>@@ -95,6 +97,66 @@
> 
>             //TODO
>         }
>+    }
>+
>+    /**
>+     * Method lookup
>+     *
>+     *
>+     * @param publishedServiceName
>+     * @param altrmiAuthentication
>+     *
>+     * @return
>+     *
>+     * @throws AltrmiConnectionException
>+     *
>+     */
>+    public Object lookup(String publishedServiceName, AltrmiAuthentication altrmiAuthentication)
>+            throws AltrmiConnectionException {
>+
>+        AltrmiReply ar =
>+            mHostContext.getInvocationHandler()
>+                .handleInvocation(new LookupRequest(publishedServiceName, altrmiAuthentication, mSession));
>+
>+        if (ar.getReplyCode() >= AltrmiReply.PROBLEMREPLY) {
>+            if (ar instanceof NotPublishedReply) {
>+                throw new AltrmiConnectionException("Service " + publishedServiceName
>+                                                    + " not published");
>+            } else if (ar instanceof ExceptionReply) {
>+                ExceptionReply er = (ExceptionReply) ar;
>+
>+                throw (AltrmiConnectionException) er.getReplyException();
>+            } else {
>+                throw new AltrmiConnectionException("Problem doing lookup on service");
>+            }
>+        } else if (ar instanceof ExceptionReply) {
>+            ExceptionReply er = (ExceptionReply) ar;
>+            Throwable t = er.getReplyException();
>+
>+            if (t instanceof AltrmiConnectionException) {
>+                throw (AltrmiConnectionException) t;
>+            } else if (t instanceof Error) {
>+                throw (Error) t;
>+            } else if (t instanceof RuntimeException) {
>+                throw (RuntimeException) t;
>+            } else {
>+                throw new AltrmiConnectionException("Problem doing lookup on service [exception: "
>+                                                    + t.getMessage() + "]");
>+            }
>+        } else if (!(ar instanceof LookupReply)) {
>+            throw new UnsupportedOperationException("Unexpected reply to lookup [reply: " + ar + "]");
>+        }
>+
>+        LookupReply lr = (LookupReply) ar;
>+        DefaultProxyHelper baseObj = new DefaultProxyHelper(this,
>+                                                        mHostContext.getInvocationHandler(),
>+                                                        publishedServiceName, "Main",
>+                                                        lr.getReferenceID(), mSession);
>+        Object retVal = getInstance(publishedServiceName, "Main", baseObj, isBeanOnly());
>+
>+        baseObj.registerImplObject(retVal);
>+
>+        return retVal;
>     }
> 
>     protected abstract Class getFacadeClass(String publishedServiceName, String objectName, boolean beanOnly) throws AltrmiConnectionException, ClassNotFoundException;
>Index: src/java/org/apache/excalibur/altrmi/client/impl/ClientClassAltrmiFactory.java
>===================================================================
>RCS file: /home/cvspublic/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/ClientClassAltrmiFactory.java,v
>retrieving revision 1.2
>diff -u -r1.2 ClientClassAltrmiFactory.java
>--- src/java/org/apache/excalibur/altrmi/client/impl/ClientClassAltrmiFactory.java	10 Apr 2002 23:36:58 -0000	1.2
>+++ src/java/org/apache/excalibur/altrmi/client/impl/ClientClassAltrmiFactory.java	17 Apr 2002 17:45:27 -0000
>@@ -10,19 +10,11 @@
> 
> 
> 
>-import org.apache.excalibur.altrmi.client.AltrmiFactory;
>-import org.apache.excalibur.altrmi.client.AltrmiHostContext;
>-import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
>-import org.apache.excalibur.altrmi.common.LookupReply;
>-import org.apache.excalibur.altrmi.common.LookupRequest;
>-import org.apache.excalibur.altrmi.common.AltrmiReply;
>-import org.apache.excalibur.altrmi.common.NotPublishedReply;
>-import org.apache.excalibur.altrmi.common.AltrmiAuthentication;
>-import org.apache.excalibur.altrmi.common.ExceptionReply;
>-
> import java.lang.reflect.Constructor;
> import java.lang.reflect.InvocationTargetException;
> 
>+import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
>+
> 
> /**
>  * Class ClientClassAltrmiFactory
>@@ -48,49 +40,6 @@
>   //      super(beanOnly, classLoader);
>     //}
> 
>-    /**
>-     * Method lookup
>-     *
>-     *
>-     * @param publishedServiceName
>-     * @param altrmiAuthentication
>-     *
>-     * @return
>-     *
>-     * @throws AltrmiConnectionException
>-     *
>-     */
>-    public Object lookup(String publishedServiceName, AltrmiAuthentication altrmiAuthentication)
>-            throws AltrmiConnectionException {
>-
>-        AltrmiReply ar =
>-            mHostContext.getInvocationHandler()
>-                .handleInvocation(new LookupRequest(publishedServiceName, altrmiAuthentication, mSession));
>-
>-        if (ar.getReplyCode() >= AltrmiReply.PROBLEMREPLY) {
>-            if (ar instanceof NotPublishedReply) {
>-                throw new AltrmiConnectionException("Service " + publishedServiceName
>-                                                    + " not published");
>-            } else if (ar instanceof ExceptionReply) {
>-                ExceptionReply er = (ExceptionReply) ar;
>-
>-                throw (AltrmiConnectionException) er.getReplyException();
>-            } else {
>-                throw new AltrmiConnectionException("Problem doing lookup on service");
>-            }
>-        }
>-
>-        LookupReply lr = (LookupReply) ar;
>-        DefaultProxyHelper baseObj = new DefaultProxyHelper(this,
>-                                                        mHostContext.getInvocationHandler(),
>-                                                        publishedServiceName, "Main",
>-                                                        lr.getReferenceID(), mSession);
>-        Object retVal = getInstance(publishedServiceName, "Main", baseObj, isBeanOnly());
>-
>-        baseObj.registerImplObject(retVal);
>-
>-        return retVal;
>-    }
> 
>     protected Class getFacadeClass(String publishedServiceName, String objectName, boolean beanOnly) throws AltrmiConnectionException, ClassNotFoundException {
>         String code = "2";
>Index: src/java/org/apache/excalibur/altrmi/client/impl/ServerClassAltrmiFactory.java
>===================================================================
>RCS file: /home/cvspublic/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/client/impl/ServerClassAltrmiFactory.java,v
>retrieving revision 1.3
>diff -u -r1.3 ServerClassAltrmiFactory.java
>--- src/java/org/apache/excalibur/altrmi/client/impl/ServerClassAltrmiFactory.java	10 Apr 2002 23:36:58 -0000	1.3
>+++ src/java/org/apache/excalibur/altrmi/client/impl/ServerClassAltrmiFactory.java	17 Apr 2002 17:45:28 -0000
>@@ -10,25 +10,17 @@
> 
> 
> 
>-import org.apache.excalibur.altrmi.client.AltrmiFactory;
>-import org.apache.excalibur.altrmi.client.AltrmiHostContext;
>-import org.apache.excalibur.altrmi.common.ClassReply;
>+import java.lang.reflect.Constructor;
>+import java.lang.reflect.InvocationTargetException;
>+import java.util.HashMap;
>+
> import org.apache.excalibur.altrmi.common.AltrmiConnectionException;
>+import org.apache.excalibur.altrmi.common.AltrmiReply;
>+import org.apache.excalibur.altrmi.common.ClassReply;
> import org.apache.excalibur.altrmi.common.ClassRequest;
>+import org.apache.excalibur.altrmi.common.ClassRetrievalFailedReply;
> import org.apache.excalibur.altrmi.common.NotPublishedException;
>-import org.apache.excalibur.altrmi.common.LookupReply;
>-import org.apache.excalibur.altrmi.common.LookupRequest;
>-import org.apache.excalibur.altrmi.common.AltrmiReply;
>-import org.apache.excalibur.altrmi.common.NotPublishedReply;
> import org.apache.excalibur.altrmi.common.RequestFailedReply;
>-import org.apache.excalibur.altrmi.common.AltrmiAuthentication;
>-import org.apache.excalibur.altrmi.common.ExceptionReply;
>-import org.apache.excalibur.altrmi.common.ClassRetrievalFailedReply;
>-
>-import java.util.HashMap;
>-
>-import java.lang.reflect.Constructor;
>-import java.lang.reflect.InvocationTargetException;
> 
> 
> /**
>@@ -54,51 +46,6 @@
>         super(beanOnly);
>     }
> 
>-
>-    /**
>-     * Method lookup
>-     *
>-     *
>-     * @param publishedServiceName
>-     * @param altrmiAuthentication
>-     *
>-     * @return
>-     *
>-     * @throws AltrmiConnectionException
>-     *
>-     */
>-    public Object lookup(String publishedServiceName, AltrmiAuthentication altrmiAuthentication)
>-            throws AltrmiConnectionException {
>-
>-        AltrmiReply ar =
>-            mHostContext.getInvocationHandler()
>-                .handleInvocation(new LookupRequest(publishedServiceName, altrmiAuthentication,
>-                                                    mSession));
>-
>-        if (ar.getReplyCode() >= AltrmiReply.PROBLEMREPLY) {
>-            if (ar instanceof NotPublishedReply) {
>-                throw new AltrmiConnectionException("Service " + publishedServiceName
>-                                                    + " not published");
>-            } else if (ar instanceof ExceptionReply) {
>-                ExceptionReply er = (ExceptionReply) ar;
>-
>-                throw (AltrmiConnectionException) er.getReplyException();
>-            } else {
>-                throw new AltrmiConnectionException("Problem doing lookup on service");
>-            }
>-        }
>-
>-        LookupReply lr = (LookupReply) ar;
>-        DefaultProxyHelper baseObj = new DefaultProxyHelper(this,
>-                                                        mHostContext.getInvocationHandler(),
>-                                                        publishedServiceName, "Main",
>-                                                        lr.getReferenceID(), mSession);
>-        Object retVal = getInstance(publishedServiceName, "Main", baseObj, isBeanOnly());
>-
>-        baseObj.registerImplObject(retVal);
>-
>-        return retVal;
>-    }
> 
>     protected Class getFacadeClass(String publishedServiceName, String objectName, boolean beanOnly) throws AltrmiConnectionException, ClassNotFoundException{
> 
>
>
>------------------------------------------------------------------------
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>