I am sending the XML String with the time-stamp format "YYYY-MM-DDTH:M:S" but ideally the date time data type of the XSD expects the format to be "YYYY-MM-DDTHH:MM:SS" hence the processing is failing with an error message "Time-stamp is missing or invalid in XML file"
Due to this incorrect time-stamp format the timestmap is being set as null during unmarshaling the xml to the Product Object. So, the XML needs to be pre-processed with the correct timestmap when ever a wrong format is encountered. Could you suggest on the best approach to customize/update the timestamp value with the expected format and send the updated xml back? Example If this time-stamp encountered is "2016-10-13T2:18:41" it has to be changed to "2016-10-13T02:18:41" this applies to hours, minutes and seconds . Here is the piece of code for your reference and the xml string value to be passed(for example:)
public Product parseXML(String xml) throws SASException {
//String xml = "<product><timestamp>2015-10-30T1:41:22.109-04:00</timestamp></product>";
Product product = null;
try {
XMLReader xmlReader = null;
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setFeature(ProductConstants.FEATURE_EXTERNAL_GENERAL_ENTITY, false);
factory.setFeature(ProductConstants.FEATURE_DISALLOW_DOCTYPE_DECLARE, false);
xmlReader = factory.newSAXParser().getXMLReader();
InputSource inSrc = new InputSource(new StringReader(xml));
SAXSource saxSource = new SAXSource(xmlReader, inSrc);
JAXBContext context = JAXBContext.newInstance(Product.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
product = (Product) unmarshaller.unmarshal(saxSource);
} catch (ParserConfigurationException | SAXException | JAXBException exception) {
LOG.error(ProductConstants.ERROR_CODE_XML_UNMARSHALLING_FAILED, exception);
throw new SASException(ProductConstants.ERROR_CODE_XML_UNMARSHALLING_FAILED, exception);
}
LOG.info("Completed product parsing xml: product" + product);
return product;
}