0

I am trying to access sample Rest method using Webtarget code in Websphere Liberty profile deployed as war and getting following exception.

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

Its working when directly run with java main method.

@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);
}

Any help is appreciated? Its simple task but taking lot of time.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
nivas
  • 53
  • 1
  • 5

1 Answers1

1

The ClientConfig and ClientProperties types are specific to Jersey. While you might have them in your application, they will almost certain conflict with WebSphere's JAX-RS implementation based on CXF. If you post the full logs, I may be able to confirm that.

Try using the JAX-RS spec API types instead of the Jersey types - and use the IBM properties (unfortunately, these properties are not portable) like this:

@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();
}

Hope this helps, Andy

Andy McCright
  • 1,273
  • 6
  • 8