我正在尝试使用Jersey来使用RESTful Web服务。
目标网址:http://<host>:8080/CatalogWS/publish/getCatFile?catalogId=CAT-865122
我编写了如下客户端类。
try
{
// ClientConfig cfg = new DefaultClientConfig();
Client c = Client.create();
WebResource resource = c
.resource("http://<host>:8080/CatalogWS/publish/getCatFile?catalogId=CAT-865122");
String resp = resource.accept(MediaType.APPLICATION_XML).get(String.class);
System.out.println("Resp: :" + resp);
} catch (Exception e)
{
e.printStackTrace();
}
当我试图运行时...我正在遵循例外情况..
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.jersey.api.client.Client$DefaultComponentProvider.getInstance(Client.java:151)
at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:133)
at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:103)
at com.sun.jersey.impl.application.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:132)
at com.sun.jersey.impl.application.MessageBodyFactory.initReaders(MessageBodyFactory.java:106)
at com.sun.jersey.impl.application.MessageBodyFactory.init(MessageBodyFactory.java:101)
at com.sun.jersey.api.client.Client.<init>(Client.java:244)
at com.sun.jersey.api.client.Client.<init>(Client.java:185)
at com.sun.jersey.api.client.Client.create(Client.java:379)
at TestClient.main(TestClient.java:19)
Caused by: java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.<init>(AbstractJAXBProvider.java:97)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.<init>(AbstractRootElementProvider.java:87)
at com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider.<init>(XMLRootElementProvider.java:72)
at com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App.<init>(XMLRootElementProvider.java:82)
... 14 more
null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.jersey.api.client.Client$DefaultComponentProvider.getInstance(Client.java:151)
at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:133)
at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:103)
at com.sun.jersey.impl.application.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:132)
at com.sun.jersey.impl.application.MessageBodyFactory.initReaders(MessageBodyFactory.java:106)
at com.sun.jersey.impl.application.MessageBodyFactory.init(MessageBodyFactory.java:101)
at com.sun.jersey.api.client.Client.<init>(Client.java:244)
at com.sun.jersey.api.client.Client.<init>(Client.java:185)
at com.sun.jersey.api.client.Client.create(Client.java:379)
at TestClient.main(TestClient.java:19)
Caused by: java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.<init>(AbstractJAXBProvider.java:97)
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.<init>(AbstractRootElementProvider.java:87)
at com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider.<init>(XMLRootElementProvider.java:72)
at com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$Text.<init>(XMLRootElementProvider.java:91)
... 14 more
null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.jersey.api.client.Client$DefaultComponentProvider.getInstance(Client.java:151)
at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:133)
at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:103)
at com.sun.jersey.impl.application.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:132)
at com.sun.jersey.impl.application.MessageBodyFactory.initReaders(MessageBodyFactory.java:106)
at com.sun.jersey.impl.application.MessageBodyFactory.init(MessageBodyFactory.java:101)
at com.sun.jersey.api.client.Client.<init>(Client.java:244)
at com.sun.jersey.api.client.Client.<init>(Client.java:185)
at com.sun.jersey.api.client.Client.create(Client.java:379)
at TestClient.main(TestClient.java:19)
Caused by: java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.<init>(AbstractJAXBProvider.java:97)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBElementProvider.<init>(AbstractJAXBElementProvider.java:85)
at com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider.<init>(XMLJAXBElementProvider.java:75)
at com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$App.<init>(XMLJAXBElementProvider.java:84)
... 14 more
null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.jersey.api.client.Client$DefaultComponentProvider.getInstance(Client.java:151)
at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:133)
at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:103)
at com.sun.jersey.impl.application.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:132)
at com.sun.jersey.impl.application.MessageBodyFactory.initReaders(MessageBodyFactory.java:106)
at com.sun.jersey.impl.application.MessageBodyFactory.init(MessageBodyFactory.java:101)
at com.sun.jersey.api.client.Client.<init>(Client.java:244)
at com.sun.jersey.api.client.Client.<init>(Client.java:185)
at com.sun.jersey.api.client.Client.create(Client.java:379)
at TestClient.main(TestClient.java:19)
Caused by: java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.<init>(AbstractJAXBProvider.java:97)
at com.sun.jersey.core.provider.jaxb.AbstractJAXBElementProvider.<init>(AbstractJAXBElementProvider.java:85)
at com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider.<init>(XMLJAXBElementProvider.java:75)
at com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$Text.<init>(XMLJAXBElementProvider.java:92)
... 14 more
null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.jersey.api.client.Client$DefaultComponentProvider.getInstance(Client.java:151)
at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:133)
at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:103)
at com.sun.jersey.impl.application.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:132)
at com.sun.jersey.impl.application.MessageBodyFactory.initReaders(MessageBodyFactory.java:106)
at com.sun.jersey.impl.application.MessageBodyFactory.init(MessageBodyFactory.java:101)
at com.sun.jersey.api.client.Client.<init>(Client.java:244)
at com.sun.jersey.api.client.Client.<init>(Client.java:185)
at com.sun.jersey.api.client.Client.create(Client.java:379)
at TestClient.main(TestClient.java:19)
Caused by: java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.<init>(AbstractJAXBProvider.java:97)
at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.<init>(AbstractListElementProvider.java:145)
at com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.<init>(XMLListElementProvider.java:81)
at com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App.<init>(XMLListElementProvider.java:90)
... 14 more
null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.jersey.api.client.Client$DefaultComponentProvider.getInstance(Client.java:151)
at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:133)
at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:103)
at com.sun.jersey.impl.application.MessageBodyFactory.getProviderMap(MessageBodyFactory.java:132)
at com.sun.jersey.impl.application.MessageBodyFactory.initReaders(MessageBodyFactory.java:106)
at com.sun.jersey.impl.application.MessageBodyFactory.init(MessageBodyFactory.java:101)
at com.sun.jersey.api.client.Client.<init>(Client.java:244)
at com.sun.jersey.api.client.Client.<init>(Client.java:185)
at com.sun.jersey.api.client.Client.create(Client.java:379)
at TestClient.main(TestClient.java:19)
Caused by: java.lang.NullPointerException
at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.<init>(AbstractJAXBProvider.java:97)
at com.sun.jersey.core.provider.jaxb.AbstractListElementProvider.<init>(AbstractListElementProvider.java:145)
at com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.<init>(XMLListElementProvider.java:81)
at com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$Text.<init>(XMLListElementProvider.java:98)
... 14 more
null
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.ext.MessageBodyReader.isReadable(Ljava/lang/Class;Ljava/lang/reflect/Type;[Ljava/lang/annotation/Annotation;)Z
at com.sun.jersey.impl.application.MessageBodyFactory._getMessageBodyReader(MessageBodyFactory.java:210)
at com.sun.jersey.impl.application.MessageBodyFactory.getMessageBodyReader(MessageBodyFactory.java:190)
at com.sun.jersey.impl.client.urlconnection.URLConnectionClientHandler$URLConnectionResponse.getEntity(URLConnectionClientHandler.java:105)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:359)
at com.sun.jersey.api.client.WebResource.access$100(WebResource.java:57)
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:285)
at TestClient.main(TestClient.java:22)