0
我有一個資源類作爲訪問PostProcessInterceptor中的資源類字段?
@Path("secure")
@RequestScoped
// @SecurityChecked
public class SecureResource {
@Context
private HttpServletRequest request;
@GET
@SecurityChecked
public Response getUser() {
return Response.ok("authenticated successfully!").build();
}
@POST
public Response login(@FormParam("user") @Nonnull final String user,
@FormParam("password") @Nonnull final String password) {
final String authToken = TokenUtils.createToken(user);
return Response.ok().header(AUTH_TOKEN, authToken).build();
}
@PUT
public Response updateUser() {
return Response.ok("updating user").build();
}
}
,我有一個PostProcessInterceptor
,我想訪問頭類的request
@Interceptor
@Provider
@ServerInterceptor
@SecurityChecked
public class SecurityCheckInterceptor implements PostProcessInterceptor {
private static final Pattern PATTERN = Pattern.compile(":");
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityCheckInterceptor.class);
@Override
public void postProcess(final ServerResponse response) {
// access the Resource class request object
}
}
我不知道我怎麼可以在這裏訪問請求對象
請幫
謝謝
是的,因爲請求有'Headers',我需要在發送響應之前訪問這些來創建一個新的Header。這有意義嗎? – daydreamer
我不熟悉這個api。也許看看http://www.mastertheboss.com/resteasy/resteasy-interceptors-tutorial/page-2,其中respone對象是在preProcess處理程序中手動創建的 - 新的頭文件