summaryrefslogtreecommitdiff
path: root/rpctest
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-10 15:34:55 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-10 15:34:55 +0100
commit9a554911174e096b95e99527eac04627400c41ba (patch)
tree2d36439a69ded1ca54051e3a1636106423c3d7c9 /rpctest
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 'rpctest')
-rw-r--r--rpctest/pom.xml63
-rw-r--r--rpctest/src/main/java/com/orbekk/App.java13
-rw-r--r--rpctest/src/main/java/com/orbekk/Calculator.java5
-rw-r--r--rpctest/src/main/java/com/orbekk/CalculatorImpl.java7
-rw-r--r--rpctest/src/main/java/com/orbekk/Client.java27
-rw-r--r--rpctest/src/main/java/com/orbekk/ServerTest.java51
-rw-r--r--rpctest/src/main/resources/log4j.properties5
-rw-r--r--rpctest/src/test/java/com/orbekk/AppTest.java38
-rw-r--r--rpctest/target/classes/log4j.properties5
9 files changed, 214 insertions, 0 deletions
diff --git a/rpctest/pom.xml b/rpctest/pom.xml
new file mode 100644
index 0000000..36fd446
--- /dev/null
+++ b/rpctest/pom.xml
@@ -0,0 +1,63 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.orbekk</groupId>
+ <artifactId>rpctest</artifactId>
+ <version>0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>rpctest</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-server</artifactId>
+ <version>3.1.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-client</artifactId>
+ <version>3.1.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.xmlrpc</groupId>
+ <artifactId>xmlrpc-common</artifactId>
+ <version>3.1.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/rpctest/src/main/java/com/orbekk/App.java b/rpctest/src/main/java/com/orbekk/App.java
new file mode 100644
index 0000000..8459172
--- /dev/null
+++ b/rpctest/src/main/java/com/orbekk/App.java
@@ -0,0 +1,13 @@
+package com.orbekk;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
diff --git a/rpctest/src/main/java/com/orbekk/Calculator.java b/rpctest/src/main/java/com/orbekk/Calculator.java
new file mode 100644
index 0000000..8fda63c
--- /dev/null
+++ b/rpctest/src/main/java/com/orbekk/Calculator.java
@@ -0,0 +1,5 @@
+package com.orbekk;
+
+interface Calculator {
+ int add(int x, int y);
+}
diff --git a/rpctest/src/main/java/com/orbekk/CalculatorImpl.java b/rpctest/src/main/java/com/orbekk/CalculatorImpl.java
new file mode 100644
index 0000000..5540f3a
--- /dev/null
+++ b/rpctest/src/main/java/com/orbekk/CalculatorImpl.java
@@ -0,0 +1,7 @@
+package com.orbekk;
+
+public class CalculatorImpl implements Calculator {
+ public int add(int x, int y) {
+ return x + y;
+ }
+}
diff --git a/rpctest/src/main/java/com/orbekk/Client.java b/rpctest/src/main/java/com/orbekk/Client.java
new file mode 100644
index 0000000..dca3018
--- /dev/null
+++ b/rpctest/src/main/java/com/orbekk/Client.java
@@ -0,0 +1,27 @@
+package com.orbekk;
+
+import java.net.URL;
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.util.ClientFactory;
+
+public class Client {
+ public static void main(String[] args) throws Exception {
+ Logger logger = Logger.getLogger("Client");
+ logger.info("Client starting.");
+ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+ config.setServerURL(new URL("http://localhost:10080/xmlrpc"));
+ XmlRpcClient client = new XmlRpcClient();
+ client.setConfig(config);
+ ClientFactory factory = new ClientFactory(client);
+ Calculator calculator = (Calculator)factory.newInstance(
+ Calculator.class);
+ int sum = calculator.add(40, 2);
+ for (int i = 0; i < 100; i++) {
+ sum = calculator.add(40, 2);
+ }
+ System.out.println("The answer is " + sum);
+ logger.info("Client finished.");
+ }
+}
diff --git a/rpctest/src/main/java/com/orbekk/ServerTest.java b/rpctest/src/main/java/com/orbekk/ServerTest.java
new file mode 100644
index 0000000..e8c9a3e
--- /dev/null
+++ b/rpctest/src/main/java/com/orbekk/ServerTest.java
@@ -0,0 +1,51 @@
+package com.orbekk;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.server.PropertyHandlerMapping;
+import org.apache.xmlrpc.server.XmlRpcHandlerMapping;
+import org.apache.xmlrpc.webserver.ServletWebServer;
+import org.apache.xmlrpc.webserver.XmlRpcServlet;
+
+public class ServerTest {
+ final static int port = 10080;
+
+ public static class HandlerServlet extends XmlRpcServlet {
+ private XmlRpcHandlerMapping mapping;
+
+ public HandlerServlet(XmlRpcHandlerMapping mapping)
+ throws ServletException {
+ this.mapping = mapping;
+ }
+
+ @Override
+ protected XmlRpcHandlerMapping newXmlRpcHandlerMapping()
+ throws XmlRpcException {
+ return mapping;
+ }
+ }
+
+ public static void main(String[] args) {
+ System.out.println("Starting " + ServerTest.class.getName());
+ try {
+ PropertyHandlerMapping phm = new PropertyHandlerMapping();
+ phm.setVoidMethodEnabled(true);
+ phm.addHandler(Calculator.class.getName(), CalculatorImpl.class);
+
+ XmlRpcServlet servlet = new HandlerServlet(phm);
+ ServletWebServer server = new ServletWebServer(servlet, port);
+ server.start();
+ } catch (XmlRpcException e) {
+ System.err.println("Error creating property mapping.");
+ e.printStackTrace();
+ } catch (ServletException e) {
+ System.err.println("Unable to initialize servlet.");
+ e.printStackTrace();
+ } catch (IOException e) {
+ System.err.println("Exception from web server.");
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/rpctest/src/main/resources/log4j.properties b/rpctest/src/main/resources/log4j.properties
new file mode 100644
index 0000000..6ca6c6f
--- /dev/null
+++ b/rpctest/src/main/resources/log4j.properties
@@ -0,0 +1,5 @@
+log4j.rootLogger=DEBUG, A1
+
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n
diff --git a/rpctest/src/test/java/com/orbekk/AppTest.java b/rpctest/src/test/java/com/orbekk/AppTest.java
new file mode 100644
index 0000000..9201a36
--- /dev/null
+++ b/rpctest/src/test/java/com/orbekk/AppTest.java
@@ -0,0 +1,38 @@
+package com.orbekk;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/rpctest/target/classes/log4j.properties b/rpctest/target/classes/log4j.properties
new file mode 100644
index 0000000..6ca6c6f
--- /dev/null
+++ b/rpctest/target/classes/log4j.properties
@@ -0,0 +1,5 @@
+log4j.rootLogger=DEBUG, A1
+
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n