Package javax.xml.stream

Examples of javax.xml.stream.XMLEventWriter


        part.setElementQName(elName);
       
        StringWriter stringWriter = new StringWriter();
        XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
        opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
        XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
        Marshaller m = context.createMarshaller();
        JAXBUtils.setNamespaceWrapper(mapper, m);
        JAXBEncoderDecoder.marshall(m, testObject, part, writer);
        writer.flush();
        writer.close();
        String xmlResult = stringWriter.toString();
        // the following is a bit of a crock, but, to tell the truth, this test case most exists
        // so that it could be examined inside the debugger to see how JAXB works.
        assertTrue(xmlResult.contains("Gallia:string2"));
    }
View Full Code Here


        part.setElementQName(elName);
               
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
        opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
        XMLEventWriter writer = opFactory.createXMLEventWriter(baos);

        //STARTDOCUMENT/ENDDOCUMENT is not required
        //writer.add(eFactory.createStartDocument("utf-8", "1.0"));       
        JAXBEncoderDecoder.marshall(context.createMarshaller(), obj, part, writer);
        //writer.add(eFactory.createEndDocument());
        writer.flush();
        writer.close();
       
        //System.out.println(baos.toString());
       
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        XMLInputFactory ipFactory = XMLInputFactory.newInstance();
View Full Code Here

        obj.setRequestType("Hello");
       
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
        opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
        XMLEventWriter writer = opFactory.createXMLEventWriter(baos);

        //STARTDOCUMENT/ENDDOCUMENT is not required
        //writer.add(eFactory.createStartDocument("utf-8", "1.0"));       
        JAXBEncoderDecoder.marshall(context.createMarshaller(), obj, null, writer);
        //writer.add(eFactory.createEndDocument());
        writer.flush();
        writer.close();
       
        //System.out.println(baos.toString());
       
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        XMLInputFactory ipFactory = XMLInputFactory.newInstance();
View Full Code Here

    private static final String TEST_XML_WITH_XML_HEADER = "<?xml version=\"1.0\"?>" + TEST_XML;

    public void testEncodingXmlEventReader() throws Exception {
        TEST_XML_WITH_XML_HEADER_ISO_8859_1_AS_BYTE_ARRAY_STREAM.reset();
        XMLEventReader reader = null;
        XMLEventWriter writer = null;
        ByteArrayOutputStream output = null;
        try {
            // enter text encoded with Latin1
            reader = context.getTypeConverter().mandatoryConvertTo(XMLEventReader.class,
                    TEST_XML_WITH_XML_HEADER_ISO_8859_1_AS_BYTE_ARRAY_STREAM);

            output = new ByteArrayOutputStream();
            // ensure UTF-8 encoding
            Exchange exchange = new DefaultExchange(context);
            exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.name());
            writer = context.getTypeConverter().mandatoryConvertTo(XMLEventWriter.class, exchange, output);
            while (reader.hasNext()) {
                writer.add(reader.nextEvent());
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (writer != null) {
                writer.close();
            }
        }
        assertNotNull(output);

        String result = new String(output.toByteArray(), UTF_8.name());
View Full Code Here

        XMLEventReader eventReader = inputFactory.createXMLEventReader(payload.getInputStream());
        Source staxSource = StaxUtils.createCustomStaxSource(eventReader);
        transformer.transform(staxSource, webServiceMessage.getPayloadResult());
        StringWriter stringWriter = new StringWriter();
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(stringWriter);
        Result staxResult = StaxUtils.createCustomStaxResult(eventWriter);
        transformer.transform(webServiceMessage.getPayloadSource(), staxResult);
        eventWriter.flush();
        assertXMLEqual(getExpectedString(), stringWriter.toString());
        validateMessage();
    }
View Full Code Here

            if (streamWriter != null) {
                callback.staxResult(streamWriter);
                return;
            }
            else {
                XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(result);
                if (eventWriter != null) {
                    callback.staxResult(eventWriter);
                    return;
                }
            }
View Full Code Here

        try {
            DocumentBuilder documentBuilder = messageFactory.getDocumentBuilderFactory().newDocumentBuilder();
            try {
                Document result = documentBuilder.newDocument();
                DOMResult domResult = new DOMResult(result);
                XMLEventWriter eventWriter = messageFactory.getOutputFactory().createXMLEventWriter(domResult);
                eventWriter.add(startDocument);
                envelope.writeTo(new NoStartEndDocumentWriter(eventWriter));
                eventWriter.add(endDocument);
                eventWriter.flush();
                return result;
            }
            catch (XMLStreamException ignored) {
                // ignored
            }
View Full Code Here

                    tos.addHeader(name, value);
                }
            }
        }
        try {
            XMLEventWriter eventWriter = messageFactory.getOutputFactory().createXMLEventWriter(outputStream);
            eventWriter.add(startDocument);
            envelope.writeTo(new NoStartEndDocumentWriter(eventWriter));
            eventWriter.add(endDocument);
            eventWriter.flush();
        }
        catch (XMLStreamException ex) {
            throw new StroapMessageException("Could not write message to OutputStream: " + ex.getMessage(), ex);
        }
    }
View Full Code Here

    }

    @Test
    public void testDoWithStaxResultEventWriter() throws Exception {
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new StringWriter());

        TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
        mock.staxResult(eventWriter);

        replay(mock);
View Full Code Here

        }
        else {
            cachingPayload = new CachingStroapPayload();
            this.payload = cachingPayload;
        }
        XMLEventWriter eventWriter = cachingPayload.getEventWriter();
        return StaxUtils.createCustomStaxResult(eventWriter);
    }
View Full Code Here

TOP

Related Classes of javax.xml.stream.XMLEventWriter

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.