xml-rpc newbie
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ron_lau
Posted On:   Tuesday, February 19, 2002 06:57 AM

HI, I am using XML-Rpc in my web app using JSP so that clients through the web can make a call to the server. i have a servlet to receive call like below: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import org.apache.xmlrpc.XmlRpcServer; public class XMLRPCServlet extends HttpServlet { public XmlRpcServer xmlrpc; public void init(ServletConfig config) throws ServletException{ xmlrpc = new XmlRpcServer (); xmlrpc.addHandler ("hello", new HelloHandler()); } public void doPost(HttpServletRequest req, HttpServletResponse res) throws Ser   More>>

HI,



I am using XML-Rpc in my web app using JSP so that clients through the web can make a call to the server.




i have a servlet to receive call like below:


			
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import org.apache.xmlrpc.XmlRpcServer;

public class XMLRPCServlet extends HttpServlet {

public XmlRpcServer xmlrpc;

public void init(ServletConfig config) throws ServletException{


xmlrpc = new XmlRpcServer ();
xmlrpc.addHandler ("hello", new HelloHandler());

}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
byte[] charAry = xmlrpc.execute (req.getInputStream());
res.setContentType("text/xml");
res.setContentLength (charAry.length);
OutputStream output = res.getOutputStream();
output.write (charAry);
output.flush ();
}
}



i make it start with Tomcat at startup and write a JSP for testing like this..


			
<%@ page language="java" %>
<%@ page import="org.apache.xmlrpc.*" %>
<%@ page import="java.util.Vector" %>
...


<%
XmlRpcClient xmlrpc = new XmlRpcClient ("http://(my IP)");
Vector params = new Vector ();
params.addElement ("it is a test");
// this method returns a string
String result = (String)xmlrpc.execute("hello.sayHello", params);
System.out.println("Response from server: " + result);

%>
<%=result%>


...



the handler is very simple


			

public class HelloHandler {


public String sayHello(String name) {
return "Hello " + name;
}

}



however, it don't work and return null.. so can anyone help to tell me what's the problem?




many many thanks!!!!!!!!!



Best regards,

Ron    <<Less
About | Sitemap | Contact