java method invocation
hi all,
i am trying to invoke a servlet method named callMe() from idm as below
<invoke name='callMe' class='po.OutputServlet'/>
But IDM is giving an error -->Couldn't find method callMe in class ko.OutputServlet ==> java.lang.NoSuchMethodException: ko.OutputServlet.callMe()
Below is my custom servlet.
package po;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class OutputServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>"+
"Hello Client</HTML>");
out.close();
}
public static String callMe()
throws ServletException, IOException {
return "Success";
}
}
[958 byte] By [
yash@IDMa] at [2007-11-27 2:03:15]

# 1
Yash,The error has the class name as "ko.OutputServlet " but you are invoking it as "'po.OutputServlet". Tell me that it is a typo and not a real error :)~Suveshnull
# 2
Hi,That was just a typo(treat everything as po or ko)...I am still getting the same error...Is it how we invoke a custom java method? Am i missing something?
# 3
I guess its a problem with the return type of the function because when i replace String with void in the return type, its not throwing any error!! If the function has to return some value...what is the solution?Yash
# 4
Try this:
<new class='java.lang.String'>
<invoke name='callMe' class='po.OutputServlet'/>
</new>
and see if you get any further. You may want to wrap that in a <set> statement to tie it to a variable.
Jason
# 5
Hi ,
I am getting the same issue after using as you said.
Here is the below piece of code.
<block trace='true'>
<new class='java.lang.String'>
<invoke name='insert_rec'class='com.CrzDBConnection'/>
</new>
<ref>user_action</ref>
...........................................
............................................
i am also returning from this method.
I appreciate if you could help me on this.
# 6
Hi Jyoti,I am also facing the same error even now....Let us see who gets it solved first....Please update incase u get it... Looking forward for others help tooYash
# 7
I just checked some of our forms to see if we used any invoke statements to return Strings from static methods, and we do this to call a homegrown date helper class. This works for us (IDM 6.0 SP1) so it is possible.
I looked at our date helper class and the one thing that I noticed was different from the return value of your callMe() method was that we created a String within the method instead of a literal.
I wonder if you changed callMe() as follows if you would still see the problem:
public static String callMe()
throws ServletException, IOException {
String throwAway = "Success";
return throwAway;
}
This isn't a exactly how our class works (because it is handling a String returned from a DateFormat object) but you get the idea.
Jason
# 8
Hey.... First tell me... where did you place the class files of the java class?
# 9
howdy harini,I have placed it in a folder named po in classes folder(within WEB-INF)Yash
# 10
Hi Yash,
Below is a rule I created to test java invocation call,
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC 'waveset.dtd' 'waveset.dtd'>
<!-- MemberObjectGroups="#ID#Top" name="YouTest"-->
<Rule name='YouTest' createDate='1179290854984'>
<block trace='true'>
<defvar name='temp'>
<invoke name='callMe' class='com.abc.test'/>
</defvar>
<cond>
<notnull>
<ref>temp</ref>
</notnull>
<s>temp</s>
<s>no temp</s>
</cond>
</block>
<MemberObjectGroups>
<ObjectRef type='ObjectGroup' id='#ID#Top' name='Top'/>
</MemberObjectGroups>
</Rule>
And I got the thing perfectly fineand its also IDM 5 sp4. Java code for the method is below:
public static string callme()
{
return "string";
}
# 11
So its clear that its nothing to do with the return type. Can you let me know where you are using this java call ?suren
# 12
I have invoked it in the value property of a form..but i did not use the defvar as u did...try removing the defvar and see if you are getting the error...and run this rule for different return types like string, int, char etc.Yash
# 13
it was just an example. I have lots of java call in our real time system which have different return type and all are working fine. I tired the same in a form and value is getting correctly set for that field variable.Regards,Surinder
# 14
Hey yash,I guess you have to place ur package in classes-> com -> waveset -> packagename. Create folders in this hierarchy and place your class files there. Tell me if it works. I did the same in my previous project. It worked.