Getoutputstream() has already been called for this response

java.lang.IllegalStateException: getOutputStream() has already been called for this response
        at org.apache.catalina.connector.Response.getWriter(
        at org.apache.catalina.connector.ResponseFacade.getWriter(
        at Source)

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);"\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: