0

我正在尝试使用 Apache Oltu 在我的 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

4

1 回答 1

0

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

于 2015-12-11T14:29:34.390 回答