From 0324f3a4fd56bf23475347bc04b367001ea22a06 Mon Sep 17 00:00:00 2001 From: kske Date: Mon, 6 Jan 2020 17:40:19 +0100 Subject: [PATCH] LV-encoding messages, added JPA validation. --- .classpath | 16 +++++----------- .project | 11 +++++++++++ .settings/org.eclipse.jdt.core.prefs | 3 +++ .settings/org.eclipse.jpt.core.prefs | 3 +++ ...lipse.wst.common.project.facet.core.prefs.xml | 7 +++++++ ...org.eclipse.wst.common.project.facet.core.xml | 5 +++++ src/main/java/envoy/server/Startup.java | 4 ++-- .../envoy/server/net/ObjectMessageReader.java | 14 ++++---------- .../java/envoy/server/net/ObjectWriteProxy.java | 7 ++++++- 9 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 .settings/org.eclipse.jpt.core.prefs create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.prefs.xml create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml diff --git a/.classpath b/.classpath index 2a83b68..047eee0 100644 --- a/.classpath +++ b/.classpath @@ -6,11 +6,6 @@ - - - - - @@ -18,12 +13,6 @@ - - - - - - @@ -35,5 +24,10 @@ + + + + + diff --git a/.project b/.project index 45a395e..fdd0c87 100644 --- a/.project +++ b/.project @@ -5,11 +5,21 @@ + + org.eclipse.wst.common.project.facet.core.builder + + + org.eclipse.jdt.core.javabuilder + + org.eclipse.wst.validation.validationbuilder + + + org.eclipse.m2e.core.maven2Builder @@ -19,5 +29,6 @@ org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 2f5cc74..cac0df4 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,10 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.release=disabled diff --git a/.settings/org.eclipse.jpt.core.prefs b/.settings/org.eclipse.jpt.core.prefs new file mode 100644 index 0000000..7ff3376 --- /dev/null +++ b/.settings/org.eclipse.jpt.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +org.eclipse.jpt.core.platform=generic2_1 +org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=true diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..7961132 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..90f3be6 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java index b616946..58931ff 100644 --- a/src/main/java/envoy/server/Startup.java +++ b/src/main/java/envoy/server/Startup.java @@ -29,10 +29,10 @@ public class Startup { * @since Envoy Server Standalone v0.1-alpha */ public static void main(String[] args) throws IOException { - Set> processors = new HashSet<>(); + Set> processors = new HashSet<>(); processors.add(new LoginCredentialProcessor()); processors.add(new MessageProcessor()); - + // new PersistenceManager(); Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors)); server.start(); server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance()); diff --git a/src/main/java/envoy/server/net/ObjectMessageReader.java b/src/main/java/envoy/server/net/ObjectMessageReader.java index b477734..51fa3df 100644 --- a/src/main/java/envoy/server/net/ObjectMessageReader.java +++ b/src/main/java/envoy/server/net/ObjectMessageReader.java @@ -5,10 +5,9 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import com.jenkov.nioserver.IMessageReader; -import com.jenkov.nioserver.Message; -import com.jenkov.nioserver.MessageBuffer; -import com.jenkov.nioserver.Socket; +import com.jenkov.nioserver.*; + +import envoy.util.SerializationUtils; /** * This {@link IMessageReader} decodes serialized Java objects.
@@ -49,7 +48,7 @@ public class ObjectMessageReader implements IMessageReader { // Get message length if (nextMessage.length - nextMessage.offset < 4) return; - int length = fromByteArray(nextMessage.sharedArray, nextMessage.offset) + 4; + int length = SerializationUtils.bytesToInt(nextMessage.sharedArray, nextMessage.offset) + 4; if (nextMessage.length - nextMessage.offset >= length) { Message message = messageBuffer.getMessage(); @@ -60,9 +59,4 @@ public class ObjectMessageReader implements IMessageReader { buffer.clear(); } - - private int fromByteArray(byte[] bytes, int offset) { - return ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) - | ((bytes[offset + 3] & 0xFF) << 0); - } } \ No newline at end of file diff --git a/src/main/java/envoy/server/net/ObjectWriteProxy.java b/src/main/java/envoy/server/net/ObjectWriteProxy.java index b1dc337..bd6baf4 100644 --- a/src/main/java/envoy/server/net/ObjectWriteProxy.java +++ b/src/main/java/envoy/server/net/ObjectWriteProxy.java @@ -11,7 +11,7 @@ import envoy.util.SerializationUtils; * Project: envoy-server-standalone
* File: ObjectWriteProxy.java
* Created: 04.01.2020
- * + * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ @@ -28,6 +28,11 @@ public class ObjectWriteProxy { // Serialize object to byte array byte[] objBytes = SerializationUtils.writeToByteArray(obj); + + // Acquire object length in bytes + byte[] objLen = SerializationUtils.intToBytes(objBytes.length); + + response.writeToMessage(objLen); response.writeToMessage(objBytes); writeProxy.enqueue(response); }