cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Voß, Marko <Marko.V...@fiz-Karlsruhe.de>
Subject Manipulating response header without returning javax.ws.rs.core.Response
Date Mon, 26 Mar 2012 15:04:41 GMT
Hello,

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

@Path("/foo")
public interface Foo {

   @Path("/{id}")
   ...
   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 javax.ws.rs.core.Response 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() {
         super(Phase.POST_LOGICAL);
     }

     public void handleMessage(Message message) {
         Map<String, List<String>> headers = (Map<String, 
List<String>>)message.get(Message.PROTOCOL_HEADERS);
         if (headers == null) {
             headers = new TreeMap<String, 
List<String>>(String.CASE_INSENSITIVE_ORDER);
             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>();
                     foo.add(meta.getLMD().toString());
                     headers.put("Last-Modified", foo);
                     return;
                 }
             }
         }
     }
}

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 
javax.ws.rs.core.Response.


Can anyone help on this issue please?


Thank you in advance and kind regards,

Marko


-------------------------------------------------------

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



Mime
View raw message