欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

测试HttpsClient,RestTemplate,WebClitnt性能的方法

程序员文章站 2022-05-31 16:09:56
...
public static void main(String[] args) throws SSLException {
    RequestEntity requestEntity = new RequestEntity();
    requestEntity.setUserId("dsds");
    requestEntity.setRegion("dasrjasl");
    requestEntity.setProductType("fdsfgsf");
    List<String> ids = new ArrayList<>();
    ids.add("132354");
    ids.add("rewwtrwetr");
    requestEntity.setProductsId(ids);
    String keyClockToken = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJLQ0FzQUVYYzVPSkRWb3RuS1hFX01Gc2FiSkc5NlRvbWJyY1VoSVRUaTVBIn0.eyJqdGkiOiI2YTZjODBmMS02OGFhLTRiMWUtOGE1NS01M2I4YjQ3YmFjYTEiLCJleHAiOjE1MzgzMDU0NjIsIm5iZiI6MCwiaWF0IjoxNTM4MjY5NDYyLCJpc3MiOiJodHRwczovLzEwLjExMC4yMi4xMy9hdXRoL3JlYWxtcy9waWNwIiwiYXVkIjoiYnNzLWNsaWVudCIsInN1YiI6ImJkN2VlNTc4LTNkMjYtNGVmYy05N2VkLWM1NzYzMjVjZjk1YSIsInR5cCI6IkJlYXJlciIsImF6cCI6ImJzcy1jbGllbnQiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiJlOTg1OGMxZi0zOGFlLTQzNDgtYTMzNS0wN2VlNTAxNGQ5MDciLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbIioiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbInVtYV9hdXRob3JpemF0aW9uIiwidm1fYXRvbWFwaSIsInVzZXIiXX0sInJlc291cmNlX2FjY2VzcyI6eyJ2bS1hdG9tYXBpIjp7InJvbGVzIjpbInVtYV9wcm90ZWN0aW9uIiwidm1fYXRvbWFwaSJdfSwiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwicHJvamVjdCI6ImppbmRlbmdrZTIiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJqaW5kZW5na2UiLCJwcm9qZWN0aWQiOiJmYzZiM2YwMi0wNzNiLTRkYTgtYmQ1ZS0xYzUzZDkxZGRiNjAiLCJlbWFpbCI6ImppbmRlbmdrZUBpbnNwdXIuY29tIn0.CduWvtxitubXiD_CIO-HywIMw6OChV7Q7WsUzrCEEi787V-Rhyx0v6x3-e60LUY7gSQ_qzNd-Q8S9-kK2ozhcauMDDPx0a6FcruCVBniqJs04QVi2b4XDpxxWkZi4V63K2RKu1YYmCVmMEMNe9N5SIzBuiUZKU2UpXXsZE8QHzO5myD1_QDddNtHIKvcVc_oNAaXtm44C9TjldpM5Q5ZRencFXvtxKLugi05RhG-zfIdPFpVBpldfd-nlGFtV_8F4J75oEr0Dj_rDXKKe0nR03uRXFbUYBuwx2BtmucsR2GFBycWc3-aHBSovIkELe4xOCXwypGnIaf3L6aiMGZqOw";
   /* HttpServletRequest request = RequestHolder.getRequest();
    String keyClockToken = request.getHeader("Authorization");*/
    long start0 = System.currentTimeMillis();
   HttpsClient.doPostJson(GET_SERVERS_FEE_DATA.getValue(), JSONObject.toJSONString(requestEntity));
    long end0 = System.currentTimeMillis();
    System.out.println("时间---0:" +(end0-start0));
    HttpHeaders getHeader = HttpEntityAndHeaderUtil.getHeader();
    getHeader.add("Authorization", keyClockToken);
    long start1 = System.currentTimeMillis();
    HttpEntity httpEntity = new HttpEntity(JSONObject.toJSONString(requestEntity), getHeader);
        ResponseEntity<ReturnEntity> responseEntity = RestTemplate()
                .exchange(GET_SERVERS_FEE_DATA.getValue(), HttpMethod.POST,
                        httpEntity,
                        ReturnEntity.class);
    long end1 = System.currentTimeMillis();
    System.out.println("时间---1:" +(end1-start1));
    System.out.println(responseEntity.getBody());

    Map<String,String> map = new HashMap<>();
    map.put(HEADER_CONTENT_TYPE.getValue(), CONTENT_TYPE_JSON.getValue());
    map.put("Authorization", keyClockToken);
    long start2 = System.currentTimeMillis();
    ReturnEntity ret = MyWebClitntUtil.post(requestEntity, GET_SERVERS_FEE_DATA.getValue(),map, ReturnEntity.class);
    long end2 = System.currentTimeMillis();
    System.out.println("时间---2:" +(end2-start2));
    System.out.println(ret);
}
已隐藏部分细节