|
Hello everybody,
I've try to find an simple servelt example for am
XML-RPC Server. I found different souces, many of them for an independent
XML-RPC server. I lookup on xml.apache.org, but I could't find anything . I
lookup up , too. at helma.org, and in many other web sites, but nothing. I was
able to run an XML -RPC Client, but XML-RPC Server dosn't work. Here my code
:
import java.io.*;
import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.Vector;
import helma.xmlrpc.*; public class ExampleServlet extends XmlRpcServlet { XmlRpcServer xmlrpc; public void init (ServletConfig config) throws ServletException { xmlrpc = new XmlRpcServer (); xmlrpc.addHandler ("test", new NewHandler() ); } public void doPost (HttpServletRequest request, HttpServletResponse response) { try
{
PrintWriter out = response.getWriter() ; byte[] tempbyte = new byte[1000] ; tempbyte = xmlrpc.execute(request.getInputStream()); String temp = new String(tempbyte); response.setContentType("text/xml"); response.setContentLength(temp.length()); out.println(temp); } catch (IOException e) { System.err.println ("Crud"); e.printStackTrace(); } } public void doGet( HttpServletRequest request,
HttpServletResponse response ) {
try { response.setContentType ("text/html"); PrintWriter out = new PrintWriter (response.getWriter(), true); out.print ("Need to use POST."); } catch (Exception e) { e.printStackTrace(); } } public void destroy ()
{
System.out.println ("TestServer destroyed..."); } public Object execute (String methodname, Vector
params) {
return "This is a fix string"; } } public class NewHandler {
// Simple test functions public int intAdd(int arg) { return 333;
} } I call this code with the folowing html
:
<html>
<BODY> <FORM ACTION="http://localhost/servlets/ExampleServlet" METHOD="POST"> <textarea rows="12" cols="45"> </textarea> <INPUT TYPE="SUBMIT" value="OK"> </FORM> </BODY> </html> with this value for the textarea field
:
<?XML
VERSION="1.0"?>
<methodCall> <methodName>test.intAdd</methodName> <params> <param> <value><i4>33</i4></value> </param> </params> </methodCall> and alway I get the following response
:
<?xml version="1.0" encoding="ISO-8859-1" ?>
</methodResponse>
Please help me with any code that work!!!
Thanks in advance,
Raul Gereanu
|
- Re: Help!!! Need an Servlet Example - Fucking help Gereanu Raul
- Re: Help!!! Need an Servlet Example - Fucking help Gereanu Raul
- Re: Help!!! Need an Servlet Example - Fucking help Daniel Rall
- Help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Need an Serv... Gereanu Raul
- Re: Help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Need... Daniel Rall
