如何使用Hessian信封与弹簧遥控器

时间:2013-09-10 17:14:29

标签: spring x509 hessian envelope

有没有人使用带有弹簧远程框架的粗麻布信封(X509和压缩)?我试图在客户端和服务器站点上继承HessianProxyFactory但没有成功:

    /*
 * (non-Javadoc)
 * 
 * @see
 * com.caucho.hessian.client.HessianProxyFactory#getHessianOutput(java.io
 * .OutputStream)
 */
@Override
public AbstractHessianOutput getHessianOutput(OutputStream os) {
    // TODO Auto-generated method stub
    // return super.getHessianOutput(arg0);
    AbstractHessianOutput standardOut;

    if (hessian2Request)
        standardOut = new Hessian2Output(os);
    else {
        standardOut = new HessianOutput(os);

        if (hessian2Reply)
            ((HessianOutput)standardOut).setVersion(2);
    }

    HessianEnvelope envelope = new Deflation();

    try {
        AbstractHessianOutput compressedOut = envelope
                .wrap((Hessian2Output) standardOut);
        compressedOut.setSerializerFactory(getSerializerFactory());

        return compressedOut;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }

}

和服务器站点:

    /* (non-Javadoc)
 * @see org.springframework.remoting.caucho.HessianExporter#doInvoke(com.caucho.hessian.server.HessianSkeleton, java.io.InputStream, java.io.OutputStream)
 */
@Override
protected void doInvoke(HessianSkeleton skeleton, InputStream inputStream,
        OutputStream outputStream) throws Throwable {

    Deflation envelope = new Deflation();
    Hessian2Input hin = new Hessian2Input(inputStream);
    hin = envelope.unwrap(hin);

    ClassLoader originalClassLoader = overrideThreadContextClassLoader();
    try {
        InputStream isToUse = inputStream;
        OutputStream osToUse = outputStream;

        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 = hin;
            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);
        }

        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);
    }
}

目前这只是一个黑客,但我的问题是,是否有人尝试过它。

问候,弗兰克

0 个答案:

没有答案