I'm trying to get a response from a working REST webservice.
I have come up with the following looking at the documentation:
void postRest(){ Client client = ClientBuilder.newClient(); WebTarget webTarget = client.target("http://localhost:8080/TestApplication/"); WebTarget resourceWebTarget = webTarget.path("webresources"); WebTarget peopleWebTarget = resourceWebTarget.path("people/get/all"); Invocation invocation = peopleWebTarget.request("text/xml").header("Content-Type", "application/xml").buildGet(); String response = invocation.invoke(String.class); System.out.println(response);}
However I am returned a not very friendly:
Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.jersey.message.internal.MessagingBinders$MessageBodyProviders.<init>(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;)V at org.glassfish.jersey.client.ClientBinder.configure(ClientBinder.java:118) at org.glassfish.hk2.utilities.binding.AbstractBinder.bind(AbstractBinder.java:169) at org.glassfish.jersey.internal.inject.Injections.bind(Injections.java:157) at org.glassfish.jersey.internal.inject.Injections._createLocator(Injections.java:147) at org.glassfish.jersey.internal.inject.Injections.createLocator(Injections.java:137) at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:352) at org.glassfish.jersey.client.ClientConfig$State.access$000(ClientConfig.java:85) at org.glassfish.jersey.client.ClientConfig$State$3.get(ClientConfig.java:117) at org.glassfish.jersey.client.ClientConfig$State$3.get(ClientConfig.java:114) at org.glassfish.jersey.internal.util.collection.Values$LazyValue.get(Values.java:275) at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:669) at org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:276) at org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:124) at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:97) at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:90) at org.glassfish.jersey.client.JerseyInvocation$Builder.buildGet(JerseyInvocation.java:201) at org.glassfish.jersey.client.JerseyInvocation$Builder.buildGet(JerseyInvocation.java:154) at client.RestClient.postRest(RestClient.java:24) at client.RestClient.main(RestClient.java:14)Java Result: 1
I'm using NetBeans and didn't add any library as it seems the GlassFish Server comes withjavax.ws.rs-api.jar which make the above run.
Do I need to add Jersey.jar as well inside libraries or am I missing something?Thank you