简体   繁体   中英

Jersey http client

I'm using jersey http client to send requests to some remote API. I need to measure how much time does it take to send request to the server and wait until it gets processed and server returns me some status code. Is there a way how I can do it with jersey? Here is my code of post method:

  public Response post(String targetUrl, Entity entity)
  {
    return client.target(targetUrl)
        .request()
        .accept(MediaType.APPLICATION_JSON_TYPE)
        .header(SERVER_AUTH, true)
        .post(entity);
  }

Actually, it was my fault. By default, this client is synchronized so it blocks thread until response is received. But my problem was that URL was incorrect and code immediately returned status 'Resouce not found.'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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