javax.ws.rs.client.Client how to configure readTimeOut?

前端 未结 1 2012
半阙折子戏
半阙折子戏 2021-02-07 09:35

Going from com.sun.jersey.api.client.Client to javax.ws.rs.client.Client how do I configure Client?

FROM:

import com.su         


        
相关标签:
1条回答
  • 2021-02-07 10:16

    I assume you are using jax-rs-ri. For this, you can use ClientProperties.CONNECT_TIMEOUT and ClientProperties.READ_TIMEOUT.

    Example:

    ClientConfig configuration = new ClientConfig();
    configuration = configuration.property(ClientProperties.CONNECT_TIMEOUT, 1000);
    configuration = configuration.property(ClientProperties.READ_TIMEOUT, 1000);
    Client client = ClientBuilder.newClient(configuration);
    WebTarget target = client.target(
            "http://developer.github.com/v3/");
    String content = target.request().get(String.class);
    System.out.println(content);
    

    EDIT:

    I read the API document for ClientConfig.property. And @Gili is right.

    0 讨论(0)
提交回复
热议问题