I'm looking into this, but I don't see the issue in the code (2.8-SNAPSHOT). 
The producer cache uses the endpoint URI as the key and this is unique
because the user/password are part of the URI...

I wrote a simple unit test and it is instantiating a different producer for
each unique endpoint URI, etc.  Can you provide a unit test that fails or
perhaps more details about the issue?


manoj.sahu wrote:
> 
> After further analysis, it appears to me as a bug in apache camel.  
> 
> The bug remains in ProducerCache.doGetProducer() where a producer is
> instantiated or retrieved from the cache. At the time of instantiating
> producer everything is initialized properly.
> 
> Basically ProducerCache caches the Producers.  However when it retrieves
> the producer from the cache it ignores the fact that the producer may have
> stale credential. 
> 
> In other words following endpoints will potentially use the same 
> producer:
> https://host/ssl-gateway?authMethod=Basic&authUsername=user1&authPassword=pwd1
> https://host/ssl-gateway?authMethod=Basic&authUsername=user2&authPassword=pwd2
> 
> I have patched the ProducerCache to fix this problem locally. Here is the
> fix I have put.  This gets executed when the producer is retrieved from
> the cache.
> 
>     protected synchronized Producer doGetProducer(Endpoint endpoint,
> boolean pooled) {
>         String key = endpoint.getEndpointUri();
>         Producer answer = producers.get(key);
>         if (pooled && answer == null) {
>             // try acquire from connection pool
>             answer = pool.acquire(endpoint);
>         }
> 
>         if (answer == null) {
>             // create a new producer
>             try {
>                 answer = endpoint.createProducer();
>                 // must then start service so producer is ready to be used
>                 ServiceHelper.startService(answer);
>             } catch (Exception e) {
>                 throw new FailedToCreateProducerException(endpoint, e);
>             }
> 
>             // add producer to cache or pool if applicable
>             if (pooled && answer instanceof ServicePoolAware) {
>                 if (LOG.isDebugEnabled()) {
>                     LOG.debug("Adding to producer service pool with key: "
> + endpoint + " for producer: " + answer);
>                 }
>                 answer = pool.addAndAcquire(endpoint, answer);
>             } else if (answer.isSingleton()) {
>                 if (LOG.isDebugEnabled()) {
>                     LOG.debug("Adding to producer cache with key: " +
> endpoint + " for producer: " + answer);
>                 }
>                 producers.put(key, answer);
>             }
>         } else {
> *// PATCH BEGIN
> *             if (endpoint instanceof HttpEndpoint && answer instanceof
> HttpProducer){
>                       if (((HttpEndpoint)endpoint).getHttpClientConfigurer() 
> != null){
>               
> ((HttpEndpoint)endpoint).getHttpClientConfigurer().configureHttpClient(((HttpProducer)answer).getHttpClient());
>    
>                       LOG.debug("Patched ProducerCache : " + " Refreshing the
> authentication credential for the cached HTTP producer");
>                       }
>               }
>         }
> *// PATCH END
> *        return answer;
>     }
> 
>  
> I am not happy about the patch due to the coupling of HttpEndpoint and
> HttpProducer classes with the ProducerCache.  But I could not get it to
> work otherwise.   I tried putting the fix in HttpEndpoint but it did not
> work consistently.  
> 
> Claus/Ashwin, should this be treated as a bug? Can this be addressed in
> the future version of the camel.  I am using version 2.4.0. However, I
> checked the code from the latest version and it seems that the problem
> exists.  I am sure that there is a better place other than ProducerCache
> where the fix can be addressed.
> 
> Thanks
> 


-----
Ben O'Day
IT Consultant -http://consulting-notes.com

--
View this message in context: 
http://camel.465427.n5.nabble.com/Multiple-remote-connection-to-the-same-host-but-different-users-tp4309456p4515210.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to