Desabilitar validação de certificado em Java SSL Connetions JAX-RS


TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {

@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
// TODO Auto-generated method stub

}

@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
// TODO Auto-generated method stub

}

@Override
public X509Certificate[] getAcceptedIssuers() {
// TODO Auto-generated method stub
return null;
}
}
};

SSLContext sc = SSLContext.getInstance(“SSL”);
sc.init(null, trustAllCerts, new java.security.SecureRandom());
Client client = ClientBuilder.newBuilder().sslContext(sc).build();
WebTarget webTarget = client.target(url);
//Builder builder = webTarget.request();

String v = url;
log.info(“URL relatorioMedVs: “+url);
webTarget.request().async().post(Entity.json(json), new InvocationCallback() {

@Override
public void completed(Response response) {
if (response.getStatus() != 200) {
log.error(“Failed : HTTP error code : “+ response.getStatus());
}
String output = response.readEntity(String.class);
log.info(output);

}

@Override
public void failed(Throwable e) {
log.error(e);
}
});

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *