You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/03/27 09:29:27 UTC

[GitHub] [servicecomb-java-chassis] solitudeycq opened a new issue #2325: HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符

solitudeycq opened a new issue #2325:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2325


   ### HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符
   
   在自定义的HttpClientFilter的afterReceiveResponse方法中,调用HttpServletResponseEx.getBodyBytes()获取到的字符包含不可见字符,导致序列化的时候失败,简易代码如下:
   
   ```java
   public class CustomFilter implements HttpClientFilter {
       @Override
       public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx response) {
           String response = new String(response.getBodyBytes(), StandardCharsets.UTF_8);
           System.out.println(response);
       }
   }
   ```
   
   获取到的字符串如下所示:
   
   {"error":{"errorCode":500,"errorMsg":"查询出问题"},"data":null}                           |(}之后,|之前是不可见字符)
   
   此时使用vertx自己的json工具解析的时候会出错,请问这个不可见字符是在什么时候什么原因加上的?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] solitudeycq commented on issue #2325: HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符

Posted by GitBox <gi...@apache.org>.
solitudeycq commented on issue #2325:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2325#issuecomment-816442984


   问题解决


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2325: HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2325:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2325#issuecomment-809004140


   这个需要从服务端的响应看下。 java chassis不会追加额外的内容, 除了服务端的实际响应值。 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] wujimin commented on issue #2325: HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符

Posted by GitBox <gi...@apache.org>.
wujimin commented on issue #2325:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2325#issuecomment-809818242


   ```java
   public interface BodyBufferSupport {
     void setBodyBuffer(Buffer bodyBuffer);
   
     Buffer getBodyBuffer();
   
     // notice: byte[] maybe null, and length maybe bigger than body length
     byte[] getBodyBytes();
   
     int getBodyBytesLength();
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] solitudeycq commented on issue #2325: HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符

Posted by GitBox <gi...@apache.org>.
solitudeycq commented on issue #2325:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2325#issuecomment-809139581


   @liubao68 这个就是在服务端,业务代码执行完成之后,到filter之后就多了这些不可见字符


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] solitudeycq commented on issue #2325: HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符

Posted by GitBox <gi...@apache.org>.
solitudeycq commented on issue #2325:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2325#issuecomment-809838435


   @wujimin @liubao68 好的,谢谢二位,那我就采用result1的获取方式


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] solitudeycq closed issue #2325: HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符

Posted by GitBox <gi...@apache.org>.
solitudeycq closed issue #2325:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2325


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] solitudeycq commented on issue #2325: HttpServletResponseEx.getBodyBytes()获取到的字符含有不可见字符

Posted by GitBox <gi...@apache.org>.
solitudeycq commented on issue #2325:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2325#issuecomment-809289623


   @liubao68 
   调试后发现,result1和result2不一样,其中result2加上了不可见字符:
   
   ```java
   public class CustomFilter implements HttpClientFilter {
       @Override
       public Response afterReceiveResponse(Invocation invocation, HttpServletResponseEx response) {
           String result1 = new String(response.getBodyBuffer().getBytes(), StandardCharsets.UTF_8);
               String result2 = new String(response.getBodyBytes(), StandardCharsets.UTF_8);
               LOGGER.error("result1,use original getBytes method:{}", result1);
               LOGGER.error("result2,use wrapped method:{}", result2);
       }
   }
   ```
   
   请问宝哥,这个是什么原因?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org