简体   繁体   English

使用 spring Web 客户端命中 https Z65E8800B5C6800AAD896F888B2A 服务

[英]Using spring Web Client hit https rest service

I have got two .cer file from client now my goal is to hit client api using https rather than http using spring webclient. I have got two .cer file from client now my goal is to hit client api using https rather than http using spring webclient. As I am new to spring webclient not getting clue what to do因为我是 spring webclient 的新手,所以不知道该怎么做

I have imported both.cer in keystore using below command我已经使用以下命令在密钥库中导入了both.cer

keytool -import -file "C:\Users\ankur\Download\Entrust_Root_Certification_Authority-G2.cer" -keystore "C:\Program Files\Java\jre1.8.0_40\lib\security\cacerts" -storepass "changeit"

keytool -import -file "C:\Users\ankur\Download\certificate\Entrust_Certification_Authority-L1K.cer" -keystore "C:\Program Files\Java\jre1.8.0_40\lib\security\cacerts" -storepass "changeit

I have written below to code in order to hit the api programatically from webclient我在下面编写了代码,以便从 webclient 以编程方式访问 api

@Bean

       public WebClient createWebClient() throws SSLException {

             SslContext sslContext = SslContextBuilder

                           .forClient()

                           .trustManager(InsecureTrustManagerFactory.INSTANCE)

                           .build();          

             HttpClient httpClient = HttpClient

                           .create()

                           .secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));

                    ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);

             return WebClient.builder()

                           .clientConnector(connector).build();

       }



application.yml
    rest:
      endpoint:https://someexample.com/xyz

I have no idea what to do with.cer file where to store these.cer file do we need to include in resource folder of spring boot any example or link would be helpful thanks我不知道如何处理.cer 文件在哪里存储这些.cer 文件我们需要包含在 spring 引导的资源文件夹中吗?任何示例或链接都会有所帮助,谢谢


below is the one of the approach with that you can configure ssl certs to webclient下面是一种方法,您可以将 ssl 证书配置为webclient

Step 1: Copy your required certs to your resources folder第 1 步:将所需的证书复制到resources文件夹
let's take an example as config/Entrust_Root_Certification_Authority-G2.cer我们以config/Entrust_Root_Certification_Authority-G2.cer

Step 2: Create a property to configure the location of your certs as below in one of your configuration class第 2 步:创建一个属性以在您的配置之一 class 中配置证书的位置,如下所示

  @Value("${entrust.ssl.cert.path:config/Entrust_Root_Certification_Authority-G2.cer}")
  private String entrustSslCertFilePath;

Step 3: Load these certs while creating SslContext第 3 步:在创建SslContext时加载这些证书

SslContext sslContext = SslContextBuilder.forClient()
            .trustManager(new ClassPathResource(entrustSslCertFilePath).getInputStream())
            .build();

Note: Above metioned i have used with pem file which worked properly, give a try and if required feel free to convert cer to pem file and sslshopper will be very helpful for validating and converting ssl certs注意:上面提到的我已经使用了正常工作的pem文件,请尝试一下,如果需要,请随时将cer转换为pem文件, sslshopper将非常有助于验证和转换 ssl 证书

Thanks谢谢

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

相关问题 在 Rest web 服务中使用 https - Using https in Rest web service 使用Spring和Rest Web服务将文件从服务器发送到Client Java - Send file from Server to Client java with Spring and Rest web service 使用HTTP(和证书)消耗Java / Spring Rest服务 - Consuming Java / Spring rest service using HTTPs(and certificate) 如何使用邮递员休息客户端发送对象以调用REST服务,以便它将使用适当的方法参数命中以下给定的方法? - how to send object using postman rest client to call REST service so that it will hit the below given method with proper method parameters? REST Web服务始终使用CodenameOne客户端返回html - REST web service returning always html using CodenameOne client 静态Web服务中的春季安全性 - spring security in rest Web service Spring无状态Rest Web服务 - Spring stateless Rest web service 使用 Spring ZC6E190B284633C48E39E55049ZD1Z 将自定义 object 从客户端传递到 REST 端点 - Passing custom object from client to REST endpoint using Spring Web https://spring.io/guides/gs/sumption-rest/ 使用 RESTful Web 服务 - https://spring.io/guides/gs/consuming-rest/ Consuming a RESTful Web Service 如何使用 Java 和 Spring 在 REST Web 服务中等待()? - How to wait() in a REST web service using Java and Spring?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM