Search in sources :

Example 1 with OResponseProcessingException

use of com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException in project orientdb by orientechnologies.

the class OChannelBinaryAsynchClient method throwSerializedException.

private void throwSerializedException(final byte[] serializedException) throws IOException {
    final OMemoryInputStream inputStream = new OMemoryInputStream(serializedException);
    final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
    Object throwable = null;
    try {
        throwable = objectInputStream.readObject();
    } catch (ClassNotFoundException e) {
        OLogManager.instance().error(this, "Error during exception deserialization", e);
        throw new IOException("Error during exception deserialization: " + e.toString());
    }
    objectInputStream.close();
    if (throwable instanceof OException) {
        try {
            final Class<? extends OException> cls = (Class<? extends OException>) throwable.getClass();
            final Constructor<? extends OException> constructor;
            constructor = cls.getConstructor(cls);
            final OException proxyInstance = constructor.newInstance(throwable);
            throw proxyInstance;
        } catch (NoSuchMethodException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (InvocationTargetException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (InstantiationException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (IllegalAccessException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        }
    }
    if (throwable instanceof Throwable) {
        throw new OResponseProcessingException("Exception during response processing", (Throwable) throwable);
    } else
        // WRAP IT
        OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null"));
}
Also used : OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OException(com.orientechnologies.common.exception.OException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OResponseProcessingException(com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with OResponseProcessingException

use of com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException in project orientdb by orientechnologies.

the class OChannelBinaryClientAbstract method throwSerializedException.

protected void throwSerializedException(final byte[] serializedException) throws IOException {
    final OMemoryInputStream inputStream = new OMemoryInputStream(serializedException);
    final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
    Object throwable = null;
    try {
        throwable = objectInputStream.readObject();
    } catch (ClassNotFoundException e) {
        OLogManager.instance().error(this, "Error during exception deserialization", e);
        throw new IOException("Error during exception deserialization: " + e.toString());
    }
    objectInputStream.close();
    if (throwable instanceof OException) {
        try {
            final Class<? extends OException> cls = (Class<? extends OException>) throwable.getClass();
            final Constructor<? extends OException> constructor;
            constructor = cls.getConstructor(cls);
            final OException proxyInstance = constructor.newInstance(throwable);
            throw proxyInstance;
        } catch (NoSuchMethodException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (InvocationTargetException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (InstantiationException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (IllegalAccessException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        }
    }
    if (throwable instanceof Throwable) {
        throw new OResponseProcessingException("Exception during response processing", (Throwable) throwable);
    } else
        // WRAP IT
        OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null"));
}
Also used : OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OException(com.orientechnologies.common.exception.OException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OResponseProcessingException(com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException)

Aggregations

OException (com.orientechnologies.common.exception.OException)2 OMemoryInputStream (com.orientechnologies.orient.core.serialization.OMemoryInputStream)2 OResponseProcessingException (com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 OIOException (com.orientechnologies.common.io.OIOException)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1