0

How can I store soap XML response in database in XML format?

I tried to store soap response in Java object and marshal to XML to store in SQL database. It's working fine, but there is a problem with date which is store after marshalling i.e. date is coming as 2017-10-10-05:00. So this is creating a problem. Can anyone tell me if there is an another approach to store the Soap XML response in XML format in oracle database.

Zissouu
  • 924
  • 2
  • 10
  • 17
Goutham
  • 1
  • 2
  • It is invalid date format for XML. you need to make it correct by transforming it. What does that `05:00` mean? is a time? than it must be like `2017-10-10T05:00:00` You need to convert if to the proper XML date or dateTime format. If you use JAXB you can look at my answer there to get an idea how to do that https://stackoverflow.com/questions/40549526/replacing-date-of-type-xmlgregoriancalendar-generated-by-wsdl-to-java-util-date/40550469#40550469 – Vadim Oct 18 '17 at 22:21
  • From soap respone am getting the date in proper format as 2017-10-10. What am doing is , setting the response to the java object and convert the java object to text(which is in xml format) by using jaxb. When am converting java object to text the date is changed by adding time as 2017-10-10-05:00 which is giving me a wrong date. Is there any other approach to store the soap response as is in database like soaphandlers etc.. – Goutham Oct 19 '17 at 20:33

1 Answers1

0

OK, I was wrong. Format is correct XML and it is a Time Zone. Such Output produces from default javax.xml.bind.DatatypeConverter.printDate(Calendar val) method. (It means your XSD has xs:date type for that element).

So, as long as you do not want to have Time Zone info within Date as String, I guess you have next options:

  1. Create your own converter and define it in binding file (as at link I gave in comments) - be careful to make that converter global. If you do not need to apply it to all xsd:date fields binding will be quite more complex.

  2. If it is about one field, better look at links in the answer there:

JAXB unmarshaller with custom interceptor? It is valid to Marshaller as well.

Jaxb Marshaller has no handlers or callback interceptors. All controls by Annotations in the Java classes or by binding file.

  1. If it is about only one field (simple "brutal" way) - Before storing that XML as String to database remove Time Zone from needed field in your code.

  2. If you do not marshal Pojo to String in your code, but some framework does it for you on the way to Database, check that framework for interceptors where you can manipulate payload. Usually they are there.

Preferred correct options: 1 (if it is for all xsd:date fields) or 2 if it is about one field only.

Vadim
  • 4,027
  • 2
  • 10
  • 26
  • You are right Vadim, my xsd has xs:date of element javax.xml.bind.DatatypeConverter. But this is given by the other system. We are not writing xsd or wsdl, it is given by the other systems. It is not for one field, for all the date fields am getting the same format. Let me check with them regarding this. Thanks for clarifying my doubt Vadim. Thank you. – Goutham Oct 20 '17 at 16:27
  • You are welcome. But I think there is nothing to deal with XSD from other system. Questions are how do you store that XML in database? does database complains about that field? how do other systems use that XML? point is that both formats with or without time zone are valid and any proper parser must understand both. difference is only in this: without time zone server, where parser runs, uses current time zone. you have 2017-10-10-05:00 (it is US Central) but if that field now with time zone will pass to California it will not be 2017-10-10 yet there, but 2017-10-09T22:00:00-07:00. – Vadim Oct 20 '17 at 22:17
  • Yeah it's nothing to do with other system. I am storing the response same as xml format which is displayed in soap ui. I think we achieve this by doing some date conversions. – Goutham Oct 23 '17 at 03:46