Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Basic Camel and HTTPS

DZone's Guide to

Basic Camel and HTTPS

In this very quick tutorial, Red Hat developer, and MVB, Mary Cochran shows you how to set up and hit basic HTTPS endpoints with Camel.

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
web dev ,camel ,https ,ssl

Published at DZone with permission of Mary Cochran, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}