updated Hessian support for Hessian 3.2 compatibility; general remoting refinements
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.remoting.caucho;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -44,7 +45,7 @@ import org.springframework.util.CommonsLogWriter;
|
||||
* <p>Hessian is a slim, binary RPC protocol.
|
||||
* For information on Hessian, see the
|
||||
* <a href="http://www.caucho.com/hessian">Hessian website</a>.
|
||||
* This exporter requires Hessian 3.1.3 or above.
|
||||
* <b>Note: As of Spring 3.0, this exporter requires Hessian 3.2 or above.</b>
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5.1
|
||||
@@ -114,81 +115,108 @@ public class HessianExporter extends RemoteExporter implements InitializingBean
|
||||
*/
|
||||
public void invoke(InputStream inputStream, OutputStream outputStream) throws Throwable {
|
||||
Assert.notNull(this.skeleton, "Hessian exporter has not been initialized");
|
||||
doInvoke(this.skeleton, inputStream, outputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
doInvoke(inputStream, outputStream);
|
||||
InputStream isToUse = inputStream;
|
||||
OutputStream osToUse = outputStream;
|
||||
|
||||
if (this.debugLogger != null && this.debugLogger.isDebugEnabled()) {
|
||||
PrintWriter debugWriter = new PrintWriter(new CommonsLogWriter(this.debugLogger));
|
||||
HessianDebugInputStream dis = new HessianDebugInputStream(inputStream, debugWriter);
|
||||
dis.startTop2();
|
||||
HessianDebugOutputStream dos = new HessianDebugOutputStream(outputStream, debugWriter);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public void doInvoke(final InputStream inputStream, final OutputStream outputStream) throws Throwable {
|
||||
InputStream isToUse = inputStream;
|
||||
OutputStream osToUse = outputStream;
|
||||
|
||||
if (this.debugLogger != null && this.debugLogger.isDebugEnabled()) {
|
||||
PrintWriter debugWriter = new PrintWriter(new CommonsLogWriter(this.debugLogger));
|
||||
isToUse = new HessianDebugInputStream(inputStream, debugWriter);
|
||||
osToUse = new HessianDebugOutputStream(outputStream, debugWriter);
|
||||
}
|
||||
|
||||
int code = isToUse.read();
|
||||
int major;
|
||||
int minor;
|
||||
|
||||
AbstractHessianInput in;
|
||||
AbstractHessianOutput out;
|
||||
|
||||
if (code == 'H') {
|
||||
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') {
|
||||
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' (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 {
|
||||
this.skeleton.invoke(in, out);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
in.close();
|
||||
isToUse.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
out.close();
|
||||
osToUse.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ import org.springframework.web.util.NestedServletException;
|
||||
* <p>Hessian is a slim, binary RPC protocol.
|
||||
* For information on Hessian, see the
|
||||
* <a href="http://www.caucho.com/hessian">Hessian website</a>.
|
||||
* This exporter requires Hessian 3.1.3 or above.
|
||||
* <b>Note: As of Spring 3.0, this exporter requires Hessian 3.2 or above.</b>
|
||||
*
|
||||
* <p>Note: Hessian services exported with this class can be accessed by
|
||||
* <p>Hessian services exported with this class can be accessed by
|
||||
* any Hessian client, as there isn't any special handling involved.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,7 +63,7 @@ public class SimpleBurlapServiceExporter extends BurlapExporter implements HttpH
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
exchange.sendResponseHeaders(500, -1);
|
||||
throw new IOException("Burlap skeleton invocation failed", ex);
|
||||
logger.error("Burlap skeleton invocation failed", ex);
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, output.size());
|
||||
|
||||
@@ -33,9 +33,9 @@ import org.springframework.util.FileCopyUtils;
|
||||
* <p>Hessian is a slim, binary RPC protocol.
|
||||
* For information on Hessian, see the
|
||||
* <a href="http://www.caucho.com/hessian">Hessian website</a>.
|
||||
* This exporter requires Hessian 3.1.3 or above.
|
||||
* <b>Note: As of Spring 3.0, this exporter requires Hessian 3.2 or above.</b>
|
||||
*
|
||||
* <p>Note: Hessian services exported with this class can be accessed by
|
||||
* <p>Hessian services exported with this class can be accessed by
|
||||
* any Hessian client, as there isn't any special handling involved.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
@@ -63,7 +63,8 @@ public class SimpleHessianServiceExporter extends HessianExporter implements Htt
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
exchange.sendResponseHeaders(500, -1);
|
||||
throw new IOException("Hessian skeleton invocation failed", ex);
|
||||
logger.error("Hessian skeleton invocation failed", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
exchange.getResponseHeaders().set("Content-Type", CONTENT_TYPE_HESSIAN);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,7 +69,8 @@ public class SimpleHttpInvokerServiceExporter extends RemoteInvocationSerializin
|
||||
exchange.close();
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new IOException("Class not found during deserialization", ex);
|
||||
exchange.sendResponseHeaders(500, -1);
|
||||
logger.error("Class not found during deserialization", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user