Does RESTeasy client support TLS / SSL?

I use several RESTful web services in a JAVA-based web application. I use the RESTeasy client to access my web service. Here, all the communication between the client and the service is done through XML (JAX-B xml annotated detail classes). Here are the following codes

String serviceURL = "https://service.company.com/Service/getService" ServiceRequestDetail serviceRequestDetail = getServiceRequestAsDetailClass(); ServiceResponseDetail serviceResponseDetail = new ServiceResponseDetail(); ClientRequest clientRequest = new ClientRequest(serviceURL); clientRequest.accept(MediaType.APPLICATION_XML); clientRequest.body(MediaType.APPLICATION_XML, serviceRequestDetail); ClientResponse<ServiceRequestDetail> response = clientRequest.post(ServiceRequestDetail.class); if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } ServiceResponseDetail serviceResponseDetail = response.getEntity(ServiceResponseDetail.class); 

and when I try to access my service, I get the error "Error without authentication"

 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated ... 

Is there a way to add SSL configuration data in a RESTeasy client? Any other suggestions for resolving this issue are also welcome.

Thank you in advance

+4
source share
2 answers

I found out the answer, but I am very sorry for the late reply.

To answer my question, the RESTeasy client supports TLS / SSL. Infact problem was missed to install certificate in JVM.

 keytool -import -alias <Replace certificate Alias name> -keystore $JAVA_HOME\jre\lib\security\cacerts -file <Replace your Certificate file location> 

This solved the "Peer Not Authenticated" problem. Hope it helps. Kudos

+3
source

If you do not want to add the certificate to the JVM and store this certificate separately. You can download the certificate as part of your code, as shown below.

'// load certificate InputStream fis = this.getClass (). GetResourceAsStream ("file / path / to / your / certificate.crt"); CertificateFactory cf = CertificateFactory.getInstance ("X.509"); Certificate cert = cf.generateCertificate (fis);

  // load the keystore that includes self-signed cert as a "trusted" entry KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null, null); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); keyStore.setCertificateEntry("cert-alias", cert); tmf.init(keyStore); SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(null, tmf.getTrustManagers(), null);' 

then attach a light builder of type to rest

resteasyClientBuilder.sslContext(sslContext)

0
source

All Articles