我有JAX-RS REST API,我需要加密添加到的答覆,所以我加入一個Servlet過濾器:JAX-RS和Servlet過濾器:IllegalStateException異常:響應已承諾
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
ServletRequestWrapper request = new ServletRequestWrapper((HttpServletRequest) servletRequest);
ServletResponseWrapper response = new ServletResponseWrapper((HttpServletResponse) servletResponse);
PrintWriter out = response.getWriter();
filterChain.doFilter(request, response);
response.getResponse().resetBuffer();
String servletResponseString = response.toString();
out.write("Hola"); // Here you can change the response
out.flush();
out.close();
logger.info("AFTER filter, original response: "
+ servletResponseString);
}
但我得到java.lang.IllegalStateException: Response already committed
使用JAX-RS和servlet過濾器有什麼問題嗎?有沒有辦法保留髮送回復?
謝謝。
什麼JAX-RS的實現和版本您使用的是什麼? –