JAX-RS Apache Oltu服务器请求带有JSON主体



我正在尝试使用ApacheOltu在我的JAX-RS应用程序中实现OAuth2。我发现:https://github.com/apache/oltu/tree/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints

@POST
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public Response authorize(@Context HttpServletRequest request) throws OAuthSystemException
{
    OAuthTokenRequest oauthRequest = null;
    OAuthIssuer oauthIssuerImpl = new OAuthIssuerImpl(new MD5Generator());
    try {
        oauthRequest = new OAuthTokenRequest(request);
    } catch (OAuthProblemException e) {
    OAuthResponse res = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST).error(e)
            .buildJSONMessage();
    return Response.status(res.getResponseStatus()).entity(res.getBody()).build();
}

这适用于application/x-www-form-urlencoded。然而,我也想得到对application/json的支持。我找不到任何关于如何扩展或实现它的文档。有人熟悉这个问题吗?

最好我想重用OAuthTokenRequest

默认情况下,JAX-RSapi中的@Consumes@Produces注释支持字符串数组。您可以像这样声明REST端点以支持多种格式:@Consumes({"application/x-www-form-urlencoded", "application/json"})

最新更新