删除URI,但不删除请求中SOAP元素的前缀

时间:2019-03-11 12:26:11

标签: java web-services soap jax-ws

具有下一个代码:

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;
}

可以使用前缀创建元素“ Created”,但不能使用 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, "");

谢谢!

0 个答案:

没有答案