title: Jersey filter giving server error
body: <p>I am using jersey filter.<br>
  In My code logic in <code>AuthenticationFilter.java</code>, if the authorization header is empty, then return the access denied error message.<br>
  First time I am hitting the application through rest client tool using the URL without attaching the header</p>
  
  <pre><code>http://localhost:8080/JerseyDemos2/rest/pocservice
  </code></pre>
  
  <p>Get the status 401 with error message <strong>"you cannot access this resource"</strong>. This is right.</p>
  
  <p>When i tried to hit second time thorugh rest client tool, and server return the exception message. </p>
  
  <p>I deployed my application in <strong>tomcat 7.x</strong> both windows and linux</p>
  
  <p>Why it give the error when we hit the second time.
  How to resolve this</p>
  
  <pre><code>@Provider
  public class AuthenticationFilter implements javax.ws.rs.container.ContainerRequestFilter {
  
  @Context
  private ResourceInfo resourceInfo;
  
  private static final String AUTHORIZATION_PROPERTY = "Authorization";
  private static final Response ACCESS_DENIED = Response.status(Response.Status.UNAUTHORIZED).entity("You cannot access this resource").build();  
  
  @Override
  public void filter(ContainerRequestContext requestContext) {    
  
          // Get request headers
          final MultivaluedMap&lt;String, String&gt; headers = requestContext.getHeaders();
  
          // Fetch authorization header
          final List&lt;String&gt; authorization = headers.get(AUTHORIZATION_PROPERTY);
  
          // If no authorization information present; block access
          if (authorization == null || authorization.isEmpty()) {
              requestContext.abortWith(ACCESS_DENIED);
              return;
          }
      }
  }   }
  </code></pre>
  
  <p><strong>Error message:</strong></p>
  
  <pre><code>Dec 19, 2016 6:26:18 PM org.glassfish.jersey.server.ServerRuntime$Responder writeResponse
  SEVERE: An I/O error has occurred while writing a response message entity to the container output stream.
  java.lang.IllegalStateException: The output stream has already been closed.
  at org.glassfish.jersey.message.internal.CommittingOutputStream.setStreamProvider(CommittingOutputStream.java:147)
  at org.glassfish.jersey.message.internal.OutboundMessageContext.setStreamProvider(OutboundMessageContext.java:803)
  ......
  </code></pre>
  
  <p>Please help me
  Thanks in advance.</p>