I use jersey-client to consume a REST service.
I need both the requested Entity and the Last-Modified header.
So I do the following:
ClientResponse response = webResource.get(ClientResponse.class);
Person person = response.getEntity(Person.class);
That works. I get a response and I can marshal the Entity (wich is XML) into my POJO.
When I debug and take a look into the Headers of the response, then I see that there is a Last-Modified header set.
But when I try to retrieve the date via
response.getLastModified();
I get a NPE somewhere in URLConnectionClientHandler.
Has anyone a clue what I do wrong?
edit: as requested the trace
java.lang.NullPointerException: null
at com.sun.jersey.api.client.ClientResponse.getLastModified(ClientResponse.java:647) ~[jersey-client-1.12.jar:1.12]
at a.o.u.user.dao.impl.uds.PersonenUdsClient.getPerson(PersonenUdsClient.java:103) ~[um-user-2.5.0-Beta1-SNAPSHOT.jar:na]
at a.o.u.user.dao.impl.UserDaoUdsImpl.mergeWithUdsUser(UserDaoUdsImpl.java:282) ~[um-user-2.5.0-Beta1-SNAPSHOT.jar:na]
at a.o.u.user.dao.impl.UserDaoUdsImpl.getUserWithEmail(UserDaoUdsImpl.java:124) ~[um-user-2.5.0-Beta1-SNAPSHOT.jar:na]
at ...
edit: as npe suggested I digged into the code. I think I found the problem. Beside jersey-client I also have cxf in the classpath. Both jersey and cxf provide a class called RuntimeDelegateImpl. But CXFs version does not feature a DateHeaderDelegate. I think the wrong version (CXFs) of RuntimeDelegateImpl is taken.
By now I have not found how I can explicitely set the RuntimeDelegateImpl to use.
To make it a wrap.
The problem is that I have both jersey-client and cxf in the classpath. Both RuntimeDelegateImpl. But CXFs version does not feature a DateHeaderDelegate. The wrong version (CXFs) of RuntimeDelegateImpl is taken.
I solved the issue by retrieving the Last-Modified Header ‘manually’:
Thanx to npe for the hints.