java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:581)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:227)
at com.alibaba.fastjson.serializer.ASMSerializer_10_ResponseFacade.write(Unknown Source)
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:333)
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:311)
at com.alibaba.fastjson.serializer.ObjectArrayCodec.write(ObjectArrayCodec.java:118)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:285)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:740)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:678)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:643)
Problem scenario: block the print request parameters in the class, and use jsonobject to convert httpservletresponse to a string.
private Object printLog(ProceedingJoinPoint joinPoint) throws Throwable {
String ipAddress = IpAddressUtil.getIpAddress(request);
String url = request.getRequestURL().toString();
String params = JSON.toJSONString(joinPoint.getArgs());
Object proceed = joinPoint.proceed();
String result = JSON.toJSONString(proceed);
log.info("\n-----------------------------------------------------------------------------------------------" +
"\n<> IP:{} " +
"\n<> url:{} " +
"\n<> params:{} " +
"\n<> result:{}" +
"\n-----------------------------------------------------------------------------------------------" , ipAddress, url, params, result);
return proceed;
}
Cause problem: the interface has two parameters, one of which is httpservletresponse
At this time, the interceptor will report an error when printing parameters.
When checking the debug, it is found that there is an error in calling getwriter after getting the object through reflection, which leads to an exception in JSON transformation
Alibaba JSON is getting the object serializer class asmserializer_ 1_ Resposefacade called ResponseFacade.getWriter ()
write javaBean error, fastjson version 1.2.58, class com.sun.proxy .$Proxy128, method : getWriter
Error usage code:
HttpServletResponse response;
JSON.toJSONString (response);
to sum up, jsonobject is unable to serialize httpservletresponse, thus reporting the above exception
Read More:
- The RenderBody method has already been called
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- Typeerror: object of type ‘response’ has no len() why?
- Debug error: abort() has been called error causes and Solutions
- JS Ajax request is successful, the response displays “failed to load response data”
- JMeter running error response code: non HTTP response code: java.lang.illegalargumentexception find and solve
- docker Error response from daemon: Bad response from Docker engine
- When feign is called, the solution of request method ‘post’ not supported appears
- Error while extracting response for type [java.util.List<java.util.Map<java.lang.String,Object>>]
- C++: terminate called after throwing an instance of ‘std::length_error‘ (sort function cmp sorting rules problem)
- Error occurred when Python called cv2.findcontours: valueerror: not enough values to unpack (expected 3, got 2)
- Error in loadNamespace(name) : there is no package called ‘yaml’
- RuntimeError: cudnn RNN backward can only be called in training mode
- How to Fix distributed training report terminate called after throwing an instance of’std::length_error’
- Runtime error: terminate called after throwing an instance of ‘STD:: Logic_ error’
- SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
- Illegalargumentexception error when adding cookie to response
- Solve the problem of flag error valueerror: View function did not return a response
- R language error error: n() should only be called in a data context
- c++ terminate called after throwing an instance of ‘std::system_error‘ what(): Unknown error -1