HttpsClient,RestTemplate,WebClitntの性能をテストする方法
3834 ワード
詳細
public static void main(String[] args) throws SSLException {
RequestEntity requestEntity = new RequestEntity();
requestEntity.setUserId("dsds");
requestEntity.setRegion("dasrjasl");
requestEntity.setProductType("fdsfgsf");
List 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 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 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);
}