tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Leone <midnightj...@cox.net>
Subject Re: Surprised with this behaviour. Is this a bug ?
Date Fri, 03 Jun 2005 03:34:09 GMT
Not sure I follow all your explanation, and I think you haven't shown us 
enough of your code to know what's going on, but what is the method 
signature for method.invoke()? You're passing it an Object and an Object[].

The former (obj) is returned from requestMap.get(). Assuming requestMap 
is a Map object, the get() method returns an object of whatever type you 
pit into it, and perhaps you should downcast to this type.

The second parameter you're passing into method.invoke() is an Object 
that has been "upcasted" from the return value of 
request.getParameterMap(). That method returns an object of type 
java.util.Map.

In sum, I would look at the method signature for method.invoke(), and 
cast your arguments in that method call as needed.

-Mark

nitin dubey wrote:

>Hello,
>
>>>From a servlet deployed in tomcat I am getting the
>request parameter map by calling getParameterMap()
>then using reflection calling a Class say "Sub" that
>has a method "construct(HashMap requestMap)".  The
>method is called properly but surprisingly I am
>getting InvocationTargetException->ClassCastException
>when I try to read the parameter from the map. 
>Following is the code.
>
>======== Code in Class called from Servlet ====
>// Note that the map instance is an instance of
>org.apache.catalina.util.ParameterMap
>Method method	= cls.getMethod("constructSql", new
>Class[]{request.getParameterMap().getClass().getSuperclass()});
>
>query	= (String) method.invoke(obj, new
>Object[]{request.getParameterMap()});
>
>======== Code from Sub ============
>public String construct(HashMap requestMap)	{
>log.info("~construct()");
>log.info("10");
>Object obj	= requestMap.get("ParamKey");
>log.info(obj.getClass());
>log.info("10.1");
>String str	= (String) obj;
>log.info(str);
>log.info("10.2");
>
>return "";
>}
>
>======== Console Output ==========
>INFO  [http-8080-Processor25] SearchCodeQuery     -
>~construct()
>INFO  [http-8080-Processor25] SearchCodeQuery     - 10
>INFO  [http-8080-Processor25] SearchCodeQuery     -
>class [Ljava.lang.String;
>INFO  [http-8080-Processor25] SearchCodeQuery     -
>10.1
>INFO  [http-8080-Processor25] ServletRequestProcessor 
>   - java.lang.reflect.InvocationTargetException
>INFO  [http-8080-Processor25] ServletRequestProcessor 
>   - java.lang.ClassCastException: [Ljava.lang.String;
>
>Is it because that the instance is actually
>org.apache.catalina.util.ParameterMap and I am trying
>to call get() over that instance ?  But ParameterMap
>itself does not have any implementation of get() it
>takes that from its superclass i.e. HashMap.
>
>Is it not supposed to run.  When you can see in the
>log that the value is a String object and a similar
>java application using LinkedHashMap and HashMap runs
>without any hiccups ?
>
>I am using JDK:1.5.0_03, Tomcat:5.5.9
>
>
>Thanks in advance
>
>
>Nitin
>
>
>
>		
>__________________________________ 
>Discover Yahoo! 
>Find restaurants, movies, travel and more fun for the weekend. Check it out! 
>http://discover.yahoo.com/weekend.html 
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>  
>

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


Mime
View raw message