Search in sources :

Example 1 with TransformService

use of javax.xml.crypto.dsig.TransformService in project jdk8u_jdk by JetBrains.

the class NullParent method main.

public static void main(String[] args) throws Exception {
    String[] transforms = new String[] { Transform.BASE64, Transform.ENVELOPED, Transform.XPATH, Transform.XPATH2, Transform.XSLT, CanonicalizationMethod.EXCLUSIVE, CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, CanonicalizationMethod.INCLUSIVE, CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS };
    for (String transform : transforms) {
        System.out.println("Testing " + transform);
        TransformService ts = TransformService.getInstance(transform, "DOM");
        try {
            ts.init(null, null);
            throw new Exception("init must throw NullPointerException " + "when the parent parameter is null");
        } catch (NullPointerException npe) {
        }
        try {
            ts.marshalParams(null, null);
            throw new Exception("marshalParams must throw " + "NullPointerException when the parent " + "parameter is null");
        } catch (NullPointerException npe) {
        }
    }
}
Also used : TransformService(javax.xml.crypto.dsig.TransformService)

Example 2 with TransformService

use of javax.xml.crypto.dsig.TransformService in project syndesis by syndesisio.

the class BaseSwaggerGeneratorExampleTest method c14Xml.

private static String c14Xml(final String xml) {
    if (xml == null) {
        return null;
    }
    try {
        final DocumentBuilder documentBuilder = DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
        final Document document = documentBuilder.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
        final TransformService transformation = TransformService.getInstance(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, "DOM");
        transformation.init(null);
        final NodeList allElements = document.getElementsByTagName("*");
        final List<Node> elements = new ArrayList<>();
        for (int i = 0; i < allElements.getLength(); i++) {
            elements.add(allElements.item(i));
        }
        final OctetStreamData data = (OctetStreamData) transformation.transform((NodeSetData) elements::iterator, null);
        try (final InputStream stream = data.getOctetStream()) {
            final byte[] buffy = new byte[stream.available()];
            stream.read(buffy);
            return new String(buffy, StandardCharsets.UTF_8);
        }
    } catch (GeneralSecurityException | TransformException | SAXException | IOException | ParserConfigurationException e) {
        throw new AssertionError(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) TransformException(javax.xml.crypto.dsig.TransformException) TransformService(javax.xml.crypto.dsig.TransformService) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) NodeSetData(javax.xml.crypto.NodeSetData) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) OctetStreamData(javax.xml.crypto.OctetStreamData)

Aggregations

TransformService (javax.xml.crypto.dsig.TransformService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 NodeSetData (javax.xml.crypto.NodeSetData)1 OctetStreamData (javax.xml.crypto.OctetStreamData)1 TransformException (javax.xml.crypto.dsig.TransformException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1