diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-10 15:34:55 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-10 15:34:55 +0100 |
commit | 9a554911174e096b95e99527eac04627400c41ba (patch) | |
tree | 2d36439a69ded1ca54051e3a1636106423c3d7c9 /jsonrpc/src/main/java/com/orbekk/rpc |
Initial import of maven projects.
jsonrpc - Common classes.
rpctest - A small xmlrpc project.
master - Android application containing broadcast code and ping service.
Diffstat (limited to 'jsonrpc/src/main/java/com/orbekk/rpc')
5 files changed, 94 insertions, 0 deletions
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); + } +} |