Ever wonder how you can set up and hit a basic https endpoint with camel? These directions are sure to help!
First, configure your RouteBuilder. This RouteBuilder calls for two methods. Those will be defined down below. It then polls a jetty https endpoint. When the jetty endpoint gets a hit, it sends a request to https endpoint deployed elsewhere.
public class MyRouteBuilder extends RouteBuilder{ public void configure() { configureJetty(); configureHttp4(); from("jetty:https://0.0.0.0:8080/sample/?matchOnUriPrefix=true") .to("https4://example.com:8081/?q=ssl&bridgeEndpoint=true&throwExceptionOnFailure=false"); } }
Next, we need to define the SSL configuration for the jetty endpoint.
private void configureJetty() { KeyStoreParameters ksp = new KeyStoreParameters(); ksp.setResource("\Projects\example\myJks.jks"); ksp.setPassword("password"); KeyManagersParameters kmp = new KeyManagersParameters(); kmp.setKeyStore(ksp); kmp.setKeyPassword("keyPassword"); SSLContextParameters scp = new SSLContextParameters(); scp.setKeyManagers(kmp); JettyHttpComponent jettyComponent = getContext().getComponent("jetty", JettyHttpComponent.class); jettyComponent.setSslContextParameters(scp); }
Finally, we need to define the SSL configuration to send to the https endpoint.
private void configureHttp4() { KeyStoreParameters ksp = new KeyStoreParameters(); ksp.setResource("\Projects\example\exampleCa.jks"); ksp.setPassword("password"); TrustManagersParameters tmp = new TrustManagersParameters(); tmp.setKeyStore(ksp); SSLContextParameters scp = new SSLContextParameters(); scp.setTrustManagers(tmp); HttpComponent httpComponent = getContext().getComponent("https4", HttpComponent.class); httpComponent.setSslContextParameters(scp); }
Red Hat Software Collections are available for download, you can read more at Red Hat Software Collections.
Last updated: March 7, 2017