Я пытаюсь подключиться к внешней конечной точке https с помощью компонента Camel https4 через прокси.
Для этого я настраиваю прокси-сервер squid в Linux (18.04).
Согласно ссылкам [http://camel.apache.org/http4.html], я отметил, что это можно сделать, используя параметры proxyAuthHost и proxyAuthPort.
Поэтому я попытался проверить это с помощью указанного URL-адреса. как показано ниже
Я пытаюсь подключиться к внешней конечной точке https с помощью компонента Camel https4 через прокси. Для этого я настраиваю прокси-сервер squid в Linux (18.04).
Согласно ссылкам [http://camel.apache.org/http4.html], я отметил, что это можно сделать, используя параметры proxyAuthHost и proxyAuthPort. Поэтому я попытался проверить это с помощью указанного URL-адреса. как показано ниже
Но это дает "[code]javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?[/code]" непрерывно. Я попробовал несколько способов, как указано ниже, но результат тот же.
Может ли кто-нибудь подсказать по этому поводу, исходя из вашего опыта/знаний?
[b]Попытка 1:[/b] Использование PoolingHttpClientConnectionManager
Код:
[code]@ApplicationScoped @ContextName("camel_cdi_context") public class HTTPRouter extends RouteBuilder {
@Override public void configure() throws Exception {
errorHandler(deadLetterChannel("direct:error"));
try {
SSLContext sslContext = new SSLContextBuilder() .loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { System.out.println("HTTPRouter.configure().new TrustStrategy() {...}.isTrusted()"); return true; } }) .build();
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);
@Override public void configureHttpClient(HttpClientBuilder builder) {
builder.setSSLSocketFactory(sslsf);
System.out.println("HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient()-1"); Registry r = RegistryBuilder.create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslsf) .build(); System.out.println("HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient()-2"); HttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(r); System.out.println("HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient()-3"); builder.setConnectionManager(cm); System.out.println("HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient()-4"); } });
} catch (Exception e) { e.printStackTrace(); }
from("direct:http") // prepare request payload // set url to header // set other connection properties (eg : Connection Method, Header etc) .choice() .when(header("url").contains("?")) .toD("${header.url}&throwExceptionOnFailure=false") .endChoice() .otherwise() .toD("${header.url}?throwExceptionOnFailure=false") .endChoice() .end() .convertBodyTo(String.class) // process on the response
}
} [/code]
Журнал:
[code][org.apache.camel.component.http4.HttpComponent] Created ClientConnectionManager org.apache.http.impl.conn.PoolingHttpClientConnectionManager@2516c8e0 [stdout] HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient()-1 [stdout] HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient()-2 [stdout] HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient()-3 [stdout] HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient()-4 [org.apache.http.client.protocol.RequestAddCookies] CookieSpec selected: default [org.apache.http.client.protocol.RequestAuthCache] Auth cache not set in the context [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection request: [route: {tls}->https://192.168.xxx.xxx:xxxx->https://endpoint-ssl-url.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection leased: [id: 10][route: {tls}->https://192.168.xxx.xxx:xxxx->https://endpoint-ssl-url.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20] [org.apache.http.impl.execchain.MainClientExec] Opening connection {tls}->https://192.168.xxx.xxx:xxxx->https://endpoint-ssl-url.com:443 [org.apache.http.impl.conn.DefaultHttpClientConnectionOperator] Connecting to /192.168.xxx.xxx:xxxx [org.apache.http.conn.ssl.SSLConnectionSocketFactory] Connecting socket to /192.168.xxx.xxx:xxxx with timeout 0 [org.apache.http.conn.ssl.SSLConnectionSocketFactory] Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2] [org.apache.http.conn.ssl.SSLConnectionSocketFactory] Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, MORE_CIPHERS ...] [org.apache.http.conn.ssl.SSLConnectionSocketFactory] Starting handshake [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-30: Shutdown connection [org.apache.http.impl.execchain.MainClientExec] Connection discarded [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection released: [id: 10][route: {tls}->https://192.168.xxx.xxx:xxxx->https://endpoint-ssl-url.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] [ERROR] Exchange[Id: ID-xxxx-xxx-37655-1534782529403-63-2, ExchangePattern: InOnly, Properties: {CamelCreatedTimestamp=Tue Aug 21 01:54:27 UTC 2018, CamelExceptionCaught=javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?, CamelFailureEndpoint=https4://endpoint-ssl-url.com/path/to/resource?proxyAuthPort=xxxx&throwExceptionOnFailure=false&proxyAuthHost=192.168.xxx.xxx, CamelFailureRouteId=route221, CamelFatalFallbackErrorHandler=[route221], CamelFilterMatched=true, CamelMessageHistory=[REMOVED...], CamelToEndpoint=log://ERROR?showAll=true}, Headers: {Accept=application/json, Accept-Encoding=gzip, Authorization=Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==, breadcrumbId=ID-xxxxx-xxx-37655-1534782529403-63-1, CamelFileName=null, CamelFileNameProduced=/xxxxxx/path/to/payloads/2018-08-21/message-id-x-[EXT-Request]-2018-08-21-015427600.json, CamelHttpMethod=POST, Content-Type=application/x-www-form-urlencoded, doLogFiles=true, dontLogErrorFiles=false, messageId=message-id-x, messageName=message-name-x, routeId=direct-http, specialRq=true, specialRs=true, url=https4://endpoint-ssl-url.com/path/to/resource?proxyAuthPort=xxxx&proxyAuthHost=192.168.xxx.xxx}, BodyType: String, Body: grant_type=client_credentials&scope=DUMMYSCOPE, CaughtExceptionType: javax.net.ssl.SSLException, CaughtExceptionMessage: Unrecognized SSL message, plaintext connection?, StackTrace: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:710) at sun.security.ssl.InputRecord.read(InputRecord.java:527) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:389) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) at org.apache.camel.component.http4.HttpProducer.executeMethod(HttpProducer.java:334) at org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:193) [/code]
[b]Попытка 2:[/b] использование BasicHttpClientConnectionManager
Код:
[code]@ApplicationScoped @ContextName("camel_cdi_context") public class HTTPRouter extends RouteBuilder {
@Override public void configure() throws Exception {
errorHandler(deadLetterChannel("direct:error"));
try {
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { System.out.println("HTTPRouter.configure()"); return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } };
SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { System.out.println("HTTPRouter.configure().new HostnameVerifier() {...}.verify()"); return true; } };
final SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext,new String[]{"TLSv1.2", "TLSv1.1", "TLSv1", "SSLv3"}, null, allHostsValid);
from("direct:http") // prepare request payload // set url to header // set other connection properties (eg : Connection Method, Header etc) .choice() .when(header("url").contains("?")) .toD("${header.url}&throwExceptionOnFailure=false") .endChoice() .otherwise() .toD("${header.url}?throwExceptionOnFailure=false") .endChoice() .end() .convertBodyTo(String.class) // process on the response
}
} [/code]
Журнал:
[code][org.apache.camel.component.http4.HttpComponent] Created ClientConnectionManager org.apache.http.impl.conn.PoolingHttpClientConnectionManager@2bb0862 [stdout] HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient() - 1 [stdout] HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient() - 2 [stdout] HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient() - 3 [stdout] HTTPRouter.configure().new HttpClientConfigurer() {...}.configureHttpClient() - 4 [org.apache.http.client.protocol.RequestAddCookies] CookieSpec selected: default [org.apache.http.client.protocol.RequestAuthCache] Auth cache not set in the context [org.apache.http.impl.conn.BasicHttpClientConnectionManager] Get connection for route {tls}->https://192.168.xxx.xxx:xxxx->https://endpoint-ssl-url.com:443 [org.apache.http.impl.execchain.MainClientExec] Opening connection {tls}->https://192.168.xxx.xxx:xxxx->https://endpoint-ssl-url.com:443 [org.apache.http.impl.conn.DefaultHttpClientConnectionOperator] Connecting to /192.168.xxx.xxx:xxxx [org.apache.http.conn.ssl.SSLConnectionSocketFactory] Connecting socket to /192.168.xxx.xxx:xxxx with timeout 0 [org.apache.http.conn.ssl.SSLConnectionSocketFactory] Enabled protocols: [SSLv3, TLSv1, TLSv1.1, TLSv1.2] [org.apache.http.conn.ssl.SSLConnectionSocketFactory] Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, MORE_CIPHERS ...] [org.apache.http.conn.ssl.SSLConnectionSocketFactory] Starting handshake [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-31: Shutdown connection [org.apache.http.impl.execchain.MainClientExec] Connection discarded [org.apache.http.impl.conn.BasicHttpClientConnectionManager] Releasing connection [Not bound] [ERROR] Exchange[Id: ID-xxxxx-xxx-37655-1534782529403-65-2, ExchangePattern: InOnly, Properties: {CamelCreatedTimestamp=Tue Aug 21 01:58:30 UTC 2018, CamelExceptionCaught=javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?, CamelFailureEndpoint=https4://endpoint-ssl-url.com/path/to/resource?proxyAuthPort=xxxx&throwExceptionOnFailure=false&proxyAuthHost=192.168.xxx.xxx, CamelFailureRouteId=route228, CamelFatalFallbackErrorHandler=[route228], CamelFilterMatched=true, CamelMessageHistory=[REMOVED...], CamelToEndpoint=log://ERROR?showAll=true}, Headers: {Accept=application/json, Accept-Encoding=gzip, Authorization=Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, breadcrumbId=ID-namal-pc-37655-1534782529403-65-1, CamelFileName=null, CamelFileNameProduced=/xxxxxx/path/to/payloads/2018-08-21/message-id-x-[EXT-Request]-2018-08-21-015830349.json, CamelHttpMethod=POST, Content-Type=application/x-www-form-urlencoded, doLogFiles=true, dontLogErrorFiles=false, messageId=message-id-x, messageName=message-name-x, routeId=direct-http, specialRq=true, specialRs=true, url=https4://endpoint-ssl-url.com/path/to/resource?proxyAuthPort=xxxx&proxyAuthHost=192.168.xxx.xxx}, BodyType: String, Body: grant_type=client_credentials&scope=DUMMYSCOPE, CaughtExceptionType: javax.net.ssl.SSLException, CaughtExceptionMessage: Unrecognized SSL message, plaintext connection?, StackTrace: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:710) at sun.security.ssl.InputRecord.read(InputRecord.java:527) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) at org.apache.http.impl.conn.BasicHttpClientConnectionManager.connect(BasicHttpClientConnectionManager.java:323) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:389) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) at org.apache.camel.component.http4.HttpProducer.executeMethod(HttpProducer.java:334) at org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:193) [/code]
[b]Попытка 3:[/b] сочетание двух вышеуказанных подходов Результат: то же исключение
[b]Попытка 4:[/b] Использование с Httpurlconnection Я выполнил это в качестве контролируемого теста, и все получилось. Код:
Я пытаюсь подключиться к внешней конечной точке HTTPS с использованием компонента Camel HTTPS4 через прокси.
для этого я настройка Squid Proxy в Linux (18.04).
Согласно ссылкам [ proxyauthhost и proxyauthport params.
Поэтому я попытался проверить...
Я хочу отправлять свои подключения Camel через прокси-сервер Burp Suite. Я импортировал свой сертификат Burp Suite в cacerts.
Таким образом, следующий пример работает: запрос появляется в Burp Suite, и программа завершается без ошибок.
public...