早上好,我目前正在使用apache camel和Quarkus,我第一次遇到了一个以前从未发生过的场景,现在我正在使用以下类型的动态url来调用:
https://localhost:8080/users/{user}/customers
这些服务都在SSL中,因此必须配置对SSL的调用,对于非动态URL我使用了以下行:
.to(configureSsl.setupSSLContext(getCamelContext(), "https://localhost:8081/api/FindPrepaidAccountByDocument"))
我的ConfigureSSL类如下:
package org.tmve.customer.ms.route;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.component.http.HttpComponent;
import org.apache.camel.support.jsse.KeyManagersParameters;
import org.apache.camel.support.jsse.KeyStoreParameters;
import org.apache.camel.support.jsse.SSLContextParameters;
import org.apache.camel.support.jsse.TrustManagersParameters;
import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
import org.eclipse.microprofile.config.ConfigProvider;
@Slf4j
public class ConfigureSsl {
private String password = ConfigProvider.getConfig().getValue("client.password", String.class);
private String resource = ConfigProvider.getConfig().getValue("client.file", String.class);
public Endpoint setupSSLContext(CamelContext camelContext, String url) throws Exception {
KeyStoreParameters keyStoreParameters = new KeyStoreParameters();
/*log.info(resource);*/
/*log.info(password);*/
keyStoreParameters.setResource(resource);
keyStoreParameters.setPassword(password);
KeyManagersParameters keyManagersParameters = new KeyManagersParameters();
keyManagersParameters.setKeyStore(keyStoreParameters);
keyManagersParameters.setKeyPassword(password);
/*log.info("keyManagersParameters "+ keyManagersParameters);*/
TrustManagersParameters trustManagersParameters = new TrustManagersParameters();
trustManagersParameters.setKeyStore(keyStoreParameters);
/*log.info("trustManagersParameters "+ trustManagersParameters);*/
SSLContextParameters sslContextParameters = new SSLContextParameters();
sslContextParameters.setKeyManagers(keyManagersParameters);
sslContextParameters.setTrustManagers(trustManagersParameters);
/*log.info("sslContextParameters "+ sslContextParameters);*/
HttpComponent httpComponent = camelContext.getComponent("https", HttpComponent.class);
httpComponent.setSslContextParameters(sslContextParameters);
httpComponent.setX509HostnameVerifier(new AllowAllHostnameVerifier());
/*log.info("httpComponent "+ httpComponent); */
return httpComponent.createEndpoint(url);
}
}
但是现在对于动态url,我需要使用apache camel的toD方法来处理动态url,但是,我不知道如何在toD方法中配置动态url中的SSL部分,我用于非动态url to方法的方法在toD方法中不适用
我试着这样做,但它给了我一个错误的行:
.toD(configureSsl.setupSSLContext(getCamelContext(),"https://localhost:8080/users/${exchangeProperty[user_id]}/customers?bridgeEndpoint=true"))
在这种情况下,我可以做什么来使用toD方法将我的SSL配置添加到apache camel中的动态URL,否则我会得到以下错误:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
1条答案
按热度按时间vyswwuz21#
我不是一个Maven,但如果我记得这个问题发生时达到本地主机与SSL.在本例中,我将X509HostnameVerifier注册为NoopHostnameVerifier示例,并在Route中引用此示例。我想还有其他的方法来配置它。
https://github.com/apache/camel-quarkus/blob/main/integration-tests/platform-http-proxy-ssl/src/main/java/org/apache/camel/quarkus/component/platform/http/proxy/ssl/it/Routes.java
我希望这能帮上忙。