泽西岛客户端异常:找不到消息正文编写器 [英] Jersey client exception: A message body writer was not found
本文介绍了泽西岛客户端异常:找不到消息正文编写器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Jersey客户端访问用于图像上传功能的PHP Web服务.我收到以下异常:
I am using Jersey client to hit a PHP web service for image uploading functionality. I am getting the following exception:
Caused by: com.sun.jersey.api.client.ClientHandlerException:
A message body writer for Java type, class
com.sun.jersey.multipart.FormDataMultiPart, and MIME media type,
multipart/form-data, was not found
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:288)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
... 63 more
这是我正在使用的代码:
This is the code I am using:
WebResource webResource = Client.create().resource(HTTP_REST_URI);
JSONObject jSONObj = webResource.queryParams(queryParams)
.type(MediaType.MULTIPART_FORM_DATA)
.post(JSONObject.class, formDataMultiPart);
该异常如何解决?
推荐答案
在创建Client
时注册MultiPartWriter
提供程序:
Register the MultiPartWriter
provider when creating the Client
:
ClientConfig cc = new DefaultClientConfig();
Client client;
cc.getClasses().add(MultiPartWriter.class);
client = Client.create(cc);
如果使用Maven,则这些是您在pom.xml
中所需的依赖项:
If using Maven, these are the dependencies you need in your pom.xml
:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.17.1</version>
</dependency>
这篇关于泽西岛客户端异常:找不到消息正文编写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文