jersey
  1. jersey
  2. JERSEY-2094

custom ContainerResponseFilter never get executed

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 2.2
    • Fix Version/s: 2.4.1
    • Component/s: core
    • Labels:
      None
    • Environment:

      Linux, latest stable Jersey release obtained with mvn

      Description

      Following the getting started guide on your website:

      https://jersey.java.net/documentation/latest/getting-started.html

      I executed the following build command:

      $ mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \
      -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
      -DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \
      -DarchetypeVersion=2.2

      I then followed your tutorial on

      https://jersey.java.net/documentation/latest/filters-and-interceptors.html#d0e6783

      to add a custom ContainerResponseFilter:

      @NameBinding
      @Retention(RetentionPolicy.RUNTIME)
      static @interface CORSBinding {}

      @Provider
      @Priority(Priorities.HEADER_DECORATOR)
      @CORSBinding
      static class CrossDomainFilter implements ContainerResponseFilter {
      @Override
      public void filter(ContainerRequestContext creq, ContainerResponseContext cres) {
      Logger.getLogger("com.example").log( Level.INFO, "before:

      {0}", cres.getHeaders());
      cres.getHeaders().add("Access-Control-Allow-Origin", "*");
      cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
      cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
      cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
      cres.getHeaders().add("Access-Control-Max-Age", "1209600");
      Logger.getLogger("com.example").log( Level.INFO, "after: {0}

      ", cres.getHeaders());
      }
      }

      I tried to register this filter with Named Binding and with Dynamic Binding, nothing works.

      To easily reproduce, I also tried an example from your sources:

      https://github.com/jersey/jersey/tree/2.2/examples/exception-mapping

      The same problem: the custom filters do not get executed.

        Issue Links

          Activity

          Hide
          kithouna added a comment -

          I think this is actually a Blocker, but I cannot change the priority.

          Show
          kithouna added a comment - I think this is actually a Blocker, but I cannot change the priority.
          Hide
          Marek Potociar added a comment - - edited

          Can you please send us your code? The behavior you report as broken passes several Jersey tests. The exception mapping example also has tests and those are invokde daily many times succesfully. So chances are that the bug is in your code.

          Show
          Marek Potociar added a comment - - edited Can you please send us your code? The behavior you report as broken passes several Jersey tests. The exception mapping example also has tests and those are invokde daily many times succesfully. So chances are that the bug is in your code.
          Hide
          Marek Potociar added a comment -

          Closing as incomplete. The requested code to reproduce the bug has not been provided.

          Show
          Marek Potociar added a comment - Closing as incomplete. The requested code to reproduce the bug has not been provided.

            People

            • Assignee:
              Unassigned
              Reporter:
              kithouna
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: