From 9a554911174e096b95e99527eac04627400c41ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 10 Jan 2012 15:34:55 +0100 Subject: Initial import of maven projects. jsonrpc - Common classes. rpctest - A small xmlrpc project. master - Android application containing broadcast code and ping service. --- jsonrpc/src/main/java/com/orbekk/rpc/App.java | 29 ++++++++++++++++++++++ jsonrpc/src/main/java/com/orbekk/rpc/Client.java | 25 +++++++++++++++++++ .../src/main/java/com/orbekk/rpc/PingService.java | 5 ++++ .../main/java/com/orbekk/rpc/PingServiceImpl.java | 8 ++++++ .../src/main/java/com/orbekk/rpc/RpcHandler.java | 27 ++++++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 jsonrpc/src/main/java/com/orbekk/rpc/App.java create mode 100644 jsonrpc/src/main/java/com/orbekk/rpc/Client.java create mode 100644 jsonrpc/src/main/java/com/orbekk/rpc/PingService.java create mode 100644 jsonrpc/src/main/java/com/orbekk/rpc/PingServiceImpl.java create mode 100644 jsonrpc/src/main/java/com/orbekk/rpc/RpcHandler.java (limited to 'jsonrpc/src/main/java/com/orbekk/rpc') diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/App.java b/jsonrpc/src/main/java/com/orbekk/rpc/App.java new file mode 100644 index 0000000..e112008 --- /dev/null +++ b/jsonrpc/src/main/java/com/orbekk/rpc/App.java @@ -0,0 +1,29 @@ +package com.orbekk.rpc; + +import org.eclipse.jetty.server.Server; + +import com.googlecode.jsonrpc4j.JsonRpcServer; + +public class App { + public static void main(String[] args) { + PingService service = new PingServiceImpl(); + JsonRpcServer jsonServer = new JsonRpcServer(service, PingService.class); + + Server server = new Server(10080); + RpcHandler rpcHandler = new RpcHandler(jsonServer); + server.setHandler(rpcHandler); + + try { + server.start(); + } catch (Exception e) { + System.out.println("Could not start jetty server."); + e.printStackTrace(); + } + + try { + server.join(); + } catch (InterruptedException e) { + System.out.println("Interrupt"); + } + } +} diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/Client.java b/jsonrpc/src/main/java/com/orbekk/rpc/Client.java new file mode 100644 index 0000000..bfb6c52 --- /dev/null +++ b/jsonrpc/src/main/java/com/orbekk/rpc/Client.java @@ -0,0 +1,25 @@ +package com.orbekk.rpc; + +import java.net.MalformedURLException; +import java.net.URL; + +import com.googlecode.jsonrpc4j.JsonRpcHttpClient; +import com.googlecode.jsonrpc4j.ProxyUtil; + +public class Client { + + public static void main(String[] args) { + JsonRpcHttpClient client = null; + try { + client = new JsonRpcHttpClient( + new URL("http://10.0.0.96:10080/PingService.json")); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + PingService service = ProxyUtil.createProxy( + client.getClass().getClassLoader(), + PingService.class, + client); + System.out.println(service.ping()); + } +} diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/PingService.java b/jsonrpc/src/main/java/com/orbekk/rpc/PingService.java new file mode 100644 index 0000000..353f7c5 --- /dev/null +++ b/jsonrpc/src/main/java/com/orbekk/rpc/PingService.java @@ -0,0 +1,5 @@ +package com.orbekk.rpc; + +public interface PingService { + String ping(); +} diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/PingServiceImpl.java b/jsonrpc/src/main/java/com/orbekk/rpc/PingServiceImpl.java new file mode 100644 index 0000000..9472846 --- /dev/null +++ b/jsonrpc/src/main/java/com/orbekk/rpc/PingServiceImpl.java @@ -0,0 +1,8 @@ +package com.orbekk.rpc; + +public class PingServiceImpl implements PingService { + @Override + public String ping() { + return "Pong"; + } +} diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/RpcHandler.java b/jsonrpc/src/main/java/com/orbekk/rpc/RpcHandler.java new file mode 100644 index 0000000..bc76e4e --- /dev/null +++ b/jsonrpc/src/main/java/com/orbekk/rpc/RpcHandler.java @@ -0,0 +1,27 @@ +package com.orbekk.rpc; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; + +import com.googlecode.jsonrpc4j.JsonRpcServer; + +public class RpcHandler extends AbstractHandler { + private JsonRpcServer rpcServer; + + public RpcHandler(JsonRpcServer rpcServer) { + this.rpcServer = rpcServer; + } + + @Override + public void handle(String target, Request baseRequest, + HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + rpcServer.handle(request, response); + } +} -- cgit v1.2.3