All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nakedobjects.nos.remote.serialise.SerializingClientConnection 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 java.net.SocketException;

import org.apache.log4j.Logger;
import org.nakedobjects.nos.remote.command.ConnectionException;
import org.nakedobjects.nos.remote.command.Request;
import org.nakedobjects.nos.remote.command.socket.ClientConnection;


class SerializingClientConnection extends ClientConnection {
    private static final Logger LOG = Logger.getLogger(SerializingClientConnection.class);
    private ObjectInputStream input;
    private ObjectOutputStream output;


    protected void openStreams(InputStream input, OutputStream output) throws IOException {
        input = new ObjectInputStream(input);
        output = new ObjectOutputStream(output);
    }

    protected Object request(final Request request) throws IOException {
            try {
            LOG.debug("sending request" + request);
            try {
                output.writeObject(request);
            } catch (SocketException e) {
                reconnect();
                output.writeObject(request);
            }
            output.flush();
            Object object = input.readObject();
            LOG.debug("response received: " + object);
            return object;
 /*       } catch (StreamCorruptedException e) {
            try {
                int available = input.available();
                LOG.debug("error in reading; skipping bytes: " + available);
                input.skip(available);
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            throw new ConnectionException(e.getMessage(), e);
            */
        } catch (ClassNotFoundException e) {
            throw new ConnectionException("Failed request", e);
        }
    }

    
}
// Copyright (c) Naked Objects Group Ltd.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy