RemoteAgents, new service with input parameters.
authorgu.martinm@gmail.com <gu.martinm@gmail.com>
Wed, 5 Mar 2014 03:20:26 +0000 (04:20 +0100)
committergu.martinm@gmail.com <gu.martinm@gmail.com>
Wed, 5 Mar 2014 03:20:26 +0000 (04:20 +0100)
RemoteAgents/remote-agents-batchapp/src/main/webapp/WEB-INF/spring-mainapp-servlet.xml
RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/ClientsMainTest.java
RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/RemoteGUIExample.java
RemoteAgents/remote-agents-clients/src/main/java/de/remote/agents/clients/app/SpringContextLocator.java
RemoteAgents/remote-agents-clients/src/main/resources/clients-remote-agents-spring.xml
RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/WriteTextServiceImpl.java [new file with mode: 0644]
RemoteAgents/remote-agents-services-implementation/src/main/resources/service-spring.xml
RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/WriteTextService.java [new file with mode: 0644]

index 980e6c6..c614c13 100644 (file)
@@ -23,4 +23,9 @@
         <property name="serviceInterface" value="de.remote.agents.services.CurrentDateService"/>
     </bean>
 
+    <bean name="/WriteTextService.json" class="com.googlecode.jsonrpc4j.spring.JsonServiceExporter">
+        <property name="service" ref="writeTextService"/>
+        <property name="serviceInterface" value="de.remote.agents.services.WriteTextService"/>
+    </bean>
+
 </beans>
index 3bbaff9..eadad13 100644 (file)
@@ -6,6 +6,7 @@ import java.util.TimerTask;
 import org.apache.log4j.Logger;
 
 import de.remote.agents.services.CurrentDateService;
