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 2020/05/08 08:13:05 UTC

[GitHub] [servicecomb-java-chassis] huanghezhen opened a new issue #1740: 在 highway 模式下 自定义ExceptionToProducerResponseConverter 返回对象序列化失败

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


   ```java
   
   public class GlobalExceptionFilter implements ExceptionToProducerResponseConverter<Exception> {
       @Override
       public Class<Exception> getExceptionClass() {
           return Exception.class;
       }
   
   
       @Override
       public Response convert(SwaggerInvocation swaggerInvocation, Exception e) {
   
           System.out.println("----------------------------------------------------------");
   
           //String s = JSONObject.toJSONString(BaseResponse.newInstance(CommonResponseMsg.ERROR));
   
           return Response
                   .create(HttpStatus.SC_OK, String.valueOf(HttpStatus.SC_OK), BaseResponse.newInstance(CommonResponseMsg.ERROR));
       }
   }
   
   ```
   > BaseResponse.newInstance(CommonResponseMsg.ERROR) 这个是自定义返回信息对象   
   当rpc 抛出 Exception 异常的时候,会得到如下json数据
   
   ```json
   
   {
   "message": "method POST, path /ProviderServiceImpl/testException/, statusCode 200, reasonPhrase 200, response content-type application/json; charset=utf-8 is not supported"
   }
   
   ```
   
   > 如下是期望的返回json数据
   
   ```json
   
   {
   "status": false,
   "resultCode": "0000000",
   "logicCode": "000000001",
   "resultMsg": "接口异常"
   }
   
   ```
   
   


----------------------------------------------------------------
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] huanghezhen commented on issue #1740: 在 highway 模式下 自定义ExceptionToProducerResponseConverter 返回对象序列化失败

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


   版本是 2.0.1


----------------------------------------------------------------
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] huanghezhen commented on issue #1740: 在 highway 模式下 自定义ExceptionToProducerResponseConverter 返回对象序列化失败

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


   找到原因了 没问题!!!!  返回的对象需要与接口的类型保持一致


----------------------------------------------------------------
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] huanghezhen commented on issue #1740: 在 highway 模式下 自定义ExceptionToProducerResponseConverter 返回对象序列化失败

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


   https://github.com/huanghezhen/servicecomb-test.git
   
   springboot


----------------------------------------------------------------
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] huanghezhen commented on issue #1740: 在 highway 模式下 自定义ExceptionToProducerResponseConverter 返回对象序列化失败

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


   #### 对象信息
   ```java
   public class BaseResponse<T> {
   
       @ApiModelProperty("状态")
       private boolean status;
       @ApiModelProperty("返回码")
       private String resultCode;
       @ApiModelProperty("返回码")
       private String logicCode;
       @ApiModelProperty("返回信息")
       private String resultMsg;
       @ApiModelProperty("返回数据")
       private T data;
   
   }
   ```
   #### 错误如下
   
   ```java
   2020-05-08 16:16:32.796 [group1-2-thread-1] ERROR org.apache.servicecomb.transport.highway.HighwayServerInvoke - 161 - encode response failed, provider.ProviderService.testException, msgId=0
   java.lang.IllegalStateException: not support serialize from hhz.springboot.common.entity.BaseResponse to proto string, field=provider.ProviderService.TestExceptionResponseWrap200:value
   	at org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils.throwNotSupportWrite(ProtoUtils.java:85)
   	at org.apache.servicecomb.foundation.protobuf.internal.ProtoUtils.throwNotSupportWrite(ProtoUtils.java:80)
   	at org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.scalar.StringWriteSchemas$StringDynamicSchema.writeTo(StringWriteSchemas.java:68)
   	at org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.MessageWriteSchema.writeFromMap(MessageWriteSchema.java:192)
   	at org.apache.servicecomb.foundation.protobuf.internal.schema.serializer.MessageWriteSchema.writeTo(MessageWriteSchema.java:151)
   	at org.apache.servicecomb.foundation.protobuf.RootSerializer.serialize(RootSerializer.java:35)
   	at org.apache.servicecomb.codec.protobuf.definition.ResponseRootSerializer.serialize(ResponseRootSerializer.java:45)
   	at org.apache.servicecomb.transport.highway.HighwayOutputStream.write(HighwayOutputStream.java:37)
   	at org.apache.servicecomb.transport.highway.HighwayCodec.encodeResponse(HighwayCodec.java:101)
   	at org.apache.servicecomb.transport.highway.HighwayServerInvoke.sendResponse(HighwayServerInvoke.java:153)
   	at org.apache.servicecomb.transport.highway.HighwayServerInvoke.lambda$doRunInExecutor$0(HighwayServerInvoke.java:134)
   	at org.apache.servicecomb.core.handler.impl.ProducerOperationHandler.syncInvoke(ProducerOperationHandler.java:117)
   	at org.apache.servicecomb.core.handler.impl.ProducerOperationHandler.invoke(ProducerOperationHandler.java:63)
   	at org.apache.servicecomb.core.handler.impl.ProducerOperationHandler.handle(ProducerOperationHandler.java:54)
   	at org.apache.servicecomb.core.Invocation.next(Invocation.java:293)
   	at org.apache.servicecomb.transport.highway.HighwayServerInvoke.doRunInExecutor(HighwayServerInvoke.java:134)
   	at org.apache.servicecomb.transport.highway.HighwayServerInvoke.runInExecutor(HighwayServerInvoke.java:110)
   	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
   	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
   	at java.lang.Thread.run(Thread.java:748)
   ```


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