Search in sources :

Example 1 with HessianInput

use of com.caucho.hessian.io.HessianInput in project cayenne by apache.

the class HessianUtil method cloneViaClientServerSerialization.

/**
 * A utility method that clones an object using Hessian serialization/deserialization
 * mechanism, which is different from default Java serialization.
 */
public static Object cloneViaClientServerSerialization(Serializable object, EntityResolver serverResolver) throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    HessianOutput out = new HessianOutput(bytes);
    out.setSerializerFactory(HessianConfig.createFactory(ClientHessianSerializationServiceProvider.CLIENT_SERIALIZER_FACTORIES, null));
    out.writeObject(object);
    byte[] data = bytes.toByteArray();
    HessianInput in = new HessianInput(new ByteArrayInputStream(data));
    in.setSerializerFactory(HessianConfig.createFactory(ServerHessianSerializationServiceProvider.SERVER_SERIALIZER_FACTORIES, serverResolver));
    return in.readObject();
}
Also used : HessianInput(com.caucho.hessian.io.HessianInput) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HessianOutput(com.caucho.hessian.io.HessianOutput)

Example 2 with HessianInput

use of com.caucho.hessian.io.HessianInput in project cayenne by apache.

the class HessianUtil method cloneViaServerClientSerialization.

public static Object cloneViaServerClientSerialization(Serializable object, EntityResolver serverResolver) throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    HessianOutput out = new HessianOutput(bytes);
    out.setSerializerFactory(HessianConfig.createFactory(ServerHessianSerializationServiceProvider.SERVER_SERIALIZER_FACTORIES, serverResolver));
    out.writeObject(object);
    byte[] data = bytes.toByteArray();
    HessianInput in = new HessianInput(new ByteArrayInputStream(data));
    in.setSerializerFactory(HessianConfig.createFactory(ClientHessianSerializationServiceProvider.CLIENT_SERIALIZER_FACTORIES, null));
    return in.readObject();
}
Also used : HessianInput(com.caucho.hessian.io.HessianInput) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HessianOutput(com.caucho.hessian.io.HessianOutput)

Example 3 with HessianInput

use of com.caucho.hessian.io.HessianInput in project cayenne by apache.

the class HessianROPSerializationService method deserialize.

@Override
public <T> T deserialize(byte[] serializedObject, Class<T> objectClass) throws IOException {
    HessianInput in = new HessianInput(new ByteArrayInputStream(serializedObject));
    in.setSerializerFactory(serializerFactory);
    return objectClass.cast(in.readObject());
}
Also used : HessianInput(com.caucho.hessian.io.HessianInput)

Example 4 with HessianInput

use of com.caucho.hessian.io.HessianInput in project spring-framework by spring-projects.

the class HessianExporter method doInvoke.

/**
	 * Actually invoke the skeleton with the given streams.
	 * @param skeleton the skeleton to invoke
	 * @param inputStream the request stream
	 * @param outputStream the response stream
	 * @throws Throwable if invocation failed
	 */
