简体   繁体   中英

RESTful service client with data-driven credentials not working

I'm using Spring 4's RestTemplate with Jakarta's HttpComponents 4.3 to implement a client for a remote web service. The client uses Basic Auth over a secured circuit. Everything has been running great, but now we're upgrading to a mode where the username for the connection will vary depending on the contents of the request.

So far, PoolingHttpClientConnectionManager seems to ignore credentials when determining whether an existing connection is valid for a new connection request - it looks strictly at the route. So the first invocation of the remote service works great. The second invocation comes back with "invalid credentials". Examining the logs shows both invocations use identical Authentication headers.

Any suggestions on how to handle this? I had hoped PoolingHttpClientConnectionManager would support named pools, effectively allowing to use the username as the pool name. That doesn't seem to be the case. I tried using multiple PoolingHttpClientConnectionManager objects, but the actual pool of connections is shared.

So coming back to this 10 months later, because who likes an unanswered question?

We ended up a creating a separate PoolingHttpClientConnectionManager for each possible set of credentials. Not a beautiful technical solution, but it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM