通过 REST 服务发送 ByteArrayOutputStream 时出现 NoMessageBodyWriterFoundFailure
我必须通过休息服务发送 ByteArrayOutputStream,并且出现此异常:
org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type text/html;charset="iso-8859- 1" 和类型类 java.io.ByteArrayOutputStream
我不明白为什么,我必须让它工作。
这是我的休息服务:
@POST
@Path("/exported")
@Consumes(MediaType.APPLICATION_XML)
public ByteArrayOutputStream getExported(Wrapper wrapper) {
ByteArrayOutputStream os = null;
os = new ByteArrayOutputStream();
try {
os.write("TTT".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return os;
}
这是我的客户:
ClientRequest request = new ClientRequest("http://localhost:8081/restws/rest/rrr/exported");
request.accept(MediaType.APPLICATION_XML);
request.body(MediaType.APPLICATION_XML, new Wrapper(
listOf Objects));
ClientResponse<ByteArrayOutputStream> response = request
.post(ByteArrayOutputStream.class);
ByteArrayOutputStream os = response.getEntity();
return "success";
包含此方法的类中的所有内容都有效,但此方法除外。
I have to send a ByteArrayOutputStream through a rest service, and I got this exception:
org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type text/html;charset="iso-8859-1" and type class java.io.ByteArrayOutputStream
I don't understand why and I have to make it work.
Here is my rest service:
@POST
@Path("/exported")
@Consumes(MediaType.APPLICATION_XML)
public ByteArrayOutputStream getExported(Wrapper wrapper) {
ByteArrayOutputStream os = null;
os = new ByteArrayOutputStream();
try {
os.write("TTT".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return os;
}
Here is my client:
ClientRequest request = new ClientRequest("http://localhost:8081/restws/rest/rrr/exported");
request.accept(MediaType.APPLICATION_XML);
request.body(MediaType.APPLICATION_XML, new Wrapper(
listOf Objects));
ClientResponse<ByteArrayOutputStream> response = request
.post(ByteArrayOutputStream.class);
ByteArrayOutputStream os = response.getEntity();
return "success";
Everything in the class containing this method works, except this method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RestEasy 不知道谁将您的 ByteArrayOutputStream 转换为可以通过 HTTP 发送的内容。阅读RESTEasy 内容编组 然后使用不同的内容类型和/或使用自动处理的不同数据类型和/或编写内容编组提供程序来处理 ByteArrayOutStream。
RestEasy doesn't know who to convert your ByteArrayOutputStream into something that can be sent over HTTP. Read up on RESTEasy Content Marshalling and then either use a different content type and/or use a different data type that is automatically handled and/or write a content marshalling provider to handle your ByteArrayOutStream.