Example usage for javax.servlet.http HttpServletRequestWrapper getHeader

List of usage examples for javax.servlet.http HttpServletRequestWrapper getHeader

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequestWrapper getHeader.

Prototype

@Override
public String getHeader(String name) 

Source Link

Document

The default behavior of this method is to return getHeader(String name) on the wrapped request object.

Usage

From source file:com.marvelution.hudson.plugins.apiv2.servlet.filter.HudsonAPIV2ServletFilter.java

/**
 * {@inheritDoc}// w  w  w. j av a  2  s.  c  om
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    // The Wink RestFilter can only handle HttpServletRequests so make sure we have one
    if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
        // Put the original HttpServletRequest in the HttpServletRequestWrapper
        final HttpServletRequestWrapper servletRequest = new HttpServletRequestWrapper(
                (HttpServletRequest) request);
        // Get the requestUri without the context path and the leading slash
        String requestUri = servletRequest.getPathInfo();
        if (StringUtils.isNotBlank(requestUri) && requestUri.startsWith("/")) {
            requestUri = requestUri.substring(1);
        }
        LOGGER.log(Level.FINE, "Got a request from URI: " + requestUri + " with Accept Header: "
                + servletRequest.getHeader("Accept"));
        // Make sure it is a REST call
        if (StringUtils.isNotBlank(requestUri) && requestUri.startsWith(BaseRestResource.BASE_REST_URI)) {
            validateRuntimeDelegate();
            LOGGER.log(Level.FINE, "Got a REST request, forwarding it to the Wink RestFilter");
            FilteredHttpServletResponse servletResponse = new FilteredHttpServletResponse(
                    (HttpServletResponse) response);
            restServlet.service(servletRequest, servletResponse);
            if ((!(servletResponse.isCommitted())) && (servletResponse.getStatusCode() == 404)) {
                LOGGER.log(Level.FINE, "Filter " + this.getClass().getName()
                        + " did not match a resource so letting request continue on FilterChain");
                servletResponse.setStatus(200);
                filterChain.doFilter(request, response);
            }
            // Otherwise forward the request to the next Filter in the chain
        } else {
            LOGGER.log(Level.FINE, "No REST request, forwarding request to the next ServletFilter");
            filterChain.doFilter(request, response);
        }
        // If we don't have a HttpServletRequest and HttpServletResponse then forward to the next Filter in the chain
    } else {
        LOGGER.log(Level.FINE,
                "No HttpServletRequest and HttpServletResponse, forwarding request to the next ServletFilter");
        filterChain.doFilter(request, response);
    }
}