我正在将 Oltu 用于 Oauth2。
使用@Context HttpServletRequest 请求时,我无法检索发布数据
当我使用 @FormParam 时,我能够检索帖子数据。
将请求传递给 OAuthTokenRequest
OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);
我收到以下错误
{"error":"invalid_request","error_description":"缺少 grant_type 参数值"}
在 oltu OAuthTokenRequest 类上进行调试时,使用以下代码检索参数值
public String getParam(String name) {
return this.request.getParameter(name); // from request it is unable to get post data.As i am getting request object using @Context HttpServletRequest request .
}
据说使用@Context HttpServletRequest 请求无法获取使用@Context HttpServletRequest 请求的帖子数据所以,我的问题是
如何在 jax-ws 中使用 post 数据获取 HttpServletRequest 请求,以便我可以将 HttpServletRequest 请求传递给 OAuthTokenRequest 这是我的代码
@Path("/token")
public class TokenEndpoint {
@POST
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public Response authorize(@FormParam("state") String state,@Context HttpServletRequest request) throws OAuthSystemException {
try {
// here I am unable to get value of request.getParameter("state")
// but using (@FormParam("state") I am able to get value of post parameter state
request.getParameter("state");
// exception is thrown from following code
OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);