You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by "yhs0092 (via GitHub)" <gi...@apache.org> on 2024/07/26 07:20:25 UTC
[I] Java-Chassis 2.8分支能否将文件下载响应的判断方式从根据接口契约判断改为根据运行时返回的body类型判断? [servicecomb-java-chassis]
yhs0092 opened a new issue, #4425:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4425
## 问题现象及原因分析
我们在支撑用户从 Java-Chassis 1.3 升级到 Java-Chassis 2.8 的过程中, 发现部分用户在服务端接口上定义自己的返回值类型为 `Object
`, 而代码里实际返回的body类型为 `Part`, 用于文件下载. 这种写法在 Java-Chassis 1.3 分支能够正常完成文件下载的功能, 但在 Java-Chassis 2.8 分支则会遇到报错, Java-Chassis 会将文件下载的`Part`类型body错误地当成一个 POJO 对象, 尝试将其序列化为 JSON 返回.
分析`ServerRestArgsFilter`的源码, 我们发现两个分支在判断HTTP响应是否是文件下载场景时存在差异, 对于 Java-Chassis 1.3 分支, 它是根据controller中实际返回的 body 类型做判断的:
https://github.com/apache/servicecomb-java-chassis/blob/77de1ef80df43d7731a6bdf8a5daebacb2a4eb3c/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java#L66-L77
注意上文末尾判断body类型时, 使用的是运行时实际返回的`body`对象.
而对于 Java-Chassis 2.8 分支, 它是根据当前HTTP响应的状态码对应的契约中的body类型做判断的:
https://github.com/apache/servicecomb-java-chassis/blob/d960aae46757f137e9c3176ec76e94626ea2e463/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/ServerRestArgsFilter.java#L68-L75
注意上文73行的`isDownloadFileResponseType`方法, 这里不再根据运行时实际的 body 类型做判断了, 转而使用契约信息做判断:
https://github.com/apache/servicecomb-java-chassis/blob/d960aae46757f137e9c3176ec76e94626ea2e463/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/filter/inner/RestServerCodecFilter.java#L123-L126
## 诉求
希望 Java-Chassis 能够将判断返回值是否是文件下载的逻辑改回根据实际的body类型做判断. 这样也好让用户更平滑地升级上来.
--
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.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Java-Chassis 2.8分支能否将文件下载响应的判断方式从根据接口契约判断改为根据运行时返回的body类型判断? [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 closed issue #4425: Java-Chassis 2.8分支能否将文件下载响应的判断方式从根据接口契约判断改为根据运行时返回的body类型判断?
URL: https://github.com/apache/servicecomb-java-chassis/issues/4425
--
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.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Java-Chassis 2.8分支能否将文件下载响应的判断方式从根据接口契约判断改为根据运行时返回的body类型判断? [servicecomb-java-chassis]
Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4425:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4425#issuecomment-2252311718
建议业务优先调整下代码。这种写法的正确语义是2.x的,1.x只是刚好碰巧运行正确,因为从接口语义来讲,它生成的契约也不是下载(即binary类型)。
是否能改为body类型还需要分析下,估计应该是不可以的,会引入歧义,造成其他正常场景出现问题。
--
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.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org