commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hubert Rabago <hrab...@gmail.com>
Subject Re: [beanutils] Problem with MethodUtils.invokeExactMethod
Date Wed, 09 Mar 2005 00:11:31 GMT
Your guess matches mine.
It seems invokeExactMethod() uses getClass() to determine the argument
types, so for your call, it'll use the actual (runtime) class of your
request object, and it won't find setupMethod1 which declares
HttpServletRequest.

I wrote a quick test:
public class SampleClass {
    
    public void method(Object a) {
        System.out.println("inside method() where a=" + a);
    }
    
    public static void main(String[] args) 
            throws Exception {
        SampleClass sc = new SampleClass();
        String s = "hello";
        MethodUtils.invokeExactMethod(sc, "method", 
                new Object[] {s}, new Class[] {Object.class});
        MethodUtils.invokeExactMethod(sc, "method", s);
    }
}

The first call ran fine, the second failed.  This seems to match the
problem you're seeing.

Hubert

On Tue, 08 Mar 2005 18:10:39 -0500, Frank W. Zammetti
<fzlists@omnytex.com> wrote:
> Hello...
> 
> I'm trying to use MethodUtils.invokeExactMethod, and I keep receiving:
> 
> java.lang.NoSuchMethodException: No such accessible method:
> setupMethod1() on object: com.omnytex.setupexample.setups.SetupClass1
> 
> Here's the pertinent code:
> 
> String setupClass = "com.omnytex.setupexample.setups.SetupClass1";
> String setupMethod = "setupMethod1";
> Object setupClassObj = RequestUtils.applicationInstance(setupClass);
> MethodUtils.invokeExactMethod(setupClassObj, setupMethod, request);
> 
> request is an HttpServletRequest object.  Here's the code for SetupClass1:
> 
> package com.omnytex.setupexample.setups;
> import javax.servlet.http.HttpServletRequest;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> public class SetupClass1 {
>   private static Log log = LogFactory.getLog(SetupClass1.class);
>   public void setupMethod1(HttpServletRequest request) {
>     log.info("setupMethod1() - Setting request attribute...");
>     request.setAttribute("c1m1", "c1m1_value");
>     log.info("setupMethod1() - Done!");
>   }
> }
> 
> Clearly, there is in fact a setupMethod1() method.  I have verified that
> setupClassObj is in fact a valid object of the correct type, so its not
> an instantiation problem (would have expected a different exception if
> it was anyway).
> 
> My only guess is that I'm somehow not using the argument portion of the
> invokeExactMethod() call properly, but I don't see what the problem
> specifically might be.
> 
> Any ideas?  Thanks!
> 
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message