Example usage for org.w3c.dom Element getPrefix

List of usage examples for org.w3c.dom Element getPrefix

Introduction

In this page you can find the example usage for org.w3c.dom Element getPrefix.

Prototype

public String getPrefix();

Source Link

Document

The namespace prefix of this node, or null if it is unspecified.

Usage

From source file:test.integ.be.fedict.hsm.ws.WSSecurityTestSOAPHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException,
        DatatypeConfigurationException, CertificateEncodingException, DOMException, NoSuchAlgorithmException,
        InvalidAlgorithmParameterException, MarshalException, XMLSignatureException, NoSuchProviderException {
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    Element soapEnvelopeElement = soapPart.getDocumentElement();
    String soapPrefix = soapEnvelopeElement.getPrefix();
    LOG.debug("SOAP prefix: " + soapPrefix);
    Element soapHeaderElement = soapPart.createElementNS(SOAP_NAMESPACE, soapPrefix + ":Header");
    Element soapBodyElement = (Element) soapEnvelopeElement.getFirstChild();
    soapBodyElement.setAttributeNS(XMLNS_NS, "xmlns:wsu", WSU_NAMESPACE);
    soapBodyElement.setAttributeNS(WSU_NAMESPACE, "wsu:Id", "Body");
    soapEnvelopeElement.insertBefore(soapHeaderElement, soapBodyElement);

    LOG.debug("adding WS-Security SOAP header");
    Element wsSecurityHeaderElement = soapPart.createElementNS(WSSE_NAMESPACE, "wsse:Security");
    soapHeaderElement.appendChild(wsSecurityHeaderElement);
    wsSecurityHeaderElement.setAttributeNS(XMLNS_NS, "xmlns:wsse", WSSE_NAMESPACE);
    wsSecurityHeaderElement.setAttributeNS(XMLNS_NS, "xmlns:wsu", WSU_NAMESPACE);
    wsSecurityHeaderElement.setAttributeNS(SOAP_NAMESPACE, soapPrefix + ":mustUnderstand", "true");

    Element tsElement = addTimestamp(wsSecurityHeaderElement);
    addBinarySecurityToken(wsSecurityHeaderElement);
    addSignature(wsSecurityHeaderElement, tsElement, soapBodyElement);
}