问题
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