+import de.remote.agents.services.WriteTextService;
 
 public class ClientsMainTest {
     private static final Logger logger = Logger.getLogger(ClientsMainTest.class);
@@ -61,6 +62,10 @@ public class ClientsMainTest {
         // GUIThread.setUncaughtExceptionHandler(new DriverHWUncaughtExceptionHandler());
         GUIThread.start();
 
+        final WriteTextService remoteWriteText = (WriteTextService) SpringContextLocator
+                .getInstance().getBean("remoteWriteTextService");
+        window.setWriteTextService(remoteWriteText);
+
         final Timer t = new Timer("Timer-Thread", false);
         t.scheduleAtFixedRate(new TimerTask() {
             @Override
index a413a3b..b13033a 100644 (file)
@@ -1,16 +1,25 @@
 package de.remote.agents.clients.app;
 
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 
+import de.remote.agents.services.WriteTextService;
+
 public class RemoteGUIExample {
 
     private Shell shell;
     private Text textBox;
     private Display display;
+    private Label lblTextToSend;
+    private Text textToSend;
+    private WriteTextService writeTextService;
 
 
     /**
@@ -38,18 +47,61 @@ public class RemoteGUIExample {
         });
     }
 
+    public void setWriteTextService(final WriteTextService writeTextService) {
+        this.writeTextService = writeTextService;
+    }
 
     private void createContents() {
         this.shell = new Shell();
-        this.shell.setSize(450, 300);
+        this.shell.setSize(526, 419);
         this.shell.setText("Remote GUI");
 
         this.textBox = new Text(this.shell, SWT.BORDER);
-        this.textBox.setBounds(111, 95, 181, 58);
+        this.textBox.setBounds(80, 66, 181, 58);
 
         final Label lblRemoteDate = new Label(this.shell, SWT.NONE);
-        lblRemoteDate.setBounds(111, 63, 113, 26);
+        lblRemoteDate.setBounds(80, 34, 113, 26);
         lblRemoteDate.setText("Remote Date:");
-    }
 
+        this.lblTextToSend = new Label(this.shell, SWT.NONE);
+        this.lblTextToSend.setText("Text to send:");
+        this.lblTextToSend.setBounds(80, 171, 113, 26);
+
+        this.textToSend = new Text(this.shell, SWT.BORDER);
+        this.textToSend.setBounds(80, 203, 181, 58);
+
+        final Combo comboSendNumber = new Combo(this.shell, SWT.READ_ONLY);
+        comboSendNumber.setItems(new String[] { "1", "20", "30", "40", "500",
+                "633", "722", "899" });
+        comboSendNumber.setBounds(80, 309, 113, 43);
+        comboSendNumber.select(0);
+
+        final Label lblNumberToSend = new Label(this.shell, SWT.NONE);
+        lblNumberToSend.setText("Number to send:");
+        lblNumberToSend.setBounds(80, 277, 113, 26);
+
+        final Button btnSendtextAndNumber = new Button(this.shell, SWT.NONE);
+        btnSendtextAndNumber.setText("SendTextAndNumber");
+        btnSendtextAndNumber.setBounds(295, 302, 162, 23);
+        btnSendtextAndNumber.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseDown(final MouseEvent e) {
+                final String text = RemoteGUIExample.this.textToSend.getText();
+                final String item = comboSendNumber.getItem(comboSendNumber.getSelectionIndex());
+                RemoteGUIExample.this.writeTextService.setWriteText(text,
+                        Integer.valueOf(item));
+            }
+        });
+
+        final Button btnSendtext = new Button(this.shell, SWT.NONE);
+        btnSendtext.setBounds(295, 225, 162, 23);
+        btnSendtext.setText("SendText");
+        btnSendtext.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseDown(final MouseEvent e) {
+                final String text = RemoteGUIExample.this.textToSend.getText();
+                RemoteGUIExample.this.writeTextService.setWriteText(text);
+            }
+        });
+    }
 }
index e5e96c2..293d371 100644 (file)
@@ -30,8 +30,8 @@ public class SpringContextLocator {
     }
 
     /**
-     * Singleton pattern not thread safety. To use SingletoHolder pattern as the
-     * best approximation otherwise to use an Enum class (see Effective Java
+     * Singleton pattern not thread safety. To use SingletonHolder 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() {
index 502b166..1445d07 100644 (file)
@@ -15,4 +15,9 @@
         <property name="serviceInterface" value="de.remote.agents.services.CurrentDateService"/>
     </bean>
 
+    <bean id="remoteWriteTextService" class="com.googlecode.jsonrpc4j.spring.JsonProxyFactoryBean">
+        <property name="serviceUrl" value="http://127.0.0.1:8080/spring-mainapp/WriteTextService.json"/>
+        <property name="serviceInterface" value="de.remote.agents.services.WriteTextService"/>
+    </bean>
+
 </beans>
diff --git a/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/WriteTextServiceImpl.java b/RemoteAgents/remote-agents-services-implementation/src/main/java/de/remote/agents/services/WriteTextServiceImpl.java
new file mode 100644 (file)
index 0000000..7c05f04
--- /dev/null
@@ -0,0 +1,20 @@
+package de.remote.agents.services;
+
+import org.apache.log4j.Logger;
+
+public class WriteTextServiceImpl implements WriteTextService {
+    private static final Logger logger = Logger
+            .getLogger(WriteTextServiceImpl.class);
+
+    @Override
+    public void setWriteText(final String text, final Integer number) {
+        logger.info("String received from agent: " + text);
+        logger.info("Number received from agent: " + number);
+    }
+
+    @Override
+    public void setWriteText(final String text) {
+        logger.info("We have received one string from agent: " + text);
+    }
+
+}
index 67b2ed4..397953f 100644 (file)
@@ -14,4 +14,7 @@
     <bean id="currentDateService" class="de.remote.agents.services.CurrentDateServiceImpl">
     </bean>
 
+    <bean id="writeTextService" class="de.remote.agents.services.WriteTextServiceImpl">
+    </bean>
+
 </beans>
diff --git a/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/WriteTextService.java b/RemoteAgents/remote-agents-services-interfaces/src/main/java/de/remote/agents/services/WriteTextService.java
new file mode 100644 (file)
index 0000000..35b0b90
--- /dev/null
@@ -0,0 +1,8 @@
+package de.remote.agents.services;
+
+public interface WriteTextService {
+
+    void setWriteText(final String text);
+
+    void setWriteText(final String text, final Integer number);
+}