spring - Add proxy information and basic auth to the resttemplate using httpClient -


my development environment behind proxy need set proxy information rest template, that's when use httpcomponentsclienthttprequestfactory , set proxy setting in httpclient , set in template.

but have rest service needs basic auth. , set basic auth credentials, need set them in httpclient on rest template. see getparams method in httpclient depricated, can't update existing client in template, , if create new httpclient object, overwrite proxy info set during application bootstrapping.

so there way extract httpclient rest template , update it? or there other way tackle this?

thanks.

configure httpclient follows:

httphost target = new httphost("hostname", 80, "http"); credentialsprovider credsprovider = new basiccredentialsprovider(); credsprovider.setcredentials(         new authscope(target.gethostname(), target.getport()),         new usernamepasswordcredentials("user", "passwd"));  httphost proxy = new httphost("proxy", 12345); closeablehttpclient httpclient = httpclients.custom()         .setproxy(proxy)         .setdefaultcredentialsprovider(credsprovider).build();  httpcomponentsclienthttprequestfactory requestfactory = new httpcomponentsclienthttprequestfactory(); requestfactory.sethttpclient(httpclient);  resttemplate resttemplate = new resttemplate(requestfactory); 

see httpclient examples


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -