本文介绍了StreamCorruptedException:无效的流头:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到一个StreamCorruptedException,我不知道它为什么或如何发生.任何帮助都是极好的!这是客户:
I am getting a StreamCorruptedException and I have no idea why or how it's happening.Any help would be awesome!Here is the Client:
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
Map params = new HashMap<String, Object>();
Order[] orders = odao.getOpenOrdersByTenant(tenantID);
JSONObject jObj = new JSONObject();
jObj.put("params", params);
jObj.put("sourcePath", System.getProperty("user.dir") + "/reports/OpenOrders.jasper");
jObj.put("method", "html");
jObj.put("datasource", orders);
ClientResponse response = service.path("rest").path("jasper").path("getJasperReport").type(MediaType.APPLICATION_JSON).post(ClientResponse.class,jObj);
服务器:
@POST
@Path("/getJasperReport")
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_JSON)
public void getJasperReport(@Context HttpServletRequest servletRequest, @Context HttpServletResponse servletResponse, @Context UriInfo uriInfo )
throws ServletException, IOException{
ObjectInputStream objInputStream = new ObjectInputStream(servletRequest.getInputStream());
JSONObject jobj = (JSONObject) objInputStream.readObject();
倒数第二行引发java.io.StreamCorruptedException:无效的流头:7B227061
The Second to last line throws a java.io.StreamCorruptedException: invalid stream header: 7B227061
推荐答案
ObjectInputStream用于读取Java序列化数据,而不是JSON格式的数据.
ObjectInputStream is for reading java serialized data, not JSON formatted data.
您可能想要类似new JSONObject(new JSONTokener(servletRequest.getReader()))
的东西.
You probably want something like new JSONObject(new JSONTokener(servletRequest.getReader()))
.
这篇关于StreamCorruptedException:无效的流头:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!