이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 6.  Configuring Transport Security for Camel Components


Abstract

Camel provides the Java Secure Socket Extension (JSSE) Utility API as a common way to configure Camel components to use Transport Layer Security (TLS). The main JSSE utility class is org.apache.util.jsse.SSLContextParameters. To configure TLS settings, you pass an instance of this class to a Camel component. You can configure an SSLContextParameters object by using pure Java or by using Spring or Blueprint XML.
The following code is an example of using Spring XML to configure an SSLContextParameters object:
<sslContextParameters id="sslContextParameters" xmlns="http://camel.apache.org/schema/spring">
   <keyManagers keyPassword="secret1">
      <keyStore resource="./my_keystore.jks" password="secret2" />
   </keyManagers>
   <trustManagers>
      <keyStore resource="./my_truststore.jks" password="secret2" />
   </trustManagers>
</sslContextParameters>
Copy to Clipboard Toggle word wrap
This shows the toplevel sslContextParameters element with keyManagers and trustManagers child elements. The keyManagers element configures the key store while the trustManagers element configures the trust store. For details about key stores and trust stores, see the Apache Camel documentation for the JSSE utility.
With this in place, you can reference the sslContextParameters bean in your endpoint URI. The following route runs a netty4 HTTPS endpoint. The ssl option is required. For example:
<route>
   <from uri="netty4:https://localhost:8080/early?sslContextParametersRef=#sslContextParameters&ssl=true"/>
   <transform>
      <constant>Hi</constant>
   </transform>
</route>
Copy to Clipboard Toggle word wrap
The following code provides an example of how to configure transport security in Java:
@Override
protected JndiRegistry createRegistry() throws Exception {
   KeyStoreParameters ksp = new KeyStoreParameters();
      ksp.setResource("./my_keystore.jks");
      ksp.setPassword("secret1");
   KeyManagersParameters kmp = new KeyManagersParameters();
      kmp.setKeyPassword("secret2");
      kmp.setKeyStore(ksp);
   KeyStoreParameters tsp = new KeyStoreParameters();
      tsp.setResource("./my_truststore.jks");
      tsp.setPassword("secret2");
   TrustManagersParameters tmp = new TrustManagersParameters();
      tmp.setKeyStore(tsp);
   SSLContextParameters sslContextParameters = new SSLContextParameters();
   sslContextParameters.setKeyManagers(kmp);
   sslContextParameters.setTrustManagers(tmp);
   JndiRegistry registry = super.createRegistry();
   registry.bind("sslContextParameters", sslContextParameters);

   return registry;
}
Copy to Clipboard Toggle word wrap
The Java route for a netty4 HTTPS endpoint looks like the following. The ssl option is required.
from("netty4:https://localhost:8080/early?sslContextParametersRef=
   #sslContextParameters&ssl=true").transform().constant("Hi");
Copy to Clipboard Toggle word wrap
In Camel, to call these HTTPS endpoints, also provide the sslContextParameters object that contains a trusted certificate. The following example reuses the server sslContextParameters object. In this example, the URI syntax is the same for the producer. For example:
String reply =       
      template.requestBody(
         "netty4:https://localhost:8080/early?ssl=true&sslContextParametersRef=
            sslContextParameters", "Hi Camel!", String.class);
Copy to Clipboard Toggle word wrap
If you do not provide an sslContextParameters object that contains a valid trust store then the server does not allow a connection and Camel throws an execution exception - CamelExecutionException.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat