From fe7ada4d90fd796a1c1ee8b3eb182a09d6cd8467 Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Mon, 27 Jan 2014 02:27:15 +0100 Subject: [PATCH] Remote comunications between GUI and batch app. --- RemoteAgents/README | 9 ++ RemoteAgents/remote-agents-batchapp/pom.xml | 53 ++++++++++ .../de/remote/agents/batch/app/BatchAppMain.java | 14 +++ .../src/main/jetty/jetty-http.xml | 71 +++++++++++++ .../src/main/resources/log4j.properties | 8 ++ .../src/main/webapp/WEB-INF/applicationContext.xml | 18 ++++ .../main/webapp/WEB-INF/spring-mainapp-servlet.xml | 21 ++++ .../src/main/webapp/WEB-INF/web.xml | 24 +++++ RemoteAgents/remote-agents-clients/pom.xml | 30 ++++++ .../remote/agents/clients/app/ClientsMainTest.java | 44 +++++++++ .../agents/clients/app/SpringContextLocator.java | 51 ++++++++++ .../resources/clients-remote-agents-spring.xml | 13 +++ .../src/main/resources/log4j.properties | 8 ++ RemoteAgents/remote-agents-main/pom.xml | 110 +++++++++++++++++++++ .../remote-agents-services-implementation/pom.xml | 25 +++++ .../main/java/de/remote/agents/SnakeEyesImpl.java | 33 +++++++ .../de/remote/agents/services/UserServiceImpl.java | 20 ++++ .../src/main/resources/service-spring.xml | 14 +++ .../remote-agents-services-interfaces/pom.xml | 20 ++++ .../src/main/java/de/remote/agents/SnakeEyes.java | 8 ++ .../de/remote/agents/services/UserService.java | 8 ++ 21 files changed, 602 insertions(+) create mode 100644 RemoteAgents/README create mode 100644 RemoteAgents/remote-agents-batchapp/pom.xml create mode 100644 RemoteAgents/remote-agents-batchapp/src/main/java/de/remote/agents/batch/app/BatchAppMain.java create mode 100644 RemoteAgents/remote-agents-batchapp/src/main/jetty/jetty-http.xml create mode 100644 RemoteAgents/remote-agents-batchapp/src/main/resources/log4j.properties create mode 100644 RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/applicationContext.xml create mode 100644 RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml create mode 100644 RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/web.xml create mode 100644 RemoteAgents/remote-agents-clients/pom.xml create mode 100644 RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java create mode 100644 RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java create mode 100644 RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml create mode 100644 RemoteAgents/remote-agents-clients/src/main/resources/log4j.properties create mode 100644 RemoteAgents/remote-agents-main/pom.xml create mode 100644 RemoteAgents/remote-agents-services-implementation/pom.xml create mode 100644 RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/SnakeEyesImpl.java create mode 100644 RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/UserServiceImpl.java create mode 100644 RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml create mode 100644 RemoteAgents/remote-agents-services-interfaces/pom.xml create mode 100644 RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/SnakeEyes.java create mode 100644 RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/UserService.java diff --git a/RemoteAgents/README b/RemoteAgents/README new file mode 100644 index 0000000..978a8f5 --- /dev/null +++ b/RemoteAgents/README @@ -0,0 +1,9 @@ + + +export M2_HOME=/opt/maven/apache-maven-3.1.1 +PATH=$M2_HOME/bin:$PATH +PATH=/opt/java/jdk1.7.0_51/bin:$PATH + +mvn clean install -Dmaven.test.skip=true + +mvn jetty:run diff --git a/RemoteAgents/remote-agents-batchapp/pom.xml b/RemoteAgents/remote-agents-batchapp/pom.xml new file mode 100644 index 0000000..6045a90 --- /dev/null +++ b/RemoteAgents/remote-agents-batchapp/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + + remote-agents + de.remote.agents + 1.0-SNAPSHOT + + remote-agents-batchapp + remote-agents-batchapp + http://gumartinm.name + + 9.1.1.v20140108 + + + + de.remote.agents + remote-agents-services-interfaces + ${project.version} + + + de.remote.agents + remote-agents-services-implementation + ${project.version} + + + org.springframework.ws + spring-ws-core + + + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.version} + + ${basedir}/src/main/jetty/jetty-http.xml + + + + + + diff --git a/RemoteAgents/remote-agents-batchapp/src/main/java/de/remote/agents/batch/app/BatchAppMain.java b/RemoteAgents/remote-agents-batchapp/src/main/java/de/remote/agents/batch/app/BatchAppMain.java new file mode 100644 index 0000000..f2d381d --- /dev/null +++ b/RemoteAgents/remote-agents-batchapp/src/main/java/de/remote/agents/batch/app/BatchAppMain.java @@ -0,0 +1,14 @@ +package de.remote.agents.batch.app; + +import javax.annotation.PostConstruct; + +import org.apache.log4j.Logger; + +public class BatchAppMain { + private static final Logger logger = Logger.getLogger(BatchAppMain.class); + + @PostConstruct + public void batchAppMain() { + logger.info("GI JOE!"); + } +} diff --git a/RemoteAgents/remote-agents-batchapp/src/main/jetty/jetty-http.xml b/RemoteAgents/remote-agents-batchapp/src/main/jetty/jetty-http.xml new file mode 100644 index 0000000..568787f --- /dev/null +++ b/RemoteAgents/remote-agents-batchapp/src/main/jetty/jetty-http.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + https + + + + 32768 + 8192 + 8192 + true + false + 512 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RemoteAgents/remote-agents-batchapp/src/main/resources/log4j.properties b/RemoteAgents/remote-agents-batchapp/src/main/resources/log4j.properties new file mode 100644 index 0000000..caabcff --- /dev/null +++ b/RemoteAgents/remote-agents-batchapp/src/main/resources/log4j.properties @@ -0,0 +1,8 @@ +log4j.rootLogger=INFO, stdout +log4j.logger.org.springframework.ws=INFO +log4j.logger.org.springframework.xml=INFO +log4j.logger.de.spring.webservices=INFO + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyyMMddHHmmssSSS} - %-5p - [%t] - [%C] - %m%n diff --git a/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/applicationContext.xml b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/applicationContext.xml new file mode 100644 index 0000000..8406d8b --- /dev/null +++ b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/applicationContext.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml new file mode 100644 index 0000000..b24b1b5 --- /dev/null +++ b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + diff --git a/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/web.xml b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..0e7541d --- /dev/null +++ b/RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + Remote Agents: batch application + + + org.springframework.web.context.ContextLoaderListener + + + + spring-mainapp + org.springframework.web.servlet.DispatcherServlet + 1 + + + + spring-mainapp + /spring-mainapp/* + + + + diff --git a/RemoteAgents/remote-agents-clients/pom.xml b/RemoteAgents/remote-agents-clients/pom.xml new file mode 100644 index 0000000..bd177ab --- /dev/null +++ b/RemoteAgents/remote-agents-clients/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + remote-agents + de.remote.agents + 1.0-SNAPSHOT + + remote-agents-clients + remote-agents-clients + http://gumartinm.name + + + com.github.briandilley.jsonrpc4j + jsonrpc4j + + + de.remote.agents + remote-agents-services-interfaces + ${project.version} + + + de.remote.agents + remote-agents-services-implementation + ${project.version} + + + diff --git a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java new file mode 100644 index 0000000..983958c --- /dev/null +++ b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java @@ -0,0 +1,44 @@ +package de.remote.agents.clients.app; + +import java.net.URL; + +import org.apache.log4j.Logger; + +import com.googlecode.jsonrpc4j.JsonRpcHttpClient; + +import de.remote.agents.SnakeEyes; +import de.remote.agents.SnakeEyesImpl; + +public class ClientsMainTest { + private static final Logger logger = Logger.getLogger(ClientsMainTest.class); + + public static void main(final String[] args) throws Throwable { + + final JsonRpcHttpClient client = new JsonRpcHttpClient(new URL( + "http://127.0.0.1:8080/spring-mainapp/UserService.json")); + + final SnakeEyes user = client.invoke("createUser", new Object[] { + "Shana M. O'Hara", "Snake Eyes" }, SnakeEyesImpl.class); + + logger.info("Canon: " + user.getCanon()); + logger.info("Name: " + user.getName()); + + + // I need a way to set the return type parameter, otherwise I am not + // going to be able to use this JSON-RPC plugin :( + + // logger.info("Starting application"); + // SpringContextLocator.getInstance(); + // + // final UserService test = (UserService) SpringContextLocator + // .getInstance().getBean("remoteUserService"); + // + // final SnakeEyes snakeEyes = test.createUser("Shana M. O'Hara", + // "Snake Eyes"); + // + // logger.info("Canon: " + snakeEyes.getCanon()); + // logger.info("Name: " + snakeEyes.getName()); + + } + +} diff --git a/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java new file mode 100644 index 0000000..e5e96c2 --- /dev/null +++ b/RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java @@ -0,0 +1,51 @@ +package de.remote.agents.clients.app; + +import org.apache.log4j.Logger; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class SpringContextLocator { + private static final Logger logger = Logger.getLogger(SpringContextLocator.class); + + // Singleton Pattern + private static SpringContextLocator instance; + + // Spring ApplicationContext + private static ApplicationContext context; + + // Spring Context + private static final String SPRING_CONFIG_CONTEXT = "clients-remote-agents-spring.xml"; + + /** + * Private constructor. Singleton pattern. + */ + private SpringContextLocator() { + logger.info("Loading context files: " + SpringContextLocator.SPRING_CONFIG_CONTEXT); + + final String[] factoryFiles = new String[] { SPRING_CONFIG_CONTEXT }; + + context = new ClassPathXmlApplicationContext(factoryFiles); + + logger.info("The context has been loaded successfully!! "); + } + + /** + * Singleton pattern not thread safety. To use SingletoHolder pattern as the + * best approximation otherwise to use an Enum class (see Effective Java + * Second Edition and ) if we need serialization. + */ + public static SpringContextLocator getInstance() { + if (instance == null) { + instance = new SpringContextLocator(); + } + return instance; + } + + /** + * Return bean from application context. + */ + public Object getBean(final String name) { + return context.getBean(name); + } + +} diff --git a/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml b/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml new file mode 100644 index 0000000..b917a91 --- /dev/null +++ b/RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/RemoteAgents/remote-agents-clients/src/main/resources/log4j.properties b/RemoteAgents/remote-agents-clients/src/main/resources/log4j.properties new file mode 100644 index 0000000..caabcff --- /dev/null +++ b/RemoteAgents/remote-agents-clients/src/main/resources/log4j.properties @@ -0,0 +1,8 @@ +log4j.rootLogger=INFO, stdout +log4j.logger.org.springframework.ws=INFO +log4j.logger.org.springframework.xml=INFO +log4j.logger.de.spring.webservices=INFO + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyyMMddHHmmssSSS} - %-5p - [%t] - [%C] - %m%n diff --git a/RemoteAgents/remote-agents-main/pom.xml b/RemoteAgents/remote-agents-main/pom.xml new file mode 100644 index 0000000..55c4e4e --- /dev/null +++ b/RemoteAgents/remote-agents-main/pom.xml @@ -0,0 +1,110 @@ + + 4.0.0 + de.remote.agents + remote-agents + pom + 1.0-SNAPSHOT + remote-agents + http://gumartinm.name + Remote Agents Implementation + + Gustavo Martin Morcuende + http://www.gumartinm.name + + + scm:git:http://git.gumartinm.name/RemoteAgents + http://git.gumartinm.name/RemoteAgents + + + UTF-8 + 3.2.4.RELEASE + 2.1.4.RELEASE + + + + org.springframework + spring-context + ${spring.version} + + + org.slf4j + slf4j-api + 1.7.5 + + + org.slf4j + slf4j-log4j12 + 1.7.5 + + + cglib + cglib + 2.2.2 + + + + + + org.springframework.ws + spring-ws-core + ${spring.ws.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + com.mchange + c3p0 + 0.9.2.1 + + + com.github.briandilley.jsonrpc4j + jsonrpc4j + 1.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + ${project.description} + ${project.version} + ${project.organization.name} + ${project.description} + ${project.version} + ${project.organization.name} + + + + + + + diff --git a/RemoteAgents/remote-agents-services-implementation/pom.xml b/RemoteAgents/remote-agents-services-implementation/pom.xml new file mode 100644 index 0000000..a5854f3 --- /dev/null +++ b/RemoteAgents/remote-agents-services-implementation/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + remote-agents + de.remote.agents + 1.0-SNAPSHOT + + remote-agents-services-implementation + remote-agents-services-implementation + http://gumartinm.name + + + com.github.briandilley.jsonrpc4j + jsonrpc4j + + + de.remote.agents + remote-agents-services-interfaces + ${project.version} + + + diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/SnakeEyesImpl.java b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/SnakeEyesImpl.java new file mode 100644 index 0000000..92f6189 --- /dev/null +++ b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/SnakeEyesImpl.java @@ -0,0 +1,33 @@ +package de.remote.agents; + +public class SnakeEyesImpl implements SnakeEyes { + + private String canon; + private String name; + + public SnakeEyesImpl() { + }; + + public SnakeEyesImpl(final String canon, final String name) { + this.canon = canon; + this.name = name; + } + + @Override + public String getCanon() { + return this.canon; + } + + @Override + public String getName() { + return this.name; + } + + public void setCanon(final String canon) { + this.canon = canon; + } + + public void setName(final String name) { + this.name = name; + } +} diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/UserServiceImpl.java b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/UserServiceImpl.java new file mode 100644 index 0000000..2741fac --- /dev/null +++ b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/UserServiceImpl.java @@ -0,0 +1,20 @@ +package de.remote.agents.services; + +import org.apache.log4j.Logger; + +import de.remote.agents.SnakeEyes; +import de.remote.agents.SnakeEyesImpl; + +public class UserServiceImpl implements UserService { + private static final Logger logger = Logger.getLogger(UserServiceImpl.class); + + @Override + public SnakeEyes createUser(final String canon, final String name) { + logger.info("Canon: " + canon); + logger.info("Name: " + name); + + // TODO: spring factory :( + return new SnakeEyesImpl(canon, name); + } + +} diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml b/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml new file mode 100644 index 0000000..5d57305 --- /dev/null +++ b/RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/RemoteAgents/remote-agents-services-interfaces/pom.xml b/RemoteAgents/remote-agents-services-interfaces/pom.xml new file mode 100644 index 0000000..73df4e1 --- /dev/null +++ b/RemoteAgents/remote-agents-services-interfaces/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + remote-agents + de.remote.agents + 1.0-SNAPSHOT + + remote-agents-services-interfaces + remote-agents-services-interfaces + http://gumartinm.name + + + com.github.briandilley.jsonrpc4j + jsonrpc4j + + + diff --git a/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/SnakeEyes.java b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/SnakeEyes.java new file mode 100644 index 0000000..be06570 --- /dev/null +++ b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/SnakeEyes.java @@ -0,0 +1,8 @@ +package de.remote.agents; + +public interface SnakeEyes { + + public String getCanon(); + + public String getName(); +} diff --git a/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/UserService.java b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/UserService.java new file mode 100644 index 0000000..2951dee --- /dev/null +++ b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/UserService.java @@ -0,0 +1,8 @@ +package de.remote.agents.services; + +import de.remote.agents.SnakeEyes; + +public interface UserService { + + SnakeEyes createUser(String canon, String name); +} -- 2.1.4