Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

ContainerRequestFilters with a @PreMatching annotation are run before the JAX-RS resource selection process starts. PreMatching filters should be used to modify request URI , or headers or input stream. Post-matching filters are run just before a selected resource method is executed.

Multiple ContainerRequestFilter and ContainerResponseFilter filters can be ordered using a @Priority annotation.

 

The implementations can be registered like any other types type of providers :

Code Block
xml
xml
<beans>
<jaxrs:server id="customerService" address="/">
    <jaxrs:serviceBeans>
      <bean class="org.CustomerService" />
    </jaxrs:serviceBeans>

    <jaxrs:providers>
      <ref bean="authorizationFilter" />
    </jaxrs:providers>
    <bean id="authorizationFilter" class="com.bar.providers.AuthorizationContainerRequestFilter">
        <!-- authorization bean properties -->
    </bean>
</jaxrs:server>
</beans>

...

Using filters and interceptors makes it possible to override all the needed request/response properties.

Overriding HTTP method

Register Use @PreMatching ContainerRequestFilter or register a custom RequestHandler CXF in intrerceptor filter which will replace the current method value keyed by
Message.HTTP_REQUEST_METHOD in a given Message.

...

One can do it either from a @PreMatching ContainerRequestFilter or CXF input interceptor (registered at the early phase like USER_STREAM) or from a RequestHandler filter, for example :

Code Block
java
java
String s = m.get(Message.REQUEST_URI);
s += "/data/";
m.put(Message.REQUEST_URI, s);

...

It is assumed here a user prefers not to use explicit Response objects in the application code.
This can be done either from a ContainerResponseFilter or CXF output interceptor (phase like MARSHALL will do) or from a ResponseHandler filter, for example this code will work for both JAXRS and JAXWS :

...

In some cases you may want to have a JAXRS Response entity which a given RequestHandler or ResponseHandler filter has produced to be directly written to the output stream. For example, a CXF JAXRS WADLGenerator RequestHandler filter produces an XML content which does not have to be serialized by JAXRS MessageBodyWriters. If you do need to have the writers ignored then set the following property on the current exchange in the custom handler :

...