java - Disabling hostname verification -
our web application calls several web services internally using jersey client api. few services secure , use certificates authenticate.
due reasons want disable hostname verification on few services.
so searched examples , found below links , service started working expected after disabling verification.
while going through third link noticed call httpsurlconnection.setdefaulthostnameverifier(allhostsvalid);
i assuming that, because of above call, hostname verification disabled on subsequent web service calls.
if assumption right, how disable verification on particular service?
hostnameverifier allhostsvalid = new hostnameverifier() { public boolean verify(string hostname, sslsession session) { if(hostname.equals("xyz")) { return true; } else { // how implement section? // if return false server perform verification? if not how implement this? } } };
in you're using httpsurlconnection directly once you've opened connection (with url.openconnection()) can call connection.sethostnameverifier(allhostsvalid) set hostname verifier single connection.
edit:
as you're using jersey, looks there 2 options depending on whether you're using jersey 1 or 2.
for jersey 2 can set hostname verifier on clientbuilder when create client.
clientbuilder.newbuilder().hostnameverifier(allhostsvalid).build(); you'd want make 2 clients , use different 1 depending on service connecting to. however, there warning in jersey docs noting that works connector providers, , i'm not sure you'd using.
this standard api should work compliant jax-rs 2.0 client (including liberty's jaxrsclient-2.0 feature).
for jersey 1 looks can set property on client or on client request.
httpsproperties httpsprops = new httpsproperties(allhostsvalid); client.getproperties().put(httpsproperties.property_https_properties, httpsprops);
Comments
Post a Comment