You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Horváth Márton <Ma...@corvex.hu> on 2013/07/25 15:25:50 UTC

CXF java.util.Date problem

Hi,

I have faced a strange issue when passing a java.util.Date through CXF (version is 2.7.4) web-service from client to server side. On the client side a java.util.Date is created (Wed Jul 31 23:59:59 GMT 2013) and passed to the web service. In the soap request the date is still correct (2013-07-31T23:59:59.999Z), but when the server side method is called in the argument the date is changed (Thu Aug 01 01:59:59 CEST 2013). It's off with plus 2 hours which is I think the difference between GMT and my timezone (CET). But what and why changes the date this way and how can I avoid this behaviour?
Thank you for your help!

Best regards,
Márton Horváth

RE: CXF java.util.Date problem

Posted by Horváth Márton <Ma...@corvex.hu>.
I managed to find the solution for the problem: the two Glassfish I used had different timezones set (with the -Duser.timezone jvm option), one was set to GMT and one was using the default CET. After I changed the GMT setting to CET the problem is gone.
Thank you for your help anyway!

Best regards,
Márton Horváth
________________________________________
Feladó: Sergey Beryozkin [sberyozkin@gmail.com]
Küldve: 2013. július 25. 18:19
To: users@cxf.apache.org
Tárgy: Re: CXF java.util.Date problem

Hi
On 25/07/13 14:25, Horváth Márton wrote:
> Hi,
>
> I have faced a strange issue when passing a java.util.Date through CXF (version is 2.7.4) web-service from client to server side. On the client side a java.util.Date is created (Wed Jul 31 23:59:59 GMT 2013) and passed to the web service. In the soap request the date is still correct (2013-07-31T23:59:59.999Z), but when the server side method is called in the argument the date is changed (Thu Aug 01 01:59:59 CEST 2013). It's off with plus 2 hours which is I think the difference between GMT and my timezone (CET). But what and why changes the date this way and how can I avoid this behaviour?

Is this Date passed as part of the soap payload itself ? If so then I
guess you may need to plugin somehow into the way JAXB reads the dates
(XmlJavaTypeAdapter I guess), example, make sure that the same Date
pattern, ex, ensure GMT timezone is set, example:

// replace the string pattern with the one matching Wed Jul 31 23:59:59
GMT 2013:


SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy
HH:mm:ss zzz", Locale.US);
TimeZone tZone = TimeZone.getTimeZone("GMT");
dateFormat.setTimeZone(tZone);

Might help,

Cheers, Sergey

> Thank you for your help!
>
> Best regards,
> Márton Horváth
>



Re: CXF java.util.Date problem

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 25/07/13 14:25, Horváth Márton wrote:
> Hi,
>
> I have faced a strange issue when passing a java.util.Date through CXF (version is 2.7.4) web-service from client to server side. On the client side a java.util.Date is created (Wed Jul 31 23:59:59 GMT 2013) and passed to the web service. In the soap request the date is still correct (2013-07-31T23:59:59.999Z), but when the server side method is called in the argument the date is changed (Thu Aug 01 01:59:59 CEST 2013). It's off with plus 2 hours which is I think the difference between GMT and my timezone (CET). But what and why changes the date this way and how can I avoid this behaviour?

Is this Date passed as part of the soap payload itself ? If so then I 
guess you may need to plugin somehow into the way JAXB reads the dates 
(XmlJavaTypeAdapter I guess), example, make sure that the same Date 
pattern, ex, ensure GMT timezone is set, example:

// replace the string pattern with the one matching Wed Jul 31 23:59:59 
GMT 2013:


SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy 
HH:mm:ss zzz", Locale.US);
TimeZone tZone = TimeZone.getTimeZone("GMT");
dateFormat.setTimeZone(tZone);

Might help,

Cheers, Sergey

> Thank you for your help!
>
> Best regards,
> Márton Horváth
>