Here's some code I wrote to illustrate a point. I know it sucks, but it
was just a quick hack. Obviously you don't want to copy the whole file
into a string buffer before you return it, but doing it the right way
would have taken more than 10 minutes. Anyway, here's Freenet via XML-RPC
in 10 minutes:
public class XmlRpcServer
{
static public void main(String[] args) throws Exception
{
WebServer webserver = new WebServer (8082);
SimpleServer ss=new SimpleServer();
webserver.addHandler ("$default", ss);
}
}
public class client
{
static public void main(String[] args) throws Exception
{
XmlRpcClient client=new XmlRpcClient("http://localhost:8082/");
Vector v=new Vector();
v.addElement("test-key");
Object result=client.execute("getFile", v);
System.out.println(result);
}
}
That's it. It uses the XML-RPC implementation for Java at
http://classic.helma.at/hannes/xmlrpc/.
Here's a client written in Python using
http://www.pythonware.com/products/xmlrpc/:
from xmlrpclib import Server
freenet = Server("http://localhost:8082")
print freenet.getFile("test-key")
Of course I have to provide an API to expose via XML-RPC, but that's just
a normal Java object which isn't aware of the existence of XML-RPC at
all. Here's the simple API I made which sucks but was fast to code:
public class SimpleServer
{
public String getFile(String uri)
{
SimplifiedClient sc=new SimplifiedClient();
Pair p=sc.get(uri);
Bucket data=(Bucket)p.first;
StringBuffer buff=new StringBuffer();
InputStream in=data.getInputStream();
byte[] b=new byte[1];
int c=in.read(b);
while(c!=-1)
{
buff.append((char)b[0]);
c=in.read(b);
}
return buff.toString();
}
}
All this code works, BTW. You can use it to actually get files from
Freenet. The next step in an XML-RPC-based client protocol would be to
define an API for SimpleServer which didn't suck so much, with events,
chunking, etc..
_______________________________________________
Devl mailing list
Devl at freenetproject.org
http://www.uprizer.com/mailman/listinfo/devl