我正在尝试从一个可用的REST Web服务中获取响应。
根据文档,我想到了以下方法:
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);
}
然而,我收到的回复并不太友好:
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
我正在使用NetBeans,似乎GlassFish服务器自带javax.ws.rs-api.jar,因此我没有添加任何库来运行上述内容。
我需要在库中添加Jersey.jar吗?或者我漏掉了什么?
谢谢。