You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "tell1014 (via GitHub)" <gi...@apache.org> on 2023/10/30 10:21:04 UTC

[I] 在Dubbo 3.2.7使用rest无法自定义HTTP响应status [dubbo]

tell1014 opened a new issue, #13287:
URL: https://github.com/apache/dubbo/issues/13287

   <!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy -->
   
   - [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: 3.2.7
   * Operating System version: win10
   * Java version: java8
   
   ### Steps to reproduce this issue
   
       @DELETE
       @Path("{uid}")
       public Response deleteUserById(@PathParam("uid") String uid) {
           return Response.status(300).build();
       }
     无法设置自定义响应码,无论怎么设置所有响应都为200。
   
   


-- 
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: notifications-unsubscribe@dubbo.apache.org.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] 在Dubbo 3.2.7使用rest无法自定义HTTP响应status [dubbo]

Posted by "CrazyHZM (via GitHub)" <gi...@apache.org>.
CrazyHZM closed issue #13287: 在Dubbo 3.2.7使用rest无法自定义HTTP响应status
URL: https://github.com/apache/dubbo/issues/13287


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] 在Dubbo 3.2.7使用rest无法自定义HTTP响应status [dubbo]

Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on issue #13287:
URL: https://github.com/apache/dubbo/issues/13287#issuecomment-1788890788

   @CrazyHZM @suncairong163 PTAL


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] 在Dubbo 3.2.7使用rest无法自定义HTTP响应status [dubbo]

Posted by "kazetyan (via GitHub)" <gi...@apache.org>.
kazetyan commented on issue #13287:
URL: https://github.com/apache/dubbo/issues/13287#issuecomment-1867454337

   看了下这块的代码,`javax.ws.rs.core.Response` 类型的返回值只对body做了codec,没有对status做处理,你可以自定义一个`RestResponseInterceptor` 来处理
   ```java
   @Activate(value = "rsResp", onClass = {"javax.ws.rs.core.Response"})
   public class RsResponseInterceptor implements RestResponseInterceptor {
       @Override
       public void intercept(RestInterceptContext restResponseInterceptor) throws Exception {
           if (restResponseInterceptor.getResult() instanceof Response) {
               Response result = (Response) restResponseInterceptor.getResult();
               restResponseInterceptor.getResponse().setStatus(result.getStatus());
           }
       }
   }
   ```
   添加spi文件
   ![image](https://github.com/apache/dubbo/assets/50894526/90bc643e-2177-447d-a8d8-6e323acf950e)
   ```plain
   rsResp=org.apache.dubbo.demo.rest.api.extension.RsResponseInterceptor
   ```
   ### 测试
   ```java
   @DELETE
   @Path("{uid}")
   public Response deleteUserById(@PathParam("uid") String uid) {
       return Response.status(300).entity("deleted").build();
   }
   ```
   ![image](https://github.com/apache/dubbo/assets/50894526/5c08f952-09fb-4afe-956c-a825420e3d09)
   <br/>
   不确定dubbo是否应该内置这个`RestResponseInterceptor` ,或者其他更好的方式来处理
   


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org