Java Code Examples for javax.xml.soap.SOAPBody#getElementsByTagNameNS()

The following examples show how to use javax.xml.soap.SOAPBody#getElementsByTagNameNS() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FolderDecryptor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void decryptFolder(SOAPBody soapBody, Crypto crypto) throws TechnicalConnectorException {
   NodeList folderNodes = soapBody.getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedData");
   if (folderNodes.getLength() == 1) {
      Node base64EncryptedDataNode = folderNodes.item(0);
      Node base64EncryptedDataParentNode = base64EncryptedDataNode.getParentNode();

      try {
         NodeList encryptedContent = ((Element)base64EncryptedDataNode).getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedValue");
         if (encryptedContent.getLength() == 0 || encryptedContent.getLength() > 1) {
            LOG.debug("Base64EncryptedValue is not a valid content. Nothing to decrypt.");
            return;
         }

         String encryptedData = encryptedContent.item(0).getTextContent();
         byte[] b64decryptedData = Base64.decode(encryptedData.getBytes());
         byte[] decryptedMessage = crypto.unseal(Crypto.SigningPolicySelector.WITH_NON_REPUDIATION, b64decryptedData).getContentAsByte();
         base64EncryptedDataParentNode.removeChild(base64EncryptedDataNode);
         ConnectorXmlUtils.dump(decryptedMessage);
         NodeList folders = getFolders(decryptedMessage);

         for(int i = 0; i < folders.getLength(); ++i) {
            Element folderElement = (Element)folders.item(i);
            Node folder = base64EncryptedDataParentNode.getOwnerDocument().importNode(folderElement, true);
            base64EncryptedDataParentNode.appendChild(folder);
         }
      } catch (SAXException var13) {
         throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_SAX_EXCEPTION, new Object[]{"SAXException when decrypting the SOAP folder", var13});
      } catch (IOException var14) {
         throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_IOEXCEPTION, new Object[]{"IOException when decrypting the SOAP folder", var14});
      }
   } else if (folderNodes.getLength() == 0) {
      LOG.debug("No node with name Base64EncryptedDatafound to decrypt");
   } else if (folderNodes.getLength() > 1) {
      LOG.debug("More then one node with name Base64EncryptedDatafound to decrypt");
   }

}
 
Example 2
Source File: FolderDecryptor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void decryptFolder(SOAPBody soapBody, Crypto crypto) throws TechnicalConnectorException {
   NodeList folderNodes = soapBody.getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedData");
   if (folderNodes.getLength() == 1) {
      Node base64EncryptedDataNode = folderNodes.item(0);
      Node base64EncryptedDataParentNode = base64EncryptedDataNode.getParentNode();

      try {
         NodeList encryptedContent = ((Element)base64EncryptedDataNode).getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedValue");
         if (encryptedContent.getLength() == 0 || encryptedContent.getLength() > 1) {
            LOG.debug("Base64EncryptedValue is not a valid content. Nothing to decrypt.");
            return;
         }

         String encryptedData = encryptedContent.item(0).getTextContent();
         byte[] b64decryptedData = Base64.decode(encryptedData.getBytes());
         byte[] decryptedMessage = crypto.unseal(Crypto.SigningPolicySelector.WITH_NON_REPUDIATION, b64decryptedData).getContentAsByte();
         base64EncryptedDataParentNode.removeChild(base64EncryptedDataNode);
         ConnectorXmlUtils.dump(decryptedMessage);
         NodeList folders = getFolders(decryptedMessage);

         for(int i = 0; i < folders.getLength(); ++i) {
            Element folderElement = (Element)folders.item(i);
            Node folder = base64EncryptedDataParentNode.getOwnerDocument().importNode(folderElement, true);
            base64EncryptedDataParentNode.appendChild(folder);
         }
      } catch (SAXException var13) {
         throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_SAX_EXCEPTION, new Object[]{"SAXException when decrypting the SOAP folder", var13});
      } catch (IOException var14) {
         throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_IOEXCEPTION, new Object[]{"IOException when decrypting the SOAP folder", var14});
      }
   } else if (folderNodes.getLength() == 0) {
      LOG.debug("No node with name Base64EncryptedDatafound to decrypt");
   } else if (folderNodes.getLength() > 1) {
      LOG.debug("More then one node with name Base64EncryptedDatafound to decrypt");
   }

}
 
Example 3
Source File: FolderDecryptor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void decryptFolder(SOAPBody soapBody, Crypto crypto) throws TechnicalConnectorException {
   NodeList folderNodes = soapBody.getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedData");
   if (folderNodes.getLength() == 1) {
      Node base64EncryptedDataNode = folderNodes.item(0);
      Node base64EncryptedDataParentNode = base64EncryptedDataNode.getParentNode();

      try {
         NodeList encryptedContent = ((Element)base64EncryptedDataNode).getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedValue");
         if (encryptedContent.getLength() == 0 || encryptedContent.getLength() > 1) {
            LOG.debug("Base64EncryptedValue is not a valid content. Nothing to decrypt.");
            return;
         }

         String encryptedData = encryptedContent.item(0).getTextContent();
         byte[] b64decryptedData = Base64.decode(encryptedData.getBytes());
         byte[] decryptedMessage = crypto.unseal(Crypto.SigningPolicySelector.WITH_NON_REPUDIATION, b64decryptedData).getContentAsByte();
         base64EncryptedDataParentNode.removeChild(base64EncryptedDataNode);
         ConnectorXmlUtils.dump(decryptedMessage);
         NodeList folders = getFolders(decryptedMessage);

         for(int i = 0; i < folders.getLength(); ++i) {
            Element folderElement = (Element)folders.item(i);
            Node folder = base64EncryptedDataParentNode.getOwnerDocument().importNode(folderElement, true);
            base64EncryptedDataParentNode.appendChild(folder);
         }
      } catch (SAXException var13) {
         throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_SAX_EXCEPTION, new Object[]{"SAXException when decrypting the SOAP folder", var13});
      } catch (IOException var14) {
         throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_IOEXCEPTION, new Object[]{"IOException when decrypting the SOAP folder", var14});
      }
   } else if (folderNodes.getLength() == 0) {
      LOG.debug("No node with name Base64EncryptedDatafound to decrypt");
   } else if (folderNodes.getLength() > 1) {
      LOG.debug("More then one node with name Base64EncryptedDatafound to decrypt");
   }

}
 
