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/01/03 07:02:56 UTC
[GitHub] [servicecomb-java-chassis] whuxiari opened a new issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
whuxiari opened a new issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1509
如下图,自定义了一个过滤器,在过滤器中向请求头添加参数,在Controller中无法拿到该参数;
但是添加的Parameter参数,在Controller中可以获取到。这是为什么?

----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [servicecomb-java-chassis] whuxiari commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
Posted by GitBox <gi...@apache.org>.
whuxiari commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1509#issuecomment-570503208
接口HttpServerFilter的实现类,业务逻辑已省略,重点看:

参考文档:
https://docs.servicecomb.io/java-chassis/zh_CN/general-development/http-filter.html
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [servicecomb-java-chassis] whuxiari edited a comment on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
Posted by GitBox <gi...@apache.org>.
whuxiari edited a comment on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1509#issuecomment-570503208
接口HttpServerFilter的实现类,业务逻辑已省略,重点看截图:

在Controller中,从请求头取参数,取到的是null;用getParameter("")方法可以取到在过滤器中设置的值。
参考文档:
https://docs.servicecomb.io/java-chassis/zh_CN/general-development/http-filter.html
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [servicecomb-java-chassis] whuxiari commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
Posted by GitBox <gi...@apache.org>.
whuxiari commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1509#issuecomment-570751537
为啥不实现呢?
那这里要在Filter层设置参数到header中,在Controller层获取,应该怎么实现呢?
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [servicecomb-java-chassis] sunjinghan7331 commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
Posted by GitBox <gi...@apache.org>.
sunjinghan7331 commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1509#issuecomment-570766745
可以使用invocation这个参数进行传递.
在过滤器的afterReceiveRequest()方法中,将你要传递的header参数使用
invocation.addContext(Constants.DEVELOPER_UID, “123456”);
的方式进行包装,然后在Controller中使用
public Response logout(InvocationContext context) {
String value = context.getContext(Constants.DEVELOPER_UID);
return null;
}
即可获取到值。
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [servicecomb-java-chassis] yhs0092 commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
Posted by GitBox <gi...@apache.org>.
yhs0092 commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1509#issuecomment-570511609
因为 HttpServletRequestEx 在服务端的实现类确实没有实现 `setHeader` 和 `addHeader` 的逻辑啊。
你可以打断点debug进去看看,`org.apache.servicecomb.common.rest.filter.HttpServerFilter`接口给出了这两个方法的默认实现,是空的
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [servicecomb-java-chassis] yhs0092 commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
Posted by GitBox <gi...@apache.org>.
yhs0092 commented on issue #1509: 为什么在过滤器中,无法向HTTP请求头添加参数?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1509#issuecomment-570486785
你说的过滤器是什么过滤器,能否给一个简单的问题复现demo呢?
----------------------------------------------------------------
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
With regards,
Apache Git Services