7.HessianExporter处理Hessian请求并将结果封装为HTTP响应:
[java] view plaincopyprint public class HessianExporter extends RemoteExporter implements InitializingBean { //Hessian HTTP响应内容类型 public static final String CONTENT_TYPE_HESSIAN = "application/x-hessian"; //Hessian序列化工厂 private SerializerFactory serializerFactory = new SerializerFactory(); //Hessian Debug日志 private Log debugLogger; //Hessian服务端框架 private HessianSkeleton skeleton; //设置Hessian序列化工厂 public void setSerializerFactory(SerializerFactory serializerFactory) { this.serializerFactory = (serializerFactory != null serializerFactory : new SerializerFactory()); } //设置序列化集合发送java集合类型 public void setSendCollectionType(boolean sendCollectionType) { this.serializerFactory.setSendCollectionType(sendCollectionType); } //设置Hessian调试模式 public void setDebug(boolean debug) { this.debugLogger = (debug logger : null); } //回调方法 public void afterPropertiesSet() { prepare(); } //初始化Hessian服务框架 public void prepare() { //这里调用父类RemoteExporter的方法检查服务提供类、服务接口 checkService(); checkServiceInterface(); //创建远程服务类的Hessian框架 this.skeleton = new HessianSkeleton(getProxyForService(), getServiceInterface()); } //远程调用处理入口 public void invoke(InputStream inputStream, OutputStream outputStream) throws Throwable { Assert.notNull(this.skeleton, "Hessian exporter has not been initialized"); doInvoke(this.skeleton, inputStream, outputStream); } //远程调用处理方法 protected void doInvoke(HessianSkeleton skeleton, InputStream inputStream, OutputStream outputStream) throws Throwable { //获取类加载器 ClassLoader originalClassLoader = overrideThreadContextClassLoader(); try { InputStream isToUse = inputStream; OutputStream osToUse = outputStream; //设置Hessian调试日志 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 =