mace-opensaml-users - XML DateTime handling in wstrust branch
Subject: OpenSAML user discussion
List archive
- From: Joakim Recht <>
- To:
- Subject: XML DateTime handling in wstrust branch
- Date: Wed, 05 Nov 2008 13:02:15 +0100
Hi
I don't know if the WSTrust branch is still active, but we're using it, and I've run into a problem with xml date parsing in AbstractDateTimeType - xml datetime canonicalization specifies that a timestamp must have 3 millisecond digits. However, the millisecond must not end on a 0.
So, 2008-10-10T12:00:00.000Z must be written as 2008-10-10T12:00:00Z. Lovely.
The problem is that the datetimetypes uses a DateTimeFormatter to parse a datetime, and the formatter expects exactly 3 digits. I've attached a patch which uses the standard XMLGregorianCalendar which is able to parse all valid representations of xml datetime.
Rgards,
--
Joakim Recht
Trifork A/S, Margrethepladsen 4, 8000 Aarhus C, Denmark
Phone: +45 8732 8787 / Mobile: +45 2021 6257
http://www.trifork.com - E-mail:
Index: src/main/java/org/opensaml/ws/wssecurity/impl/AbstractDateTimeTypeUnmarshaller.java =================================================================== --- src/main/java/org/opensaml/ws/wssecurity/impl/AbstractDateTimeTypeUnmarshaller.java (revision 273) +++ src/main/java/org/opensaml/ws/wssecurity/impl/AbstractDateTimeTypeUnmarshaller.java (working copy) @@ -17,7 +17,15 @@ package org.opensaml.ws.wssecurity.impl; +import java.util.GregorianCalendar; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; + import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.convert.ConverterManager; +import org.joda.time.convert.InstantConverter; import org.opensaml.ws.wssecurity.DateTimeType; import org.opensaml.xml.XMLObject; import org.slf4j.Logger; @@ -52,9 +60,16 @@ log.debug("parse DateTime {}", elementContent); } if (elementContent != null) { - DateTimeType dateTimeObject = (DateTimeType) xmlObject; - DateTime dateTime = AbstractDateTimeType.FORMATTER.parseDateTime(elementContent); - dateTimeObject.setDateTime(dateTime); + try { + DateTimeType dateTimeObject = (DateTimeType) xmlObject; + + GregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(elementContent).toGregorianCalendar(); + InstantConverter converter = ConverterManager.getInstance().getInstantConverter(cal); + + dateTimeObject.setDateTime(new DateTime(converter.getChronology(cal, DateTimeZone.UTC))); + } catch (DatatypeConfigurationException e) { + throw new RuntimeException("Unable to get DatatypeFactory", e); + } } } } Index: src/main/java/org/opensaml/ws/wssecurity/impl/AbstractDateTimeType.java =================================================================== --- src/main/java/org/opensaml/ws/wssecurity/impl/AbstractDateTimeType.java (revision 273) +++ src/main/java/org/opensaml/ws/wssecurity/impl/AbstractDateTimeType.java (working copy) @@ -17,7 +17,15 @@ package org.opensaml.ws.wssecurity.impl; +import java.util.GregorianCalendar; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; + import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.convert.ConverterManager; +import org.joda.time.convert.InstantConverter; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import org.opensaml.ws.wssecurity.DateTimeType; @@ -84,7 +92,15 @@ */ public void setValue(String newValue) { value_ = prepareForAssignment(value_, newValue); - dateTime_ = FORMATTER.parseDateTime(newValue); + + try { + GregorianCalendar cal = DatatypeFactory.newInstance().newXMLGregorianCalendar(newValue).toGregorianCalendar(); + InstantConverter converter = ConverterManager.getInstance().getInstantConverter(cal); + + dateTime_ = new DateTime(converter.getChronology(cal, DateTimeZone.UTC)); + } catch (DatatypeConfigurationException e) { + throw new RuntimeException("Unable to get DatatypeFactory", e); + } } }
- XML DateTime handling in wstrust branch, Joakim Recht, 11/05/2008
- RE: [OpenSAML] XML DateTime handling in wstrust branch, Scott Cantor, 11/05/2008
- Re: [OpenSAML] XML DateTime handling in wstrust branch, Joakim Recht, 11/05/2008
- RE: [OpenSAML] XML DateTime handling in wstrust branch, George Stanchev, 11/05/2008
- Re: [OpenSAML] XML DateTime handling in wstrust branch, Valery Tschopp, 11/12/2008
- RE: [OpenSAML] XML DateTime handling in wstrust branch, George Stanchev, 11/05/2008
- Re: [OpenSAML] XML DateTime handling in wstrust branch, Joakim Recht, 11/05/2008
- RE: [OpenSAML] XML DateTime handling in wstrust branch, Scott Cantor, 11/05/2008
Archive powered by MHonArc 2.6.16.