Bug6388460.java revision 779:2b61bfcaa586
1193323Sed/*
2193323Sed * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3193323Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4193323Sed *
5193323Sed * This code is free software; you can redistribute it and/or modify it
6193323Sed * under the terms of the GNU General Public License version 2 only, as
7193323Sed * published by the Free Software Foundation.
8193323Sed *
9193323Sed * This code is distributed in the hope that it will be useful, but WITHOUT
10193323Sed * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11193323Sed * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12193323Sed * version 2 for more details (a copy is included in the LICENSE file that
13193323Sed * accompanied this code).
14193323Sed *
15193323Sed * You should have received a copy of the GNU General Public License version
16193323Sed * 2 along with this work; if not, write to the Free Software Foundation,
17193323Sed * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18239462Sdim *
19239462Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20239462Sdim * or visit www.oracle.com if you need additional information or have any
21251662Sdim * questions.
22249423Sdim */
23218893Sdim
24218893Sdimpackage stream.XMLStreamReaderTest;
25198090Srdivacky
26193323Sedimport java.io.ByteArrayInputStream;
27249423Sdimimport java.io.ByteArrayOutputStream;
28249423Sdim
29249423Sdimimport javax.xml.stream.XMLInputFactory;
30249423Sdimimport javax.xml.stream.XMLStreamReader;
31249423Sdimimport javax.xml.transform.Source;
32249423Sdimimport javax.xml.transform.Transformer;
33249423Sdimimport javax.xml.transform.TransformerFactory;
34249423Sdimimport javax.xml.transform.stream.StreamResult;
35249423Sdimimport javax.xml.transform.stream.StreamSource;
36193323Sed
37212904Sdimimport org.testng.Assert;
38193323Sedimport org.testng.annotations.Test;
39193323Sedimport org.xml.sax.InputSource;
40193323Sed
41239462Sdim/*
42198090Srdivacky * @bug 6388460
43239462Sdim * @summary Test StAX parser can parse UTF-16 wsdl.
44239462Sdim */
45239462Sdimpublic class Bug6388460 {
46239462Sdim
47243830Sdim    @Test
48239462Sdim    public void test() {
49193323Sed        try {
50193323Sed
51193323Sed            Source source = new StreamSource(util.BOMInputStream.createStream("UTF-16BE", this.getClass().getResourceAsStream("Hello.wsdl.data")),
52218893Sdim                        this.getClass().getResource("Hello.wsdl.data").toExternalForm());
53221345Sdim            ByteArrayOutputStream baos = new ByteArrayOutputStream();
54221345Sdim            TransformerFactory factory = TransformerFactory.newInstance();
55218893Sdim            Transformer transformer = factory.newTransformer();
56218893Sdim            transformer.transform(source, new StreamResult(baos));
57218893Sdim            System.out.println(new String(baos.toByteArray()));
58218893Sdim            ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
59218893Sdim            InputSource inSource = new InputSource(bis);
60218893Sdim
61221345Sdim            XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
62221345Sdim            xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
63221345Sdim            XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(inSource.getSystemId(), inSource.getByteStream());
64226633Sdim            while (reader.hasNext()) {
65239462Sdim                reader.next();
66218893Sdim            }
67221345Sdim        } catch (Exception ex) {
68221345Sdim            ex.printStackTrace(System.err);
69221345Sdim            Assert.fail("Exception occured: " + ex.getMessage());
70212904Sdim        }
71239462Sdim    }
72239462Sdim}
73239462Sdim