title: Getting hostname of the client that is calling my JAX-RS rest webservice
body: <p>I have developed my rest service in JAX-RS Jersey. I have deployed in the Tomcat 7.0. Now I am exposing my web service URL to third party client. I want to put validation mechanism that includes getting host name i.e. the client host name that is using my service. I would like to match with our database entered host name. How to get the host name of the client?</p>
  
  <p>Here is my web.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;servlet&gt;
      &lt;servlet-name&gt;ServletAdaptor&lt;/servlet-name&gt;
          &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;ServletAdaptor&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/intellixservices/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;secureRESTFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;com.astroved.intellix.security.SecurityFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;secureRESTFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/intellixservices/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>Now I am creating a SecurityFilter class implementing Filter. inside doFilter() method -</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  public void doFilter(ServletRequest req, ServletResponse res,
          FilterChain chain) throws IOException, ServletException {
      HttpServletRequest httpReq = (HttpServletRequest) req;
      HttpServletResponse httpRes = (HttpServletResponse)res;
      String url = "http://localhost:8888/IntellixWebApi/intellixservices/dnareport";
      System.out.println("In security filter");
      req.getRequestDispatcher(url).forward(req, res);    
  
      chain.doFilter(httpReq, httpRes);
  }
  </code></pre>
  
  <p>But it is not forwarding to the next URL. In <code>Resource</code> class, it is returning xml/json type. </p>