javaspringsslcertificatecaucho

Java How to - Spring Caucho Hessian Client with SSL


I am trying to consume SSL secured Spring/Java Hessian Service.

Problem: No where I could find an example how can I setup SSL to pass my client certificate :(

Any help here is most appreciated.

Server Setup

  1. With Jetty Application am exposing Hessian service like following.
  2. Following "booking" Service is exposed on https://super.server/service/booking.
  3. Here before request reaching Java Web Application, it goes through a Web Server where the request is secured with SSL. If passed, than only its forwarded to Java Web application hosting following Hessian Service.
    @Bean(name = "/booking") 
    RemoteExporter bookingService() {
        HessianServiceExporter exporter = new HessianServiceExporter();
        exporter.setService(new CabBookingServiceImpl());
        exporter.setServiceInterface( CabBookingService.class );
        return exporter;
    }

Client Setup

  1. Here somehow I have to access a https URL i.e. Setup an SSL.
  2. I know how to do it for HttpCleint.
  3. I as well know internally even Hessian is using URLConnection. And I am sure there is a easier way to hook ssl in here.
    @Configuration
    public class HessianClient {
        @Bean
        public HessianProxyFactoryBean hessianInvoker() {
            HessianProxyFactoryBean invoker = new HessianProxyFactoryBean();
            invoker.setServiceUrl("https://super.server/booking");
            invoker.setServiceInterface(CabBookingService.class);
            return invoker;
        }
    }

Solution

    1. HessianProxyFactory is the one that returns target Proxy Service.
    2. HessianProxyFactory has method createHessianConnectionFactory() returning HessianURLConnectionFactory.
    3. HessianURLConnectionFactory is the building target HessianURLConnection (Internally uses Java URLConnection).
    4. HessianURLConnectionFactory type is decided on runtime based on System.property. Following is the sample code from 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. Idea is to return Custom HessianURLConnectionFactory that builds SSL integrated URLConnection's.