0

我正在尝试使用 SSL 安全的 Spring/Java Hessian 服务。

问题:没有在哪里可以找到示例如何设置 SSL 以通过我的客户端证书:(

非常感谢这里的任何帮助。

服务器设置

  1. 使用 Jetty 应用程序公开 Hessian 服务,如下所示。
  2. 以下“预订”服务在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;
        }
    }
4

1 回答 1

0
  1. HessianProxyFactory 是返回目标代理服务的那个。
  2. HessianProxyFactory 有方法 createHessianConnectionFactory() 返回 HessianURLConnectionFactory。
  3. HessianURLConnectionFactory 是构建目标HessianURLConnection(内部使用Java URLConnection)。
  4. HessianURLConnectionFactory 类型decided on runtime基于 System.property。以下是来自 HessianProxyFactory.class 的示例代码
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. 想法是返回构建 SSL 集成 URLConnection 的 Custom HessianURLConnectionFactory。
于 2019-07-25T12:03:00.913 回答