2

Please advise how can we generate dynamic wsu:Id in soap request xml.

 <wsu:Timestamp wsu:Id="TS-C68ABF4EC1E628F5B5143638245038886955">
                <wsu:Created>2015-07-08T19:07:30.388Z</wsu:Created>
                <wsu:Expires>2015-07-08T19:12:30.388Z</wsu:Expires>
            </wsu:Timestamp>

Java code :


private Element addTimestamp(Element wsSecurityHeaderElement) throws SOAPException, DatatypeConfigurationException { /if (false == this.addTimestamp) { return null; }/ Document document = wsSecurityHeaderElement.getOwnerDocument(); Element timestampElement = document.createElementNS(WSU_NAMESPACE, "wsu:Timestamp"); timestampElement.setAttributeNS(WSU_NAMESPACE, "wsu:Id", "TS"); // hard coded ts needs to be removed Attr idAttr = timestampElement.getAttributeNodeNS(WSU_NAMESPACE, "Id"); timestampElement.setIdAttributeNode(idAttr, true); Element createdElement = document.createElementNS(WSU_NAMESPACE, "wsu:Created"); DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); GregorianCalendar gregorianCalendar = new GregorianCalendar(); Date now = new Date(); gregorianCalendar.setTime(now); gregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC")); XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory .newXMLGregorianCalendar(gregorianCalendar); createdElement.setTextContent(xmlGregorianCalendar.toXMLFormat()); timestampElement.appendChild(createdElement); Element expiresElement = document.createElementNS(WSU_NAMESPACE, "wsu:Expires"); Date expiresDate = new Date(now.getTime() + 1000 * 60 * 5); gregorianCalendar.setTime(expiresDate); xmlGregorianCalendar = datatypeFactory .newXMLGregorianCalendar(gregorianCalendar); expiresElement.setTextContent(xmlGregorianCalendar.toXMLFormat()); timestampElement.appendChild(expiresElement); wsSecurityHeaderElement.appendChild(timestampElement); return timestampElement; } </code>
user2707491
  • 59
  • 10
  • There are utilities that can generate the client side stubs/classes for you. It's been a while I did this. Have you check something like wsdl.exe? – alltej Mar 21 '17 at 12:06
  • Can you please share useful url to the above requirement? – user2707491 Mar 21 '17 at 16:52
  • Did you add the wsu:Id="TS-C68ABF4EC1E628F5B5143638245038886955" ? and what is the C68ABF4EC1E628F5B5143638245038886955 part ? – user2209350 Apr 24 '20 at 05:56

0 Answers0