{} WebClient的拦截器抛出异常,现在展开无法发送消息

时间:2017-08-23 14:44:24

标签: java jax-rs restful-authentication websphere-liberty open-liberty

我正在尝试使用部署为战争的Websphere Liberty配置文件中的Webtarget代码访问示例Rest方法并获得以下异常。

[WARNING ] Interceptor for {https://www.google.com}WebClient has thrown exception, unwinding now
Could not send Message.

直接使用java main方法运行它。

@GET
    @Produces("text/plain")
    @Path("/hello")
    public Response healthCheck() {
        ClientConfig configuration = new ClientConfig();
        configuration = configuration.property(ClientProperties.CONNECT_TIMEOUT, 30000);
        configuration = configuration.property(ClientProperties.READ_TIMEOUT, 30000);
        configuration = configuration.property(ClientProperties.PROXY_URI, "http://xxx.xxx.com:8080");
        configuration.connectorProvider(new ApacheConnectorProvider());
        Client client = ClientBuilder.newClient(configuration);
        WebTarget target = client.target(
                "https://www.google.com");

        String content = target.request().get(String.class);
        System.out.println(content);
}

感谢任何帮助?它的任务很简单,但需要花费很多时间。

1 个答案:

答案 0 :(得分:0)

ClientConfigClientProperties类型特定于泽西岛。虽然您可能在应用程序中使用它们,但它们几乎肯定会与基于CXF的WebSphere JAX-RS实现发生冲突。如果您发布完整日志,我可以确认。

尝试使用JAX-RS规范API类型而不是Jersey类型 - 并使用IBM属性(不幸的是,这些属性不可移植),如下所示:

@GET
@Produces("text/plain")
@Path("/hello")
public Response healthCheck() {
    Client client = ClientBuilder.newBuilder()
            .property("com.ibm.ws.jaxrs.client.connection.timeout", 30000)
            .property("com.ibm.ws.jaxrs.client.receive.timeout", 30000)
            .property("com.ibm.ws.jaxrs.client.proxy.host", "xxx.xxx.com")
            .property("com.ibm.ws.jaxrs.client.proxy.port", "8080")
            .build();

    WebTarget target = client.target(
            "https://www.google.com");

    String content = target.request().get(String.class);
    System.out.println(content);
    return Response.ok(content).build();
}

希望这有帮助,Andy

相关问题