java - Remove filter from JAX RS client -


i needed add authorisation header outgoing requests client, , added clientrequestfilter instructed in this answer.

now want change properties of filter created. tried re-register new copy of filter didn't work. tried through available methods of client object didn't find de-register or remove.

sample code:

client client = clientbuilder.newclient().register(new clientobjectmapperprovider()); authtokenfilter authtokenfilter = new authtokenfilter(authtokenservice, authconfig);         client.register(authtokenfilter); //make requests   //in method in class authtokenfilter newfilter = new authtokenfilter(authtokenservice, newconfig); client.register(newfilter);  //make more requests 

when send requests after registering new filter, want auth header different according new config, that's not happening.

on further investigation seems client object not register object if of same type registered. still haven't found way de-register though.

creating client instances quite heavyweight don't want often, hence makes sense caching , reusing client instance.

if wish have separate authentication filter per targeted endpoint registration doesn't have done on client instance. before can talk need create webtarget (which represents concrete endpoint communicate) once you've created webtarget can register filter that.

configuring webtarget's can heavy weight (see here) mean can spawn (and cache) different authentication filters per targeted host.

if wanting dynamically reconfigure client/webtarget based on edited configuration (e.g. properties file/configuration rest endpoint) can have cache of webtarget/client instances regenerate scratch when configuration changes. (you need remember call client.close() before discarding old client instance)


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -