[New] Implementing PLC client<->server websocket
This commit is contained in:
parent
a1429b8d7b
commit
08e6057a08
18
pom.xml
18
pom.xml
|
@ -69,7 +69,8 @@
|
|||
<module>strolch-plc-model</module>
|
||||
<module>strolch-plc-core</module>
|
||||
<module>strolch-plc-rest</module>
|
||||
<module>strolch-plc-gw</module>
|
||||
<module>strolch-plc-gw-client</module>
|
||||
<module>strolch-plc-gw-server</module>
|
||||
</modules>
|
||||
|
||||
<developers>
|
||||
|
@ -149,6 +150,11 @@
|
|||
</dependency>
|
||||
|
||||
<!-- PLC -->
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>strolch-plc-model</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>strolch-plc-core</artifactId>
|
||||
|
@ -159,6 +165,16 @@
|
|||
<artifactId>strolch-plc-rest</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>strolch-plc-gw-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>strolch-plc-gw-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Pi4j -->
|
||||
<dependency>
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
<version>0.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>strolch-plc-gw</artifactId>
|
||||
<name>strolch-plc-gw</name>
|
||||
<artifactId>strolch-plc-gw-client</artifactId>
|
||||
<name>strolch-plc-gw-client</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>https://github.com/4treesCH/strolch-plc</url>
|
||||
|
||||
|
@ -109,20 +109,17 @@
|
|||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/componentVersion.properties</exclude>
|
||||
</excludes>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**/componentVersion.properties</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/*.properties</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package li.strolch.plc.gw;
|
||||
package li.strolch.plc.gw.client;
|
||||
|
||||
import static java.net.NetworkInterface.getByInetAddress;
|
||||
import static li.strolch.model.Tags.Json.*;
|
||||
|
@ -8,11 +8,8 @@ import static li.strolch.utils.helper.ExceptionHelper.getExceptionMessageWithCau
|
|||
import static li.strolch.utils.helper.NetworkHelper.formatMacAddress;
|
||||
import static li.strolch.utils.helper.StringHelper.isEmpty;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.*;
|
||||
import javax.websocket.CloseReason.CloseCodes;
|
||||
import javax.websocket.PongMessage;
|
||||
import javax.websocket.RemoteEndpoint;
|
||||
import javax.websocket.Session;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketException;
|
||||
import java.net.URI;
|
||||
|
@ -35,7 +32,7 @@ import li.strolch.utils.helper.ExceptionHelper;
|
|||
import li.strolch.utils.helper.NetworkHelper;
|
||||
import org.glassfish.tyrus.client.ClientManager;
|
||||
|
||||
public class PlcGwHandler extends StrolchComponent {
|
||||
public class PlcGwClientHandler extends StrolchComponent {
|
||||
|
||||
private static final long RETRY_DELAY = 30;
|
||||
private static final int INITIAL_DELAY = 10;
|
||||
|
@ -55,7 +52,7 @@ public class PlcGwHandler extends StrolchComponent {
|
|||
private JsonArray ipAddresses;
|
||||
private JsonObject versions;
|
||||
|
||||
public PlcGwHandler(ComponentContainer container, String componentName) {
|
||||
public PlcGwClientHandler(ComponentContainer container, String componentName) {
|
||||
super(container, componentName);
|
||||
}
|
||||
|
||||
|
@ -393,4 +390,39 @@ public class PlcGwHandler extends StrolchComponent {
|
|||
}
|
||||
return this.ipAddresses;
|
||||
}
|
||||
|
||||
@ClientEndpoint
|
||||
public static class PlcGwClientEndpoint {
|
||||
|
||||
private PlcGwClientHandler gwHandler;
|
||||
|
||||
public PlcGwClientEndpoint(PlcGwClientHandler gwHandler) {
|
||||
this.gwHandler = gwHandler;
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session) {
|
||||
this.gwHandler.handleMessage(session, message);
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onPong(PongMessage message, Session session) {
|
||||
this.gwHandler.pong(message, session);
|
||||
}
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session) {
|
||||
this.gwHandler.open(session);
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose(Session session, CloseReason closeReason) {
|
||||
this.gwHandler.close(session, closeReason);
|
||||
}
|
||||
|
||||
@OnError
|
||||
public void onError(Session session, Throwable throwable) {
|
||||
this.gwHandler.error(session, throwable);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
groupId=${project.groupId}
|
||||
artifactId=${project.artifactId}
|
||||
artifactVersion=${project.version}
|
||||
scmRevision=${buildNumber}
|
||||
scmBranch=${scmBranch}
|
||||
buildTimestamp=${buildTimestamp}
|
|
@ -0,0 +1,137 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>
|
||||
|
||||
<parent>
|
||||
<artifactId>strolch-plc</artifactId>
|
||||
<groupId>li.strolch</groupId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>strolch-plc-gw-server</artifactId>
|
||||
<name>strolch-plc-gw-client</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>https://github.com/4treesCH/strolch-plc</url>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:4treesCH/strolch-plc.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:4treesCH/strolch-plc.git</developerConnection>
|
||||
<url>https://github.com/4treesCH/strolch-plc</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<!-- properties -->
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- base -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Strolch -->
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.model</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.agent</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.service</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- PLC -->
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>strolch-plc-model</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- web -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.websocket</groupId>
|
||||
<artifactId>javax.websocket-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.bundles</groupId>
|
||||
<artifactId>jaxrs-ri</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.tyrus</groupId>
|
||||
<artifactId>tyrus-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.tyrus</groupId>
|
||||
<artifactId>tyrus-container-grizzly-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/*.properties</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,33 @@
|
|||
package li.strolch.plc.gw.server;
|
||||
|
||||
import javax.websocket.*;
|
||||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.StrolchComponent;
|
||||
|
||||
public class PlcGwServerHandler extends StrolchComponent {
|
||||
|
||||
public PlcGwServerHandler(ComponentContainer container, String componentName) {
|
||||
super(container, componentName);
|
||||
}
|
||||
|
||||
public void onMessage(String message, Session session) {
|
||||
logger.info(session.getId() + ": Message: " + message);
|
||||
}
|
||||
|
||||
public void onPong(PongMessage message, Session session) {
|
||||
logger.info(session.getId() + ": Message: " + message);
|
||||
}
|
||||
|
||||
public void onOpen(Session session) {
|
||||
logger.info(session.getId() + ": Opening!");
|
||||
}
|
||||
|
||||
public void onClose(Session session, CloseReason closeReason) {
|
||||
logger.info(session.getId() + ": Closing: " + closeReason);
|
||||
}
|
||||
|
||||
public void onError(Session session, Throwable throwable) {
|
||||
logger.error(session.getId() + ": Error: " + throwable.getMessage(), true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package li.strolch.plc.gw.server;
|
||||
|
||||
import javax.websocket.*;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
import li.strolch.rest.RestfulStrolchComponent;
|
||||
|
||||
@ServerEndpoint("/websocket/strolch/plc")
|
||||
public class PlcServerWebSocketEndpoint {
|
||||
|
||||
private PlcGwServerHandler serverHandler;
|
||||
|
||||
public PlcServerWebSocketEndpoint() {
|
||||
this.serverHandler = RestfulStrolchComponent.getInstance().getComponent(PlcGwServerHandler.class);
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session) {
|
||||
this.serverHandler.onMessage(message, session);
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onPong(PongMessage message, Session session) {
|
||||
this.serverHandler.onPong(message, session);
|
||||
}
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session) {
|
||||
this.serverHandler.onOpen(session);
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose(Session session, CloseReason closeReason) {
|
||||
this.serverHandler.onClose(session, closeReason);
|
||||
}
|
||||
|
||||
@OnError
|
||||
public void onError(Session session, Throwable throwable) {
|
||||
this.serverHandler.onError(session, throwable);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
groupId=${project.groupId}
|
||||
artifactId=${project.artifactId}
|
||||
artifactVersion=${project.version}
|
||||
scmRevision=${buildNumber}
|
||||
scmBranch=${scmBranch}
|
||||
buildTimestamp=${buildTimestamp}
|
|
@ -1,38 +0,0 @@
|
|||
package li.strolch.plc.gw;
|
||||
|
||||
import javax.websocket.*;
|
||||
|
||||
@ClientEndpoint
|
||||
public class PlcGwClientEndpoint {
|
||||
|
||||
private PlcGwHandler gwHandler;
|
||||
|
||||
public PlcGwClientEndpoint(PlcGwHandler gwHandler) {
|
||||
this.gwHandler = gwHandler;
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onMessage(String message, Session session) {
|
||||
this.gwHandler.handleMessage(session, message);
|
||||
}
|
||||
|
||||
@OnMessage
|
||||
public void onPong(PongMessage message, Session session) {
|
||||
this.gwHandler.pong(message, session);
|
||||
}
|
||||
|
||||
@OnOpen
|
||||
public void onOpen(Session session) {
|
||||
this.gwHandler.open(session);
|
||||
}
|
||||
|
||||
@OnClose
|
||||
public void onClose(Session session, CloseReason closeReason) {
|
||||
this.gwHandler.close(session, closeReason);
|
||||
}
|
||||
|
||||
@OnError
|
||||
public void onError(Session session, Throwable throwable) {
|
||||
this.gwHandler.error(session, throwable);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
groupId=${project.groupId}
|
||||
artifactId=${project.artifactId}
|
||||
artifactVersion=${project.version}
|
||||
scmRevision=${buildNumber}
|
||||
scmBranch=${scmBranch}
|
||||
buildTimestamp=${buildTimestamp}
|
|
@ -110,20 +110,17 @@
|
|||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/componentVersion.properties</exclude>
|
||||
</excludes>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**/componentVersion.properties</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/*.properties</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
groupId=${project.groupId}
|
||||
artifactId=${project.artifactId}
|
||||
artifactVersion=${project.version}
|
||||
scmRevision=${buildNumber}
|
||||
scmBranch=${scmBranch}
|
||||
buildTimestamp=${buildTimestamp}
|
Loading…
Reference in New Issue