我正在尝试使用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
发布于 2015-12-11 22:29:34
默认情况下,JAX-RS中的@Consumes和@Produces注释支持字符串数组。您可以像这样声明您的REST端点以支持多种格式:@Consumes({"application/x-www-form-urlencoded", "application/json"})
https://stackoverflow.com/questions/34137488
复制相似问题