Apache http client with https proxy - apache-httpcomponents

I am using Apache HTTP Components HttpClient using the following code.
HttpAsyncClientBuilder builder = HttpAsyncClients.custom();
builder.setConnectionManager(manager);
builder.setRoutePlanner(planner)
.setDefaultCredentialsProvider(provider);
return builder.build();
And,
return new DefaultProxyRoutePlanner(new HttpHost("https", proxyHost, proxyPort));
The flow is like below,
http client -> https proxy(with auth) -> https endpoint
The code makes a successful connection to the proxy but ends up with the below TLS error.
.c.h.i.a.InternalAbstractHttpAsyncClient : ex-0000000001 preparing request execution
o.a.h.c.h.p.RequestAddCookies : ex-0000000001 Cookie spec selected: strict
o.a.h.c.h.p.RequestAuthCache : ex-0000000001 Re-using cached 'Basic' auth scheme for https://proxy.host:3128
o.a.h.c.h.i.a.AsyncProtocolExec : ex-0000000001 target auth state: UNCHALLENGED
o.a.h.c.h.i.a.AsyncConnectExec : ex-0000000001 acquiring connection with route {tls}->https://proxy.host:3128->https://api.host:443
o.a.h.c.h.i.a.InternalHttpAsyncClient : ex-0000000001 acquiring endpoint (3 MINUTES)
.i.n.PoolingAsyncClientConnectionManager : ex-0000000001 endpoint lease request (3 MINUTES) [route: {tls}->https://proxy.host:3128->https://api.host:443][total available: 0; route allocated: 0 of 5; total allocated: 0 of 25]
.i.n.PoolingAsyncClientConnectionManager : ex-0000000001 endpoint leased [route: {tls}->https://proxy.host:3128->https://api.host:443][total available: 0; route allocated: 1 of 5; total allocated: 1 of 25]
.i.n.PoolingAsyncClientConnectionManager : ex-0000000001 acquired ep-0000000000
o.a.h.c.h.i.a.InternalHttpAsyncClient : ex-0000000001 acquired endpoint ep-0000000000
o.a.h.c.h.i.a.InternalHttpAsyncClient : ep-0000000000 connecting endpoint (3 MINUTES)
.i.n.PoolingAsyncClientConnectionManager : ep-0000000000 connecting endpoint to https://proxy.host:3128 (3 MINUTES)
.a.h.c.h.i.n.MultihomeIOSessionRequester : https://proxy.host:3128 resolving remote address
.a.h.c.h.i.n.MultihomeIOSessionRequester : https://proxy.host:3128 resolved to [proxy.host/XX.XX.XX.XX, proxy.host/10.XX.XX.88]
.a.h.c.h.i.n.MultihomeIOSessionRequester : https://proxy.host:3128 connecting null to proxy.host/XX.XX.XX.XX:3128 (3 MINUTES)
o.a.h.c.r.IOSessionImpl : c-0000000000[ACTIVE][rc:c] protocol upgrade class org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiator
.a.h.c.h.i.n.MultihomeIOSessionRequester : https://proxy.host:3128 connected c-0000000000 /XXX.XX.XX.XXX:44774->proxy.host/XX.XX.XX.XX:3128
.i.n.DefaultManagedAsyncClientConnection : c-0000000000 start TLS
.i.n.PoolingAsyncClientConnectionManager : ep-0000000000 connected c-0000000000
o.a.h.c.h.i.a.InternalHttpAsyncClient : ep-0000000000 endpoint connected
o.a.h.c.h.i.a.AsyncConnectExec : ex-0000000001 connected to proxy
o.a.h.c.h.i.a.AsyncConnectExec : ex-0000000001 create tunnel
o.a.h.c.h.i.a.HttpAsyncMainClientExec : ex-0000000001 executing CONNECT api.host:443 HTTP/1.1
o.a.h.c.h.i.a.InternalHttpAsyncClient : ep-0000000000 start execution ex-0000000001
.i.n.PoolingAsyncClientConnectionManager : ep-0000000000 executing exchange ex-0000000001 over c-0000000000
.i.n.DefaultManagedAsyncClientConnection : c-0000000000 RequestExecutionCommand with NORMAL priority
o.a.h.c.r.s.SSLIOSession : c-0000000000[ACTIVE][rwc:c][ACTIVE][rw][NOT_HANDSHAKING][0][0][0] Enqueued RequestExecutionCommand with priority IMMEDIATE
o.a.h.c.r.s.SSLIOSession : c-0000000000[ACTIVE][rw:c][ACTIVE][rw][NOT_HANDSHAKING][0][0][0] Event cleared [c]
o.a.h.c.r.s.SSLIOSession : c-0000000000[ACTIVE][r:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][0] protocol upgrade class org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler
o.a.h.c.h.i.a.HttpAsyncMainClientExec : ex-0000000001 send request CONNECT api.host:443 HTTP/1.1, null entity
o.a.h.c.h.headers : c-0000000000 >> CONNECT api.host:443 HTTP/1.1
o.a.h.c.h.headers : c-0000000000 >> Host: api.host:443
o.a.h.c.h.headers : c-0000000000 >> User-Agent: Apache-HttpAsyncClient/5.1.3 (Java/17.0.4)
o.a.h.c.h.headers : c-0000000000 >> Proxy-Authorization: Basic <token>
o.a.h.c.r.s.SSLIOSession : c-0000000000[ACTIVE][r:r][ACTIVE][rw][NOT_HANDSHAKING][0][0][347] 318 bytes written
.
.
.
o.a.h.c.r.s.SSLIOSession : c-0000000000[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][68][39][0] 0 bytes read
o.a.h.c.h.headers : c-0000000000 << HTTP/1.1 200 Connection established
o.a.h.c.h.i.a.HttpAsyncMainClientExec : ex-0000000001 consume response HTTP/1.1 200 Connection established, null entity
o.a.h.c.h.i.a.AsyncConnectExec : ex-0000000001 tunnel to target created
o.a.h.c.h.i.a.InternalHttpAsyncClient : ep-0000000000 upgrading endpoint
.i.n.DefaultManagedAsyncClientConnection : c-0000000000 start TLS
o.a.h.c.h.i.a.HttpAsyncMainClientExec : ex-0000000001 execution failed: TLS already activated
.c.h.i.a.InternalAbstractHttpAsyncClient : ex-0000000001 request failed: TLS already activated
.i.n.PoolingAsyncClientConnectionManager : ep-0000000000 close IMMEDIATE
.i.n.DefaultManagedAsyncClientConnection : c-0000000000 Shutdown connection IMMEDIATE
o.a.h.c.r.s.SSLIOSession : c-0000000000[ACTIVE][r:r][ACTIVE][r][NOT_HANDSHAKING][0][0][0] Close IMMEDIATE
o.a.h.c.h.i.a.InternalHttpAsyncClient : ep-0000000000 endpoint closed
o.a.h.c.h.i.a.InternalHttpAsyncClient : ep-0000000000 discarding endpoint
.i.n.PoolingAsyncClientConnectionManager : ep-0000000000 releasing endpoint
.i.n.PoolingAsyncClientConnectionManager : ep-0000000000 connection released [route: {tls}->https://proxy.host:3128->https://api.host:443][total available:0; route allocated: 0 of 5; total allocated: 0 of 25]
Any pointers on whats going on here and how to go about the above flow?

Related

Rabbit mq 2.1.3 version

I am getting below error while consuming message on rabbit mq through fanout approach :
2022-08-24 12:53:29.559 ERROR 42 --- [2.20.43.29:5672] o.s.a.r.c.CachingConnectionFactory : Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'avitas.nodedata' in vhost 'avitas': received 'topic' but current is 'fanout', class-id=40, method-id=10)

Can't reach gRPC server exposed by a nginx ingress in kubernetes

I have a gRPC server exposed by an ingress.
Here are the nginx annotations I use :
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/backend-protocol: "GRPC"
I am able to request it using grpcurl :
grpcurl -d '<arg>:<value>' <address>:443 api.Service/Request
But when I use a basic golang program :
conn,_ := grpcconn.Dial("<address>:443",grpccon.WithInsecure())
api := apiService.NewServiceClient(conn)
res,err := api.Request(<parameters>)
if err!=nil {
log.Fatalf("Request failed : %v",err)
}
log.Println(res)
I get the error :
rpc error : code = Unavailable desc = connection closed

Handshake failed due to invalid Connection header [Keep-Alive]

I have a websocket project, develop it on Weblogic 12c and Spring MVC 5.1.0.RELEASE
When i running project on local tomcat, its working normally, but when trying to deploy on Weblogic, its gave below error. (Error only occurs with secure domain, when i tried to on http adress with ip its working good.)
Apr 09, 2021 2:28:57 PM org.springframework.web.socket.server.support.AbstractHandshakeHandler handleInvalidConnectHeader
SEVERE: Handshake failed due to invalid Connection header [Keep-Alive]
<Apr 9, 2021 2:28:57 PM GMT+03:00> <Error> <org.springframework.web.socket.server.support.DefaultHandshakeHandler> <BEA-000000> <Handshake failed due to invalid Connection header [Keep-Alive]>
My headers;
- Sec-WebSocket-Version : 13
- Sec-WebSocket-Key : MoTfrW6Iim1noQgYHlkeYQ==
- Upgrade : websocket
- Cookie : jwt=eyJhbGciO....
- Sec-WebSocket-Extensions : permessage-deflate; client_max_window_bits
- Host : infotest.infotech.com.tr
- ECID-Context : 1.005jsZwLhO_EoIWVLynJ8A0001Cy0000i2;kXjE
- Connection : Keep-Alive
- X-WebLogic-KeepAliveSecs : 30
- X-WebLogic-Force-JVMID : -414283189
- X-WebLogic-Request-ClusterInfo : true
My implementation something like;
#Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(new EchoHandler(), "/echo").addInterceptors(customHandshakeInterceptor())
.setAllowedOrigins("*");
}
Testing with;
wscat -c ws://localhost:8080/projectName/echo --no-color
any help ?
you need to change the value for Connection header to 'Upgrade';

Storm topology shuts down in Local cluster after running for few seconds

I have a very basic topology. Starting with KafkaSpout, it has 3 bolts. First bolt is CassandraWriterBolt to write data in Cassandra, remaining 2 other bolts read old data from Cassandra create another set of data by using new and old data and again insert that data into Cassandra.
I am running that topology in LocalCluster during development. It runs for few seconds and then it starts shutting down worker, executor etc. Finally it fails with Cassandra driver related exception -
java.lang.IllegalStateException: Could not send request, session is closed
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:696) ~[cassandra-driver-core-3.6.0.jar:na]
Other logs are -
[er Executor - 1] o.a.s.s.org.apache.zookeeper.ZooKeeper : Session: 0x100166ad36d0024 closed
[.0/0.0.0.0:2000] o.a.s.s.o.a.z.server.NIOServerCnxn : Unable to read additional data from client sessionid 0x100166ad36d0024, likely client has closed socket
[.0/0.0.0.0:2000] o.a.s.s.o.a.z.server.NIOServerCnxn : Closed socket connection for client /0:0:0:0:0:0:0:1:63890 which had sessionid 0x100166ad36d0024
[- 1-EventThread] o.a.s.s.org.apache.zookeeper.ClientCnxn : EventThread shut down for session: 0x100166ad36d0024
[tor-Framework-0] o.a.s.s.o.a.c.f.i.CuratorFrameworkImpl : backgroundOperationsLoop exiting
[:0 cport:2000):] o.a.s.s.o.a.z.s.PrepRequestProcessor : Processed session termination for sessionid: 0x100166ad36d0021
[er Executor - 4] o.a.s.s.org.apache.zookeeper.ZooKeeper : Session: 0x100166ad36d0021 closed
[.0/0.0.0.0:2000] o.a.s.s.o.a.z.server.NIOServerCnxn : Unable to read additional data from client sessionid 0x100166ad36d0021, likely client has closed socket
[.0/0.0.0.0:2000] o.a.s.s.o.a.z.server.NIOServerCnxn : Closed socket connection for client /0:0:0:0:0:0:0:1:63885 which had sessionid 0x100166ad36d0021
[- 4-EventThread] o.a.s.s.org.apache.zookeeper.ClientCnxn : EventThread shut down for session: 0x100166ad36d0021
[ SLOT_1027] org.apache.storm.ProcessSimulator : Begin killing process 1347f01d-7982-4141-9b9d-cac65a6e703d
[ SLOT_1027] org.apache.storm.daemon.worker.Worker : Shutting down worker forex-topology-1-1577152204 517f3306-5ad3-433b-82e1-b2d031779f0b 1027
[ SLOT_1027] org.apache.storm.daemon.worker.Worker : Terminating messaging context
[ SLOT_1027] org.apache.storm.daemon.worker.Worker : Shutting down executors
[ SLOT_1027] o.a.storm.executor.ExecutorShutdown : Shutting down executor __system:[-1, -1]
[xecutor[-1, -1]] org.apache.storm.utils.Utils : Async loop interrupted!
[ SLOT_1027] o.a.storm.executor.ExecutorShutdown : Shut down executor __system:[-1, -1]
[ SLOT_1027] o.a.storm.executor.ExecutorShutdown : Shutting down executor pairStrengthAccumulator:[8, 8]
[-executor[8, 8]] org.apache.storm.utils.Utils : Async loop interrupted!
[ SLOT_1027] o.a.s.cassandra.executor.AsyncExecutor : shutting down async handler executor
[ SLOT_1027] o.a.s.c.client.impl.DefaultClient : Try to close connection to cluster: cluster2
Following logs can be seen for 40 times -
[ main] o.a.storm.zookeeper.ClientZookeeper : Starting ZK Curator
[ main] o.a.s.s.o.a.c.f.i.CuratorFrameworkImpl : Starting
[ main] o.a.s.s.org.apache.zookeeper.ZooKeeper : Initiating client connection, connectString=localhost:2000/storm sessionTimeout=20000 watcher=org.apache.storm.shade.org.apache.curator.ConnectionState#4bcaa195
[ main] o.a.s.s.o.a.c.f.i.CuratorFrameworkImpl : Default schema
[localhost:2000)] o.a.s.s.org.apache.zookeeper.ClientCnxn : Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2000. Will not attempt to authenticate using SASL (unknown error)
[ main] o.a.storm.zookeeper.ClientZookeeper : Starting ZK Curator
[ main] o.a.s.s.o.a.c.f.i.CuratorFrameworkImpl : Starting
[.0/0.0.0.0:2000] o.a.s.s.o.a.z.s.NIOServerCnxnFactory : Accepted socket connection from /0:0:0:0:0:0:0:1:63756
[ main] o.a.s.s.org.apache.zookeeper.ZooKeeper : Initiating client connection, connectString=localhost:2000/storm sessionTimeout=20000 watcher=org.apache.storm.shade.org.apache.curator.ConnectionState#6bc24e72
[localhost:2000)] o.a.s.s.org.apache.zookeeper.ClientCnxn : Socket connection established to localhost/0:0:0:0:0:0:0:1:2000, initiating session
[.0/0.0.0.0:2000] o.a.s.s.o.a.z.server.ZooKeeperServer : Client attempting to establish new session at /0:0:0:0:0:0:0:1:63756
[ main] o.a.s.s.o.a.c.f.i.CuratorFrameworkImpl : Default schema
[localhost:2000)] o.a.s.s.org.apache.zookeeper.ClientCnxn : Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2000, sessionid = 0x100166ad36d0001, negotiated timeout = 20000
[ SyncThread:0] o.a.s.s.o.a.z.server.ZooKeeperServer : Established session 0x100166ad36d0001 with negotiated timeout 20000 for client /0:0:0:0:0:0:0:1:63756
[localhost:2000)] o.a.s.s.org.apache.zookeeper.ClientCnxn : Opening socket connection to server localhost/127.0.0.1:2000. Will not attempt to authenticate using SASL (unknown error)
[ain-EventThread] o.a.s.s.o.a.c.f.s.ConnectionStateManager : State change: CONNECTED
[localhost:2000)] o.a.s.s.org.apache.zookeeper.ClientCnxn : Socket connection established to localhost/127.0.0.1:2000, initiating session
[.0/0.0.0.0:2000] o.a.s.s.o.a.z.s.NIOServerCnxnFactory : Accepted socket connection from /127.0.0.1:63759
[.0/0.0.0.0:2000] o.a.s.s.o.a.z.server.ZooKeeperServer : Client attempting to establish new session at /127.0.0.1:63759
[ SyncThread:0] o.a.s.s.o.a.z.server.ZooKeeperServer : Established session 0x100166ad36d0002 with negotiated timeout 20000 for client /127.0.0.1:63759
[localhost:2000)] o.a.s.s.org.apache.zookeeper.ClientCnxn : Session establishment complete on server localhost/127.0.0.1:2000, sessionid = 0x100166ad36d0002, negotiated timeout = 20000
[ain-EventThread] o.a.s.s.o.a.c.f.s.ConnectionStateManager : State change: CONNECTED
[ main] o.a.storm.validation.ConfigValidation : task.heartbeat.frequency.secs is a deprecated config please see class org.apache.storm.Config.TASK_HEARTBEAT_FREQUENCY_SECS for more information.
Your main method does this:
public static void main(String[] args) {
ApplicationContext springContext = SpringApplication.run(CurrencyStrengthCalculatorApplication.class, args);
StormTopology topology = SpringBasedTopologyBuilder.getInstance().buildStormTopologyUsingApplicationContext(springContext);
LOG.info("Topology created successfully. Now starting it .............");
new LocalCluster().submitTopology("forext-topology", ImmutableMap.of(), topology);
}
submitTopology isn't a blocking call, it just submits the topology and returns. If you want to keep the program running for a while, you need to put in a sleep after the submit. Once the main method returns, the LocalCluster will begin shutting down.

