我有一项任务是检查传入的HTTP请求,并对标头和请求主体进行一些处理,然后在本地存储。
如果我理解正确,我可以使用apache module用于Apache服务器和IIS extension用于IIS。我不清楚我将用于基于Java的应用程序服务器。
任何帮助/指导将不胜感激。
答案 0 :(得分:0)
也许你可以使用HttpServlet。
另请查看tutorial。
答案 1 :(得分:0)
如果您将使用Java应用程序服务器,那么您应该在Servlet过滤器中处理它。这是一个例子:
@WebFilter("/app/*")
public class LoginFilter implements Filter {
@Override
public void init(FilterConfig config) throws ServletException {
//Set init params and load any resources to be used in this class.
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
//Here you will pre and post process the request-response cycle.
//Pre process is before executing "chain.doFilter(req, res);"
//Post process is after executing "chain.doFilter(req, res);"
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
String someRequestHeader = request.getHeader("<header-you-want-or-need>");
//do what you need to do
chain.doFilter(req, res);
}
@Override
public void destroy() {
//Close/free any resources used in this class.
}
}
更多信息: