2

I have written a RESTful Client using Jersey 2.15 and invoking IBM Watson's RankRetrieve(R&R) Service. The code snippet works out of Eclipse environment as well as a WAR deployed out of Tomcat 7 and fetches the result JSON from the R&R service

HttpAuthenticationFeature basicAuthCredentials = HttpAuthenticationFeature.basic(this.userName, this.password);
Client client = ClientBuilder.newClient();
client.register(basicAuthCredentials);
WebTarget webTarget = client.target(this.buildUri())
                            .queryParam("ranker_id", this.rankerID)
                            .queryParam("q", searchTerm)
                            .queryParam("wt", "json");
Invocation.Builder invocationBuilder = webTarget.request(MediaType.TEXT_PLAIN_TYPE)
                                                .accept(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.get();
String resultString = response.readEntity(String.class);
System.out.println("RankRetrieve Response: " + resultString);

But when the same WAR file is deployed in Websphere LibertyProfile 8.5.5.7 the response received is 404.

{"responseHeader":{"status":400,"QTime":0},"error":{"msg":"Bad contentType for search handler :text/xml request={q=theQuestions&ranker_id=SomeRankerID&wt=json}","code":400}}

I then started searching about WLP & Jersey and came across articles such as JAX-RS Jersey Client on Websphere 8.5

Also during in Debug mode when I watch webTarget under Tomcat, I see the contents such as follows:

webTarget : JerseyWebTarget { https://<URL>?ranker_id=someRankerID&q=theQuestions&wt=json }

But the same watch under WLP shows me as follows:

webTarget : org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl@3e59a416

In the same application, in some other classes the Jersey Client also consumes other services and is working as expected under WLP, so I'm not able to figure out what is the reason only this code isn't working as expected under WLP.

This is my first Java project and I've tried searching online/reading SO/reading WLP documentation but none has helped me uncover what is the reason the same code is fetching me results under Tomcat and not under WLP.

I cannot remove WLP from our servers as it is extensively houses many other applications but any help in regards to the problem is appreciated.

Community
  • 1
  • 1
user6083088
  • 1,047
  • 1
  • 9
  • 27
  • Have you tried disabling the jaxrs feature in liberty since you are providing your own impl? It could be added by eclipse or implicitly by e.g. webPorfile or ee7 features. Check server.xml – covener Mar 19 '16 at 12:37
  • I'm have been looking at the WLP documentation, but unable to figure out the examples as my server.xml file does not contain anything like whats described in the documentation. – user6083088 Mar 20 '16 at 19:12

1 Answers1

0

The root cause is built-in cxf WebTargetImpl has been loaded first then Jersey's.

option 1) Disable the feature jaxrs, you can check the /usr/servers//logs/message.log to see if there any jaxrs feature enabled: com.ibm.ws.kernel.feature.internal.FeatureManager A CWWKF0012I: The server installed the following features: [....jaxrs-2.0...]

option 2) Change classloader policy to parentLast: ..

option 3) Remove all jersey jars and enable jaxrs-2.0 feature then try.

Neal

Neal Hu
  • 16