protected void doInvoke(HessianSkeleton skeleton, InputStream inputStream, OutputStream outputStream) throws Throwable {
    ClassLoader originalClassLoader = overrideThreadContextClassLoader();
    try {
        InputStream isToUse = inputStream;
        OutputStream osToUse = outputStream;
        if (this.debugLogger != null && this.debugLogger.isDebugEnabled()) {
            PrintWriter debugWriter = new PrintWriter(new CommonsLogWriter(this.debugLogger));
            @SuppressWarnings("resource") HessianDebugInputStream dis = new HessianDebugInputStream(inputStream, debugWriter);
            @SuppressWarnings("resource") HessianDebugOutputStream dos = new HessianDebugOutputStream(outputStream, debugWriter);
            dis.startTop2();
            dos.startTop2();
            isToUse = dis;
            osToUse = dos;
        }
        if (!isToUse.markSupported()) {
            isToUse = new BufferedInputStream(isToUse);
            isToUse.mark(1);
        }
        int code = isToUse.read();
        int major;
        int minor;
        AbstractHessianInput in;
        AbstractHessianOutput out;
        if (code == 'H') {
            // Hessian 2.0 stream
            major = isToUse.read();
            minor = isToUse.read();
            if (major != 0x02) {
                throw new IOException("Version " + major + '.' + minor + " is not understood");
            }
            in = new Hessian2Input(isToUse);
            out = new Hessian2Output(osToUse);
            in.readCall();
        } else if (code == 'C') {
            // Hessian 2.0 call... for some reason not handled in HessianServlet!
            isToUse.reset();
            in = new Hessian2Input(isToUse);
            out = new Hessian2Output(osToUse);
            in.readCall();
        } else if (code == 'c') {
            // Hessian 1.0 call
            major = isToUse.read();
            minor = isToUse.read();
            in = new HessianInput(isToUse);
            if (major >= 2) {
                out = new Hessian2Output(osToUse);
            } else {
                out = new HessianOutput(osToUse);
            }
        } else {
            throw new IOException("Expected 'H'/'C' (Hessian 2.0) or 'c' (Hessian 1.0) in hessian input at " + code);
        }
        if (this.serializerFactory != null) {
            in.setSerializerFactory(this.serializerFactory);
            out.setSerializerFactory(this.serializerFactory);
        }
        if (this.remoteResolver != null) {
            in.setRemoteResolver(this.remoteResolver);
        }
        try {
            skeleton.invoke(in, out);
        } finally {
            try {
                in.close();
                isToUse.close();
            } catch (IOException ex) {
            // ignore
            }
            try {
                out.close();
                osToUse.close();
            } catch (IOException ex) {
            // ignore
            }
        }
    } finally {
        resetThreadContextClassLoader(originalClassLoader);
    }
}
Also used : Hessian2Output(com.caucho.hessian.io.Hessian2Output) HessianInput(com.caucho.hessian.io.HessianInput) AbstractHessianInput(com.caucho.hessian.io.AbstractHessianInput) BufferedInputStream(java.io.BufferedInputStream) HessianDebugInputStream(com.caucho.hessian.io.HessianDebugInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) HessianDebugOutputStream(com.caucho.hessian.io.HessianDebugOutputStream) IOException(java.io.IOException) HessianOutput(com.caucho.hessian.io.HessianOutput) AbstractHessianOutput(com.caucho.hessian.io.AbstractHessianOutput) AbstractHessianInput(com.caucho.hessian.io.AbstractHessianInput) HessianDebugInputStream(com.caucho.hessian.io.HessianDebugInputStream) Hessian2Input(com.caucho.hessian.io.Hessian2Input) HessianDebugOutputStream(com.caucho.hessian.io.HessianDebugOutputStream) BufferedInputStream(java.io.BufferedInputStream) CommonsLogWriter(org.springframework.util.CommonsLogWriter) AbstractHessianOutput(com.caucho.hessian.io.AbstractHessianOutput) PrintWriter(java.io.PrintWriter)

Example 5 with HessianInput

use of com.caucho.hessian.io.HessianInput in project cayenne by apache.

the class HessianROPSerializationService method deserialize.

@Override
public <T> T deserialize(InputStream input, Class<T> objectClass) throws IOException {
    HessianInput in = new HessianInput(input);
    in.setSerializerFactory(serializerFactory);
    return objectClass.cast(in.readObject());
}
Also used : HessianInput(com.caucho.hessian.io.HessianInput)

Aggregations

HessianInput (com.caucho.hessian.io.HessianInput)5 HessianOutput (com.caucho.hessian.io.HessianOutput)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 AbstractHessianInput (com.caucho.hessian.io.AbstractHessianInput)1 AbstractHessianOutput (com.caucho.hessian.io.AbstractHessianOutput)1 Hessian2Input (com.caucho.hessian.io.Hessian2Input)1 Hessian2Output (com.caucho.hessian.io.Hessian2Output)1 HessianDebugInputStream (com.caucho.hessian.io.HessianDebugInputStream)1 HessianDebugOutputStream (com.caucho.hessian.io.HessianDebugOutputStream)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 CommonsLogWriter (org.springframework.util.CommonsLogWriter)1