简体   繁体   English

RESTeasy客户端是否支持TLS / SSL?

[英]Does RESTeasy client support TLS/SSL?

I'm using several RESTful webservice in JAVA based web-application. 我在基于JAVA的Web应用程序中使用了几个RESTful Web服务。 I'm using the RESTeasy client to access my webservice. 我正在使用RESTeasy客户端访问我的Web服务。 Here all communication between the client and service is through XML(JAX-B xml annotated detail classes). 这里客户端和服务之间的所有通信都是通过XML(JAX-B xml带注释的详细信息类)。 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 "Peer not Authenticated" error 当我尝试访问我的服务时,我得到“Peer not Authenticated”错误

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

Is there any way to add the SSL configuration details in the RESTeasy client? 有没有办法在RESTeasy客户端中添加SSL配置详细信息? any other suggestions for solving this issue is also welcome 任何其他解决这个问题的建议也是受欢迎的

Thanks in advance 提前致谢

I found out the answer but I'm really sorry for the late response. 我找到了答案,但我很抱歉迟到的回复。

To answer my question, RESTeasy client does support TLS/SSL. 为了回答我的问题,RESTeasy客户端确实支持TLS / SSL。 Infact the problem was I missed to install the certificate into the JVM. 事实上,问题是我错过了将证书安装到JVM中。

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

This solved the issue of "Peer Not Authenticated". 这解决了“Peer Not Authenticated”的问题。 Hope it helps. 希望能帮助到你。 Kudos 荣誉

If you don't want to add certificate to JVM and keep this cert separate. 如果您不想将证书添加到JVM并将此证书分开。 You can load the cert as part of your code like below. 您可以将证书作为代码的一部分加载,如下所示。

` // load the certificate InputStream fis = this.getClass().getResourceAsStream("file/path/to/your/certificate.crt"); `//加载证书InputStream fis = this.getClass()。getResourceAsStream(“file / path / to / your / certificate.crt”); CertificateFactory cf = CertificateFactory.getInstance("X.509"); CertificateFactory cf = CertificateFactory.getInstance(“X.509”); Certificate cert = cf.generateCertificate(fis); 证书证书= 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 to rest easy builder like 然后附上休息容易建设者喜欢

resteasyClientBuilder.sslContext(sslContext)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM