Package org.apache.xml.security.stax.impl

Examples of org.apache.xml.security.stax.impl.XMLSecurityEventWriter


    @Test
    public void testConformness() throws Exception {
        XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
        StringWriter secStringWriter = new StringWriter();
        XMLStreamWriter secXmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(secStringWriter);
        XMLSecurityEventWriter xmlSecurityEventWriter = new XMLSecurityEventWriter(secXmlStreamWriter);

        StringWriter stdStringWriter = new StringWriter();
        XMLEventWriter stdXmlEventWriter = xmlOutputFactory.createXMLEventWriter(stdStringWriter);

        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
        XMLStreamReader xmlStreamReader =
            xmlInputFactory.createXMLStreamReader(this.getClass().getClassLoader().getResourceAsStream(
                    "org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));

        while (xmlStreamReader.hasNext()) {
            XMLEvent xmlEvent = XMLSecEventFactory.allocate(xmlStreamReader, null);
            xmlSecurityEventWriter.add(xmlEvent);
            stdXmlEventWriter.add(xmlEvent);
            xmlStreamReader.next();
        }

        xmlSecurityEventWriter.close();
        stdXmlEventWriter.close();
        XMLAssert.assertXMLEqual(stdStringWriter.toString(), secStringWriter.toString());
    }
View Full Code Here


    //@see WSS-437
    @Test
    public void testNamespaces() throws Exception {
        StringWriter stringWriter = new StringWriter();
        XMLStreamWriter xmlStreamWriter = XMLSecurityConstants.xmlOutputFactory.createXMLStreamWriter(stringWriter);
        XMLEventWriter xmlEventWriter = new XMLSecurityEventWriter(xmlStreamWriter);
        xmlEventWriter.add(new XMLSecStartElementImpl(new QName("http://ns1", "a", "ns1"), null, null));
        xmlEventWriter.add(XMLSecNamespaceImpl.getInstance("ns1", "http://ns1"));
        xmlEventWriter.add(new XMLSecStartElementImpl(new QName("http://ns2", "b", ""), null, null));
        xmlEventWriter.add(XMLSecNamespaceImpl.getInstance("", "http://ns2"));
        xmlEventWriter.add(new XMLSecEndElementImpl(new QName("http://ns2", "b", ""), null));
        xmlEventWriter.add(new XMLSecStartElementImpl(new QName("http://ns3", "c", ""), null, null));
        xmlEventWriter.close();

        Assert.assertEquals(
                "<ns1:a xmlns:ns1=\"http://ns1\">" +
                        "<b xmlns=\"http://ns2\"/>" +
                        "<c xmlns=\"http://ns3\">" +
View Full Code Here

                //the trimmer output stream is needed to strip away the dummy wrapping element which must be added
                cipherOutputStream = new TrimmerOutputStream(outputStream, 8192 * 10, 3, 4);

                //we create a new StAX writer for optimized namespace writing.
                //spec says (4.2): "The cleartext octet sequence obtained in step 3 is interpreted as UTF-8 encoded character data."
                xmlEventWriter = new XMLSecurityEventWriter(
                        XMLSecurityConstants.xmlOutputFactoryNonRepairingNs.createXMLStreamWriter(
                                cipherOutputStream, "UTF-8"));
                //we have to output a fake element to workaround text-only encryption:
                xmlEventWriter.add(wrapperStartElement);
            } catch (NoSuchPaddingException e) {
View Full Code Here

                //the trimmer output stream is needed to strip away the dummy wrapping element which must be added
                cipherOutputStream = new TrimmerOutputStream(outputStream, 8192 * 10, 3, 4);

                //we create a new StAX writer for optimized namespace writing.
                //spec says (4.2): "The cleartext octet sequence obtained in step 3 is interpreted as UTF-8 encoded character data."
                xmlEventWriter = new XMLSecurityEventWriter(
                        XMLSecurityConstants.xmlOutputFactoryNonRepairingNs.createXMLStreamWriter(
                                cipherOutputStream, "UTF-8"));
                //we have to output a fake element to workaround text-only encryption:
                xmlEventWriter.add(wrapperStartElement);
            } catch (NoSuchPaddingException e) {
View Full Code Here

    public FinalOutputProcessor(OutputStream outputStream, String encoding) throws XMLSecurityException {
        super();
        setPhase(XMLSecurityConstants.Phase.POSTPROCESSING);
        try {
            xmlEventWriter = new XMLSecurityEventWriter(XMLSecurityConstants.xmlOutputFactory.createXMLStreamWriter(outputStream, encoding));
        } catch (XMLStreamException e) {
            throw new XMLSecurityException(e);
        }
    }
View Full Code Here

    }

    public FinalOutputProcessor(XMLStreamWriter xmlStreamWriter) throws XMLSecurityException {
        super();
        setPhase(XMLSecurityConstants.Phase.POSTPROCESSING);
        this.xmlEventWriter = new XMLSecurityEventWriter(xmlStreamWriter);
    }
View Full Code Here

TOP

Related Classes of org.apache.xml.security.stax.impl.XMLSecurityEventWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.