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/02/26 07:34:26 UTC

[GitHub] [servicecomb-java-chassis] guoHuanMessi opened a new issue #2254: 改造CSE 后 RequestContextHolder依赖于Spring MVC REST来设置请求上下文,在整改后,获取到的attributes为空,从而导致抛出NPE异常

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


   
       public static HttpServletRequest getServletRequest() {
           ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.currentRequestAttributes();
           return requestAttributes.getRequest();
       }
   
   	public static RequestAttributes currentRequestAttributes() throws IllegalStateException {
   		RequestAttributes attributes = getRequestAttributes();
   		if (attributes == null) {
   			if (jsfPresent) {
   				attributes = FacesRequestAttributesFactory.getFacesRequestAttributes();
   			}
   			if (attributes == null) {
   				throw new IllegalStateException("No thread-bound request found: " +
   						"Are you referring to request attributes outside of an actual web request, " +
   						"or processing a request outside of the originally receiving thread? " +
   						"If you are actually operating within a web request and still receive this message, " +
   						"your code is probably running outside of DispatcherServlet: " +
   						"In this case, use RequestContextListener or RequestContextFilter to expose the current request.");
   			}
   		}
   		return attributes;
   	}
   
   attributes  为空 ,因为cse定义了自己的上下文,对于这种依赖spring上下文如何处理。
   
   


----------------------------------------------------------------
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 edited a comment on issue #2254: 改造CSE 后 RequestContextHolder依赖于Spring MVC REST来设置请求上下文,在整改后,获取到的attributes为空,从而导致抛出NPE异常

Posted by GitBox <gi...@apache.org>.
liubao68 edited a comment on issue #2254:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2254#issuecomment-786973305


   这类问题需要结合业务场景和目的进行分析和设计方案,即使用RequestAtrributes做什么事情,达到什么目的,然后寻找替代方案。 通常会用到Context参数, 参考:https://docs.servicecomb.io/java-chassis/zh_CN/build-provider/catalog/


----------------------------------------------------------------
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 #2254: 改造CSE 后 RequestContextHolder依赖于Spring MVC REST来设置请求上下文,在整改后,获取到的attributes为空,从而导致抛出NPE异常

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


   这类问题需要结合业务场景和目的进行分析和设计方案。 通常会用到Context参数, 参考:https://docs.servicecomb.io/java-chassis/zh_CN/build-provider/catalog/


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