Closed HeiXXwowoTou closed 1 year ago
I discussed with my team leader just now, which might be because of the following code. Is there any good way
package com.labway.sso.starter.common;
import com.labway.sso.core.user.SsoUser;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
public class SsoUserHelper {
private SsoUserHelper() {
}
public static SsoUser getLoginUser() {
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
Object userObject = request.getAttribute("labway_sso_user");
return Objects.isNull(userObject) ? null : (SsoUser)userObject;
}
}
whats the code from ?
whats the code from ?
This code is a project of my own
whats the code from ?
In case I wasn't clear enough, this code is a class that gets user information from our login, and my dubbo project depends on our login
I discussed with my team leader just now, which might be because of the following code. Is there any good way
package com.labway.sso.starter.common; import com.labway.sso.core.user.SsoUser; import java.util.Objects; import javax.servlet.http.HttpServletRequest; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; public class SsoUserHelper { private SsoUserHelper() { } public static SsoUser getLoginUser() { HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); Object userObject = request.getAttribute("labway_sso_user"); return Objects.isNull(userObject) ? null : (SsoUser)userObject; } }
我觉得问题可能是我的这个类去获取request对象中的信息,这个request已经被读取过的这种问题?类似于 主线程读取过之后子线程就无法读取这样?这个问题可以提供一个解决思路吗
目前我的解决方案,在网关层定义了过滤器,将token信息传递在RpcContext中,在我的服务中进行获取
Question
environment: shenyu: 2.5.1, spring-boot: 2.3.2.RELEASE, spring-cloud: Hoxton.SR9 spring-cloud-alibaba: 2.2.6.RELEASE spring-cloud-starter-dubbo: 2.2.6.RELEASE jdk:11
my own service dependent and config:
My problem is as follows: After I used my dubbo to access our shenyu gateway, the GET request could be successful, but my Post interface, using the body parameter, my program has an error
I suspect it may be because the body request body or the request header has not been passed, but I have not found relevant information for the configuration or operation of this part, so I ask for help