How to configure camel jetty producer endpoint to use SSL certificate

1.2k views Asked by At

Camel jetty endpoint allows several SSL options, but only applicable to consumer (i.e. server side). See Apache Camel Jetty

Is there a way to force the producer to use the certificate without writing a bunch of codes? The remote server requires client authentication.

1

There are 1 answers

0
Khoa Nguyen On

Looks like coding is the only option. There are two choices that I've tried: configure SSL to (1) JettyComponent or (2) https4 component.

def configJetty = {
  println("Configuring Jetty component...")

  val ksp = new KeyStoreParameters()
  ksp.setResource(keyStore)
  ksp.setPassword(keyPassword)

  val kmp = new KeyManagersParameters()
  kmp.setKeyStore(ksp)
  kmp.setKeyPassword(keyPassword)

  val scp = new SSLContextParameters()
  scp.setKeyManagers(kmp)

  val jettyComponent = camelContext.getComponent("jetty").asInstanceOf[JettyHttpComponent]
  jettyComponent.setSslContextParameters(scp)

}

Or

def configHttps4 = {
  println("Configuring HTTPS4 component...")

  val ksp = new KeyStoreParameters()
  ksp.setResource(keyStore)
  ksp.setPassword(keyPassword)

  val tsp = new KeyStoreParameters()
  tsp.setResource(trustStore)
  tsp.setPassword(trustPassword)


  val kmp = new KeyManagersParameters()
  kmp.setKeyStore(ksp)
  kmp.setKeyPassword(keyPassword)

  val tmp = new TrustManagersParameters()
  tmp.setKeyStore(tsp)

  val scp = new SSLContextParameters()
  scp.setKeyManagers(kmp)
  scp.setTrustManagers(tmp)

  val httpComponent = camelContext.getComponent("https4").asInstanceOf[HttpComponent]
  httpComponent.setSslContextParameters(scp)

}

Then the endpoint URL can be:

https4://somewhere.com

or

jetty:https://somewhere.com

Note: with the above code, jetty component won't be able to speak clear HTTP anymore.