cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Voß, Marko <>
Subject Manipulating response header without returning
Date Mon, 26 Mar 2012 15:04:41 GMT

we have an issue, where we cannot return the 
type in our method signatures of our JAX-RS interfaces. Example:

public interface Foo {

   JaxbFooObj retrieveFoo(@PathParam("id") String id) {
     return logic.retrieve(id);

JaxbFooObj is a class generated by the JAXB maven-plugin, generated from 
a schema file. The data of JaxbFooObj may be stored into a database. The 
timestamp when this data has been stored or changed should become the 
'Last-Modified' HTTP header value according to RFC 2822 or RFC 5322.
Returning is no option because we need the 
WADL-generator to use the return type to add the element type to the 
representation element. Example:

<representation mediaType="text/xml" element="prefix1:foo"/>

I tried to solve this by writing a CXF interceptor:

public class CustomOutInterceptor extends 
AbstractOutDatabindingInterceptor {

     public CustomOutInterceptor() {

     public void handleMessage(Message message) {
         Map<String, List<String>> headers = (Map<String, 
         if (headers == null) {
             headers = new TreeMap<String, 
             message.put(Message.PROTOCOL_HEADERS, headers);
         List contents = message.getContent(List.class);
         if (contents != null) {
             for (int i=0; i<contents.size(); i++) {
                 if (contents.get(i) instanceof MetaObject) {
                     MetaObject meta = (MetaObject)contents.get(i);
                     contents.set(i, meta.getObj());

                     List<String> foo = new ArrayList<String>();
                     headers.put("Last-Modified", foo);

The MetaObject contains the JaxbFooObj and the last modification date. 
This works but again, the element type is missing the in the generated 
WADL. So the result is the same as by simply returning

Can anyone help on this issue please?

Thank you in advance and kind regards,



Fachinformationszentrum Karlsruhe, Gesellschaft für wissenschaftlich-technische Information
Sitz der Gesellschaft: Eggenstein-Leopoldshafen, Amtsgericht Mannheim HRB 101892. 
Geschäftsführerin: Sabine Brünger-Weilandt. 
Vorsitzender des Aufsichtsrats: MinDirig Dr. Thomas Greiner.

View raw message