It definitely works for me,
I just added
headers.add("Foo", "Bar");
to
http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GenericHandlerWriter.java
just before the delegation to the JAXBProvider occurs and I can see
HTTP/1.1 200 OK
Content-Type: application/xml
BookId: 123
Date: Wed, 02 Dec 2009 17:00:56 GMT
Foo: Bar
Content-Length: 106
Server: Jetty(6.1.21)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Book><id>123</id><name>CXF in
Action</name></Book>
Paul, what CXF version you use, I think it was CXF 2.2.5 which you
mentioned...Any chnace you can step into the code ?
thanks, Sergey
----- Original Message -----
From: "Sergey Beryozkin" <[email protected]>
To: "Paul Wilton" <[email protected]>; <[email protected]>
Sent: Wednesday, December 02, 2009 4:49 PM
Subject: Re: setting response headers in AtomFeedProvider
Hi Paul
let me write a little test, using a derived provider, exactly the way you did
it.
The filter will have a Response as one of the input parameters, this is a
Response which will be eventually serialized by your
provider, response.getEntity() will return a Feed instance. You'd need to create a new Response and copy this entity into it and
also set the headers as needed on the new Response...However, let me write a quick test first
cheers, Sergey
Hi Sergey
I have tried
headers.add("CustomHeader", "bar");
headers.add("Last-Modified",
org.apache.cxf.jaxrs.utils.HttpUtils.getHttpDateFormat().format(feed.get
Updated());
and nothing is on the Wire..
If I add a custom ResponseHandler filter - how would this filter now
about my feed object in order that I can extract the date from it ?
(would prefer to do it in the Provider really)
Cheers
Paul
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: 02 December 2009 15:36
To: Paul Wilton; [email protected]
Subject: Re: setting response headers in AtomFeedProvider
Hi Paul
This really has to work...
Can you please try, just for the sake of the test, doing
headers.add("CustomHeader", "bar");
and see if it's there on the wire.
I'm just thinking that may be it is the fact that a Date as opposed to
String which is being set in your case that affects it ?
If you were setting this header on the JAXRS ResponseBuilder then the
CXF would convert a Date into a properly formatted value but
in this case the headers go directly to the AbstractHttpDestination and
eventually to the container...
If headers.add("CustomHeader", "bar");
works then you can do
headers.add("Last-Modified",
org.apache.cxf.jaxrs.utils.HttpUtils.getHttpDateFormat().format(feed.get
Updated());
By the way, is feed.getUpdated() returning something ?
Another option, provided you would not like to return a Response
directly from your service class, is to register a custom
ResponseHandler filter and set this Date from there.
let me know please how it goes
Sergey
----- Original Message -----
From: "Paul Wilton" <[email protected]>
To: <[email protected]>
Cc: "Sergey Beryozkin" <[email protected]>
Sent: Wednesday, December 02, 2009 12:29 PM
Subject: setting response headers in AtomFeedProvider
Hi Sergey,
I was planning on setting a response header (Last-Modified, expires,
cache-control etc) in an extended AtomFeedProvider based on the Feed
updated data,
for example:
public class AtomFeedProvider extends
org.apache.cxf.jaxrs.provider.AtomFeedProvider {
@Override
public void writeTo(Feed feed, Class<?> clazz, Type type,
Annotation[] a, MediaType mt, MultivaluedMap<String, Object> headers,
OutputStream os) throws IOException {
headers.add("Last-Modified", feed.getUpdated());
super.writeTo(feed, clazz, type, a, mt, headers, os);
}
}
However, in the source
org.apache.cxf.jaxrs.provider.AtomFeedProvider.writeTo() method the
headers are ignored (lost).
Is this the correct approach I am taking to add headers, or is this a
bug, or is there a better way ?
Thanks
Paul
This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless
specifically stated. If you have received it in error, please delete it
from your system. Do not use, copy or disclose the
information in any way nor act in reliance on it and notify the sender
immediately.
Please note that the BBC monitors e-mails sent or received. Further
communication will signify your consent to this
This e-mail has been sent by one of the following wholly-owned
subsidiaries of the BBC:
BBC Worldwide Limited, Registration Number: 1420028 England, Registered
Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World News Limited, Registration Number: 04514407 England,
Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World Distribution Limited, Registration Number: 04514408,
Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