commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <fzli...@omnytex.com>
Subject Re: [beanutils] Problem with MethodUtils.invokeExactMethod
Date Wed, 09 Mar 2005 00:37:16 GMT
Ah!  Found the problem!

At runtime, the request object is of type 
org.apache.coyote.tomcat5.CoyoteRequestFacade.

Well, ok.  Guess I didn't quite find it :)  I'm not sure why that would 
matter, and I'm not sure why fully-qualifying HttpServlevRequest would 
work.  Hopefully one of you smarter than I knows?

I tried casting request to HttpServletRequest before handing it off to 
invokeExactMethod(), that made no difference.  I'm out of ideas!  I can 
just stick with the code that does work, its not at all a problem to 
have the fully-qualified name hardcoded because it would never be 
anything else.

However, I really want to understand why the beanutils call doesn't work...

Frank

Frank W. Zammetti wrote:
> Odd... Here's an interesting observation... If you look at the code I 
> just posted that DID work, it is interesting that in order for it to 
> work, the request object MUST be fully-qualified in the forName() call. 
>  Also, I tried replacing that single line with:
> 
> pTypes[0] = request.getClass();
> 
> ...which by all rights should work, but no, it doesn't (which is 
> basically all beanutils is doing).
> 
> It seems that beanutils, and more generically the getClass() method, 
> isn't returning the proper type... or something (in my best Butthead 
> voice)...
> 
> Hubert Rabago wrote:
> 
>> 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
>>>
>>>
>>
>>
>>
>>
>>
> 

-- 
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


Mime
View raw message