Java 如何 - Spring 使用 SSL 的 Caucho Hessian 客户端

Java How to - Spring Caucho Hessian Client with SSL

我正在尝试使用受保护的 SSL Spring/Java Hessian 服务。

问题: 找不到示例我如何设置 SSL 来传递我的客户端证书:(

非常感谢您的帮助。

服务器设置

  1. 使用 Jetty 应用程序公开 Hessian 服务,如下所示。
  2. 以下 "booking" 服务公开于 https://super.server/service/booking
  3. 在请求到达 Java Web 应用程序之前,它会通过一个 Web 服务器,在该服务器上请求使用 SSL 进行保护。 如果通过,则仅将其转发到 Hessian 服务之后的 Java Web 应用程序托管。
    @Bean(name = "/booking") 
    RemoteExporter bookingService() {
        HessianServiceExporter exporter = new HessianServiceExporter();
        exporter.setService(new CabBookingServiceImpl());
        exporter.setServiceInterface( CabBookingService.class );
        return exporter;
    }

客户端设置

  1. 在这里我必须以某种方式访问​​ https URL 即设置 SSL。
  2. 我知道如何为 HttpCleint 做这件事。
  3. 我在内部也知道甚至 Hessian 也在使用 URLConnection。而且我确信这里有一种更简单的方法来连接 ssl。
    @Configuration
    public class HessianClient {
        @Bean
        public HessianProxyFactoryBean hessianInvoker() {
            HessianProxyFactoryBean invoker = new HessianProxyFactoryBean();
            invoker.setServiceUrl("https://super.server/booking");
            invoker.setServiceInterface(CabBookingService.class);
            return invoker;
        }
    }
  1. HessianProxyFactory 是 return 的目标代理服务。
  2. HessianProxyFactory 有方法 createHessianConnectionFactory() returning HessianURLConnectionFactory。
  3. HessianURLConnectionFactory 是构建目标 HessianURLConnection(内部使用 Java URLConnection)。
  4. HessianURLConnectionFactory 类型是 decided on runtime 基于 System.property。以下是 HessianProxyFactory.class
  5. 中的示例代码
Class HessianProxyFactory{
    protected HessianConnectionFactory createHessianConnectionFactory(){
        String className= System.getProperty(HessianConnectionFactory.class.getName());
        HessianConnectionFactory factory = null;
        try {
          if (className != null) {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            Class<?> cl = Class.forName(className, false, loader);
            factory = (HessianConnectionFactory) cl.newInstance();
            return factory;
          }
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        return new HessianURLConnectionFactory();
    }
}
  1. 想法是 return 构建 SSL 集成 URLConnection 的自定义 HessianURLConnectionFactory。