со следующим кодом:
public boolean handleMessage(SOAPMessageContext context) { boolean res = false; try { Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (outboundProperty.booleanValue()) { SOAPMessage message = context.getMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPFactory factory = SOAPFactory.newInstance(); String prefix = "wsu"; String uri = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"; SOAPElement timestamp = factory.createElement("Timestamp", prefix, uri); SOAPElement created = factory.createElement("Created", prefix, uri); created.addTextNode(getTimestamp()); timestamp.addChildElement(created); SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); } header.addChildElement(timestamp); message.saveChanges(); res = true; } } catch (Exception e) { //do something } return res; }
Можно создать элемент «Создан» с префиксом , но не с uri ??
Это очень многословно для меня:
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2019-03-11T13:15:17.661+01:00</wsu:Created> </wsu:Timestamp>
Я бы хотел иметь это вместо:
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsu:Created>2019-03-11T13:15:17.661+01:00</wsu:Created> </wsu:Timestamp>
Ни одна из следующих работ не работает:
SOAPElement created = factory.createElement("Created", prefix, null); SOAPElement created = factory.createElement("Created", prefix, "");
Спасибо!