Example usage for javax.xml.soap SOAPPart getElementsByTagNameNS

List of usage examples for javax.xml.soap SOAPPart getElementsByTagNameNS

Introduction

In this page you can find the example usage for javax.xml.soap SOAPPart getElementsByTagNameNS.

Prototype

public NodeList getElementsByTagNameNS(String namespaceURI, String localName);

Source Link

Document

Returns a NodeList of all the Elements with a given local name and namespace URI in document order.

Usage

From source file:be.e_contract.mycarenet.xkms.ProofOfPossessionSignatureSOAPHandler.java

@Override
public boolean handleMessage(SOAPMessageContext context) {
    if (null == this.sessionKey) {
        return true;
    }//w ww  .j  a va  2 s  . c  o m
    if (null == this.prototypeKeyBindingId) {
        return true;
    }

    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (false == outboundProperty) {
        return true;
    }
    LOG.debug("adding proof of possession signature");
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    NodeList registerRequestNodeList = soapPart.getElementsByTagNameNS(XKMS_NAMESPACE, "Register");
    Element registerRequestElement = (Element) registerRequestNodeList.item(0);
    Document xkmsDocument;
    try {
        xkmsDocument = copyDocument(registerRequestElement);
    } catch (ParserConfigurationException e) {
        LOG.error("error copying XKMS request: " + e.getMessage(), e);
        return false;
    }

    NodeList proofOfPossessionNodeList = xkmsDocument.getElementsByTagNameNS(XKMS_NAMESPACE,
            "ProofOfPossession");
    Element proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0);
    try {
        prepareDocument(xkmsDocument);
        addSignature(proofOfPossessionElement);
    } catch (Exception e) {
        LOG.error("error adding proof signature: " + e.getMessage(), e);
        return false;
    }
    Node signatureNode = soapPart.importNode(proofOfPossessionElement.getFirstChild(), true);

    proofOfPossessionNodeList = soapPart.getElementsByTagNameNS(XKMS_NAMESPACE, "ProofOfPossession");
    proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0);
    proofOfPossessionElement.appendChild(signatureNode);
    return true;
}

From source file:be.e_contract.mycarenet.xkms2.ProofOfPossessionSignatureSOAPHandler.java

@Override
public boolean handleMessage(SOAPMessageContext context) {
    if (null == this.sessionKey) {
        return true;
    }/* w  w w  .  j  a va  2 s. c  om*/
    if (null == this.prototypeKeyBindingId) {
        return true;
    }

    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (false == outboundProperty) {
        return true;
    }
    LOG.debug("adding proof of possession signature");
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    NodeList registerRequestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE,
            "RegisterRequest");
    Element registerRequestElement = (Element) registerRequestNodeList.item(0);
    Document xkmsDocument;
    try {
        xkmsDocument = copyDocument(registerRequestElement);
    } catch (ParserConfigurationException e) {
        LOG.error("error copying XKMS request: " + e.getMessage(), e);
        return false;
    }

    NodeList proofOfPossessionNodeList = xkmsDocument
            .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "ProofOfPossession");
    Element proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0);
    try {
        prepareDocument(xkmsDocument);
        addSignature(proofOfPossessionElement);
    } catch (Exception e) {
        LOG.error("error adding proof signature: " + e.getMessage(), e);
        return false;
    }
    Node signatureNode = soapPart.importNode(proofOfPossessionElement.getFirstChild(), true);

    proofOfPossessionNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE,
            "ProofOfPossession");
    proofOfPossessionElement = (Element) proofOfPossessionNodeList.item(0);
    proofOfPossessionElement.appendChild(signatureNode);
    return true;
}

From source file:be.e_contract.mycarenet.xkms2.KeyBindingAuthenticationSignatureSOAPHandler.java

@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (false == outboundProperty) {
        return true;
    }//  w  w w.jav  a2 s  .com
    LOG.debug("adding key binding authentication signature");
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String requestElementName;
    if (null != this.prototypeKeyBindingId) {
        requestElementName = "RegisterRequest";
        this.referenceUri = "#" + this.prototypeKeyBindingId;
    } else if (null != this.revokeKeyBindingId) {
        requestElementName = "RevokeRequest";
        this.referenceUri = "#" + this.revokeKeyBindingId;
    } else {
        LOG.error("missing key binding id");
        return false;
    }
    NodeList requestNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE,
            requestElementName);
    Element requestElement = (Element) requestNodeList.item(0);
    if (null == requestElement) {
        LOG.error("request element not present");
        return false;
    }
    Document xkmsDocument;
    try {
        xkmsDocument = copyDocument(requestElement);
    } catch (ParserConfigurationException e) {
        LOG.error("error copying XKMS request: " + e.getMessage(), e);
        return false;
    }

    NodeList keyBindingAuthenticationNodeList = xkmsDocument
            .getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE, "KeyBindingAuthentication");
    Element keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0);
    try {
        prepareDocument(xkmsDocument);
        addSignature(keyBindingAuthenticationElement);
    } catch (Exception e) {
        LOG.error("error adding authn signature: " + e.getMessage(), e);
        return false;
    }

    Node signatureNode = soapPart.importNode(keyBindingAuthenticationElement.getFirstChild(), true);

    keyBindingAuthenticationNodeList = soapPart.getElementsByTagNameNS(XKMS2ServiceFactory.XKMS2_NAMESPACE,
            "KeyBindingAuthentication");
    keyBindingAuthenticationElement = (Element) keyBindingAuthenticationNodeList.item(0);
    keyBindingAuthenticationElement.appendChild(signatureNode);
    return true;
}