拦截服务器java中的HTTP请求 [英] Intercept HTTP requests in server java

查看:1743
本文介绍了拦截服务器java中的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现像过滤器或监听器之类的东西来拦截HTTP请求并为各种目的检索HTTP标头。

I need to implemented something like a filter or listener, that intercepts HTTP requests and retrieves the HTTP headers for various purposes.

我使用Java,Jboss应用服务器和网页服务。我希望在Web服务调用之前执行此过滤系统 - 考虑方面但他们不保存HTTP相关的东西。在过滤器之后,应该执行服务调用。

I use Java, Jboss application server and web services. I want this filtering system to be performed prior to the Web Services call - was thinking about aspects but they do not hold the HTTP related stuff. After the filter, the service call should be carried out.

Jax-WS处理程序对我来说不起作用,因为它们只保存SOAP有效负载。

Jax-WS handlers don't work for me either as they only hold the SOAP payload.

任何想法?

提前致谢。

推荐答案

你能不能创建一个servlet过滤器来拦截所有进入你的webservice引擎的请求?如果您使用的是Axis或任何其他SOAP引擎,我希望您能够创建一个过滤器来拦截进入SOAP引擎提供的主servlet的所有请求。

can you not create a servlet filter which intercepts all the requests coming to your webservice engine? If you are using Axis or anyother SOAP engine, I hope you should be able to create a filter that intercepts all the requests coming to the main servlet that the SOAP engine provides.

 public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,ServletException
  {
    HttpServletRequest httpRequest=(HttpServletRequest)request;
    HttpServletResponse httpResponse=(HttpServletResponse)response;
       Enumeration headerNames = httpRequest.getHeaderNames();
        while(headerNames.hasMoreElements()) {
          String headerName = (String)headerNames.nextElement();
          out.println(headerName);
          out.println(request.getHeader(headerName));
        }
       chain.doFilter(request,response);
}

这篇关于拦截服务器java中的HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