我正在尝试将一些自定义标头参数添加到HTTP 303(重定向)响应中。但是,新标题似乎从响应中被剥离。
此代码用于接收请求并返回HTTP 303响应:
@POST
@Path("/authorize")
@Produces("application/x-www-form-urlencoded")
public Response getOAuthGrant(@HeaderParam(OAuth2.AUTHORIZATION) @DefaultValue("") String authorization,
@HeaderParam(OAuth2.CLIENT_ID) @DefaultValue("") String clientId,
@HeaderParam(OAuth2.CLIENT_SECRET) @DefaultValue("") String clientSecret,
@HeaderParam(OAuth2.GRANT_TYPE) @DefaultValue("") String grantType) throws InternalServerException, UnauthorizedException {
OAuth2.validateGrantRequest(clientId, clientSecret, authorization, grantType);
ApiTokenV2 apiTokenV2 = new ApiTokenV2();
try {
apiTokenV2 = TokenManager.getApiToken(clientId);
if (apiTokenV2 != null) {
apiTokenV2.generateAccessGrant(clientId);
} else {
logger.error("Error in TokenEndpoint. Retrieved token is null.");
throw new InternalServerException("A server error occurred while trying to authorize the requester. Could not find 'generateAccessGrant' method");
}
} catch (NamingException e) {
throw new InternalServerException("A server error occurred while trying to authorize grant request. Could not find 'generateAccessGrant' method.", e);
}
return Response.status(Response.Status.SEE_OTHER)
.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
.header("Location", "/api/token")
.header("Authorization", "OAuth")
.header("Access-Grant", apiTokenV2.getAccessGrant())
.build();
}
我在这里做错了什么?我应该使用@Context
吗?