StreamCorruptedException: invalid stream header:

风流意气都作罢 提交于 2021-02-11 12:41:01

问题


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);

Server:

@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();         

The Second to last line throws a java.io.StreamCorruptedException: invalid stream header: 7B227061


回答1:


ObjectInputStream is for reading java serialized data, not JSON formatted data.

You probably want something like new JSONObject(new JSONTokener(servletRequest.getReader())).



来源:https://stackoverflow.com/questions/9986672/streamcorruptedexception-invalid-stream-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!