org.nakedobjects.nos.remote.serialise.SerializingServerConnection Maven / Gradle / Ivy
package org.nakedobjects.nos.remote.serialise;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import org.nakedobjects.noa.NakedObjectRuntimeException;
import org.nakedobjects.nof.reflect.remote.IllegalRequestException;
import org.nakedobjects.nof.reflect.remote.data.Distribution;
import org.nakedobjects.nos.remote.command.Request;
import org.nakedobjects.nos.remote.command.socket.ServerConnection;
class SerializingServerConnection extends ServerConnection {
private final ObjectOutputStream output;
private final ObjectInputStream input;
public SerializingServerConnection(final InputStream input, final OutputStream output, final Distribution server) {
super(server);
try {
this.output = new ObjectOutputStream(output);
this.input = new ObjectInputStream(input);
} catch (IOException e) {
throw new NakedObjectRuntimeException(e);
}
}
protected Request awaitRequest() throws IOException {
try {
Request request = (Request) input.readObject();
return request;
} catch (ClassNotFoundException e) {
throw new IllegalRequestException("unknown class received; closing connection: " + e.getMessage(), e);
}
}
protected void sendError(NakedObjectRuntimeException exception) throws IOException {
send(exception);
}
protected void sendResponse(Object response) throws IOException {
send(response);
}
private void send(Object object) throws IOException {
output.writeObject(object);
output.flush();
}
}
// Copyright (c) Naked Objects Group Ltd.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy