【问题标题】:WebClient class missing from Apache CXF?Apache CXF 中缺少 WebClient 类?
【发布时间】:2017-10-15 05:20:49
【问题描述】:

我目前正在使用 Apache CXF 3.1.11 版构建 JAX-RS 客户端。我一直在网上查看一些简单的示例,似乎 WebClient 类已经丢失。

查看下面我在网上找到的示例代码。

public static void main(String[] args) throws JsonParseException,
             JsonMappingException, IOException {
    WebClient client = WebClient
            .create("http://localhost:8080/",
                    Collections.singletonList(new JacksonJsonProvider()))
            .path("test").accept(MediaType.APPLICATION_JSON_TYPE);
    Message message = client.get(Message.class);
    System.out.println("Message recieved : " + message);
}

我在代码中的任何地方都找不到 WebClient 类,我使用以下 maven 依赖项。

  • cxf-rt-frontend-jaxws
  • cxf-rt-transsports-http
  • cxf-rt-transports-http-jetty

请有人确认我是否缺少依赖项或 WebClient 是否已从版本 3.1.11 中删除

【问题讨论】:

    标签: java apache jax-rs cxf


    【解决方案1】:

    如果您不确定具体的提供程序实现,您可以改用 JAX-RS 的标准部分类,它们是二重奏 ClientWebTarget。但是对于编组,当然,您可能仍然需要配置特定的依赖项,要么手动配置,要么已由 Apache CXF 提供。

        Client client = ClientBuilder.newBuilder().build();
        WebTarget target = client
                .target("http://localhost:8080/");
        Response response = target.request().get();
        Message message = client.readEntity(Message.class);
         /*
         // now.. process the message
         for (Message message : message.get...) {.. }
        */
        response.close(); // close connections.
    

    【讨论】:

      【解决方案2】:

      你需要添加 cxf-rt-frontend-jaxrs 而不是 cxf-rt-frontend-jaxws

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多