Example 4
Source File: FolderDecryptor.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void decryptFolder(SOAPBody soapBody, Crypto crypto) throws TechnicalConnectorException {
   Node base64EncryptedDataNode = null;
   Node base64EncryptedDataParentNode = null;
   NodeList folderNodes = soapBody.getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedData");
   if (folderNodes.getLength() == 1) {
      base64EncryptedDataNode = folderNodes.item(0);
      base64EncryptedDataParentNode = base64EncryptedDataNode.getParentNode();

      try {
         NodeList encryptedContent = ((Element)base64EncryptedDataNode).getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedValue");
         if (encryptedContent.getLength() == 0 || encryptedContent.getLength() > 1) {
            LOG.debug("Base64EncryptedValue is not a valid content. Nothing to decrypt.");
            return;
         }

         String encryptedData = encryptedContent.item(0).getTextContent();
         byte[] b64decryptedData = Base64.decode(encryptedData.getBytes());
         byte[] decryptedMessage = crypto.unseal(Crypto.SigningPolicySelector.WITH_NON_REPUDIATION, b64decryptedData).getContentAsByte();
         base64EncryptedDataParentNode.removeChild(base64EncryptedDataNode);
         NodeList folders = getFolders(decryptedMessage);

         for(int i = 0; i < folders.getLength(); ++i) {
            Element folderElement = (Element)folders.item(i);
            Node folder = base64EncryptedDataParentNode.getOwnerDocument().importNode(folderElement, true);
            base64EncryptedDataParentNode.appendChild(folder);
         }
      } catch (SAXException var13) {
         LOG.error("SAXException when decrypting the SOAP folder", var13);
      } catch (IOException var14) {
         LOG.error("IOException when decrypting the SOAP folder", var14);
      }
   } else if (folderNodes.getLength() == 0) {
      LOG.debug("No node with name Base64EncryptedDatafound to decrypt");
   } else if (folderNodes.getLength() > 1) {
      LOG.debug("More then one node with name Base64EncryptedDatafound to decrypt");
   }

}
 
Example 5
Source File: FolderDecryptor.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void decryptFolder(SOAPBody soapBody, Crypto crypto) throws TechnicalConnectorException {
   NodeList folderNodes = soapBody.getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedData");
   if (folderNodes.getLength() == 1) {
      Node base64EncryptedDataNode = folderNodes.item(0);
      Node base64EncryptedDataParentNode = base64EncryptedDataNode.getParentNode();

      try {
         NodeList encryptedContent = ((Element)base64EncryptedDataNode).getElementsByTagNameNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "Base64EncryptedValue");
         if (encryptedContent.getLength() == 0 || encryptedContent.getLength() > 1) {
            LOG.debug("Base64EncryptedValue is not a valid content. Nothing to decrypt.");
            return;
         }

         String encryptedData = encryptedContent.item(0).getTextContent();
         byte[] b64decryptedData = Base64.decode(encryptedData.getBytes());
         byte[] decryptedMessage = crypto.unseal(Crypto.SigningPolicySelector.WITH_NON_REPUDIATION, b64decryptedData).getContentAsByte();
         base64EncryptedDataParentNode.removeChild(base64EncryptedDataNode);
         ConnectorXmlUtils.dump(decryptedMessage);
         NodeList folders = getFolders(decryptedMessage);

         IntStream.range(0, folders.getLength()).mapToObj(folders::item).forEach((Node e) -> {
            Element folderElement = (Element) e;
            Element folder = base64EncryptedDataParentNode.getOwnerDocument().createElementNS("http://www.ehealth.fgov.be/standards/kmehr/schema/v1", "folder");
            NodeList folderChildren = folderElement.getChildNodes();
            IntStream.range(0, folderChildren.getLength()).mapToObj(folderChildren::item).forEach((Node fn) -> {
               folder.appendChild(base64EncryptedDataParentNode.getOwnerDocument().importNode(fn, true));
            });
            NamedNodeMap m = folderElement.getAttributes();
            for (int ii = 0; ii < m.getLength(); ii++) {
               Node attr = m.item(ii);
               folder.setAttribute(attr.getNodeName(), attr.getNodeValue());
            }
            base64EncryptedDataParentNode.appendChild(folder);
         });
      } catch (SAXException var13) {
         throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_SAX_EXCEPTION, "SAXException when decrypting the SOAP folder", var13);
      } catch (IOException var14) {
         throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_IOEXCEPTION, "IOException when decrypting the SOAP folder", var14);
      }
   } else if (folderNodes.getLength() == 0) {
      LOG.debug("No node with name Base64EncryptedDatafound to decrypt");
   } else if (folderNodes.getLength() > 1) {
      LOG.debug("More then one node with name Base64EncryptedDatafound to decrypt");
   }

}