LV-encoding messages, added JPA validation.
This commit is contained in:
		
							
								
								
									
										16
									
								
								.classpath
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								.classpath
									
									
									
									
									
								
							@@ -6,11 +6,6 @@
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="optional" value="true"/>
 | 
			
		||||
@@ -18,12 +13,6 @@
 | 
			
		||||
			<attribute name="test" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
			<attribute name="test" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
@@ -35,5 +24,10 @@
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="src" path="/envoy-common"/>
 | 
			
		||||
	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
 | 
			
		||||
		<attributes>
 | 
			
		||||
			<attribute name="maven.pomderived" value="true"/>
 | 
			
		||||
		</attributes>
 | 
			
		||||
	</classpathentry>
 | 
			
		||||
	<classpathentry kind="output" path="target/classes"/>
 | 
			
		||||
</classpath>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								.project
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								.project
									
									
									
									
									
								
							@@ -5,11 +5,21 @@
 | 
			
		||||
	<projects>
 | 
			
		||||
	</projects>
 | 
			
		||||
	<buildSpec>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>org.eclipse.wst.common.project.facet.core.builder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>org.eclipse.jdt.core.javabuilder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>org.eclipse.wst.validation.validationbuilder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>org.eclipse.m2e.core.maven2Builder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
@@ -19,5 +29,6 @@
 | 
			
		||||
	<natures>
 | 
			
		||||
		<nature>org.eclipse.jdt.core.javanature</nature>
 | 
			
		||||
		<nature>org.eclipse.m2e.core.maven2Nature</nature>
 | 
			
		||||
		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
 | 
			
		||||
	</natures>
 | 
			
		||||
</projectDescription>
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								.settings/org.eclipse.jpt.core.prefs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.settings/org.eclipse.jpt.core.prefs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
eclipse.preferences.version=1
 | 
			
		||||
org.eclipse.jpt.core.platform=generic2_1
 | 
			
		||||
org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=true
 | 
			
		||||
@@ -0,0 +1,7 @@
 | 
			
		||||
<root>
 | 
			
		||||
  <facet id="jpt.jpa">
 | 
			
		||||
    <node name="libprov">
 | 
			
		||||
      <attribute name="provider-id" value="jpa-no-op-library-provider"/>
 | 
			
		||||
    </node>
 | 
			
		||||
  </facet>
 | 
			
		||||
</root>
 | 
			
		||||
							
								
								
									
										5
									
								
								.settings/org.eclipse.wst.common.project.facet.core.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								.settings/org.eclipse.wst.common.project.facet.core.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<faceted-project>
 | 
			
		||||
  <installed facet="java" version="1.8"/>
 | 
			
		||||
  <installed facet="jpt.jpa" version="2.1"/>
 | 
			
		||||
</faceted-project>
 | 
			
		||||
@@ -29,10 +29,10 @@ public class Startup {
 | 
			
		||||
	 * @since Envoy Server Standalone v0.1-alpha
 | 
			
		||||
	 */
 | 
			
		||||
	public static void main(String[] args) throws IOException {
 | 
			
		||||
		Set<ObjectProcessor<?, ?>> processors = new HashSet<>();
 | 
			
		||||
		Set<ObjectProcessor<?>> 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());
 | 
			
		||||
 
 | 
			
		||||
@@ -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.<br>
 | 
			
		||||
@@ -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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -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);
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user