Tôi muốn đo thời gian của yêu cầu HTTP GET của cuộc gọi RestTemplate.getForObject
mà không cần thời gian để phân tích cú pháp phản hồi. Vì vậy, chỉ cần thời gian cuộc gọi HTTP từ xa cần. Tôi đã cố gắng thiết lập một ClientHttpRequestInterceptor
nhưng tôi không nghĩ rằng đây là đúng cách để làm điều đó như thời gian có vẻ là sai:Đo thời gian khôi phục SpringTemplate HTTP
public class PerfRequestSyncInterceptor implements ClientHttpRequestInterceptor {
private Logger log = Logger.getLogger(this.getClass());
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
long start = System.nanoTime();
ClientHttpResponse resp = execution.execute(request, body);
log.debug("remote request time: "
+ ((System.nanoTime() - start) * Math.pow(10, -9)));
return resp;
}
}
Gọi:
RestTemplate rest = new RestTemplate();
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
interceptors.add(new PerfRequestSyncInterceptor());
rest.setInterceptors(interceptors);
Response inob = rest.getForObject(xmlURL, Response.class);
Làm thế nào tôi có thể đo thời gian một yêu cầu HTTP RestTemplate?
Tôi đã gặp vấn đề tương tự. Bạn cần thực hiện cuộc gọi phương thức trên đối tượng phản hồi để chặn thực thi cho đến khi có phản hồi. – jaydfwtx