LV-encoding messages, added JPA validation.
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import envoy.util.SerializationUtils;
|
||||
* Project: <strong>envoy-server-standalone</strong><br>
|
||||
* File: <strong>ObjectWriteProxy.java</strong><br>
|
||||
* Created: <strong>04.01.2020</strong><br>
|
||||
*
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user