Feign Client: How to log the server name which the request was sent to?

I am using a Feign Client to call a REST endpoint with success, and have logging turned on to FULL. This is helpfully shows me the request sent and the response received. However, I cannot see which server the request was sent to. It only shows me that it was POSTed to http://foo-service which is the name of the service, not the name of the server.
How can I log which server name this request was sent to?
This is what I see in the logs:
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] ---> POST http://foo-service/some-endoint HTTP/1.1
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Accept: application/json
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Content-Type: application/json
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Content-Length: 15
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar]
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] {"name":"John"}
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] ---> END HTTP (15-byte body)
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] <--- HTTP/1.1 200 (8ms)
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Transfer-Encoding: chunked
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] X-Application-Context: fooService:9006
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Date: Tue, 10 Oct 2017 09:25:36 GMT
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] Content-Type: application/json;charset=UTF-8
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar]
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] {"result":"Hello John"}
c.l.l.r.service.FooFeignClient : [FooFeignClient#bar] <--- END HTTP (23-byte body)
To turn on logging, I declare this bean:
#Bean
public feign.Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
We are using spring-cloud-netflix-core:1.1.0.M4
You will need to provide your own Logger to achieve this. The default Logger is very simple and logs the host before the request is sent. When using Ribbon the information will be available with the Response. If you override the logAndRebufferResponse method, the response.url property will be the entire url submitted, including host name.
protected Response logAndRebufferResponse(
String configKey,
Level logLevel,
Response response,
long elapsedTime) throws IOException {
/* ask the response for the request and log the uri */
log(response.request.url());
}
Enable logging via logback and set log level of debug or these classes
<logger name="com.netflix.loadbalancer.BaseLoadBalancer" level="DEBUG"/>
<logger name="com.netflix.loadbalancer.LoadBalancerContext" level="DEBUG"/>
<logger name="com.netflix.loadbalancer.reactive.LoadBalancerCommand" level="DEBUG"/>
I can see where each request is going (server:port) and request failed on which server
DEBUG [ c.a.m.c.f.CommonProducerClient][72] - [CommonProducerClient#findAllEmployee] ---> GET http://COMMON-PRODUCER/allemployee HTTP/1.1
DEBUG [ c.n.loadbalancer.LoadBalancerContext][492] - COMMON-PRODUCER using LB returned Server: localhost:7001 for request http:///allemployee
DEBUG [ c.n.l.reactive.LoadBalancerCommand][314] - Got error java.net.ConnectException: Connection refused: connect when executed on server localhost:7001
DEBUG [ c.n.l.reactive.LoadBalancerCommand][314] - Got error java.net.ConnectException: Connection refused: connect when executed on server localhost:7001
DEBUG [ c.n.l.reactive.LoadBalancerCommand][314] - Got error java.net.ConnectException: Connection refused: connect when executed on server localhost:7001
DEBUG [ c.n.loadbalancer.LoadBalancerContext][492] - COMMON-PRODUCER using LB returned Server: localhost:7003 for request http:///allemployee
DEBUG [ c.a.m.c.f.CommonProducerClient][72] - [CommonProducerClient#findAllEmployee] <--- HTTP/1.1 200 (4010ms)
From Logs its clear, first request went to port 7001, connection refused there, second request goes to 7003, all good there.

Resources