Search in sources :

Example 26 with StAXSource

use of javax.xml.transform.stax.StAXSource in project teiid by teiid.

the class TestWSTranslatorMetadata method testMetadata.

@Test
public void testMetadata() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    Properties props = new Properties();
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    Mockito.stub(mockConnection.getWsdl()).toReturn(new File(UnitTestUtil.getTestDataPath() + "/xquotes.wsdl").toURI().toURL());
    Mockito.stub(mockConnection.getServiceQName()).toReturn(new QName("http://www.xignite.com/services/", "XigniteQuotes"));
    Mockito.stub(mockConnection.getPortQName()).toReturn(new QName("http://www.xignite.com/services/", "XigniteQuotesSoap"));
    MetadataFactory mf = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    ef.getMetadata(mf, mockConnection);
    assertEquals(36, mf.getSchema().getProcedures().size());
    TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    Dispatch<Object> mockDispatch = Mockito.mock(Dispatch.class);
    StAXSource source = Mockito.mock(StAXSource.class);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(source);
    Mockito.stub(mockConnection.createDispatch(Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
    CommandBuilder cb = new CommandBuilder(tm);
    Call call = (Call) cb.getCommand("call GetFundQuote('<foo/>')");
    WSWSDLProcedureExecution wpe = new WSWSDLProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    wpe.execute();
    wpe.getOutputParameterValues();
}
Also used : WSConnection(org.teiid.translator.WSConnection) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) QName(javax.xml.namespace.QName) StAXSource(javax.xml.transform.stax.StAXSource) Properties(java.util.Properties) DataSource(javax.activation.DataSource) ExecutionContext(org.teiid.translator.ExecutionContext) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) CommandBuilder(org.teiid.cdk.CommandBuilder) File(java.io.File) Test(org.junit.Test)

Example 27 with StAXSource

use of javax.xml.transform.stax.StAXSource in project teiid by teiid.

the class TestXMLInputStream method testUTF16Streaming.

@Test
public void testUTF16Streaming() throws Exception {
    StringBuilder xmlBuilder = new StringBuilder();
    xmlBuilder.append("<?xml version=\"1.0\"?><root>");
    for (int i = 0; i < 1000; i++) {
        xmlBuilder.append("<a></a>");
        xmlBuilder.append("<b></b>");
    }
    xmlBuilder.append("</root>");
    String xml = xmlBuilder.toString();
    StAXSource source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader(xml)));
    XMLInputStream is = new XMLInputStream(source, XMLOutputFactory.newFactory(), "UTF-16");
    byte[] bytes = ObjectConverterUtil.convertToByteArray(is);
    assertEquals(xml, new String(bytes, "UTF-16"));
}
Also used : StringReader(java.io.StringReader) StAXSource(javax.xml.transform.stax.StAXSource) Test(org.junit.Test)

Example 28 with StAXSource

use of javax.xml.transform.stax.StAXSource in project teiid by teiid.

the class TestXMLInputStream method testStreaming.

@Test
public void testStreaming() throws Exception {
    StringBuilder xmlBuilder = new StringBuilder();
    xmlBuilder.append("<?xml version=\"1.0\"?><root>");
    for (int i = 0; i < 1000; i++) {
        xmlBuilder.append("<a></a>");
        xmlBuilder.append("<b></b>");
    }
    xmlBuilder.append("</root>");
    String xml = xmlBuilder.toString();
    StAXSource source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader(xml)));
    XMLInputStream is = new XMLInputStream(source, XMLOutputFactory.newFactory());
    byte[] bytes = ObjectConverterUtil.convertToByteArray(is);
    assertEquals(xml, new String(bytes, "UTF-8"));
}
Also used : StringReader(java.io.StringReader) StAXSource(javax.xml.transform.stax.StAXSource) Test(org.junit.Test)

Example 29 with StAXSource

use of javax.xml.transform.stax.StAXSource in project teiid by teiid.

the class TestXMLReader method testStreaming.

@Test
public void testStreaming() throws Exception {
    StringBuilder xmlBuilder = new StringBuilder();
    xmlBuilder.append("<?xml version=\"1.0\"?><root>");
    for (int i = 0; i < 1000; i++) {
        xmlBuilder.append("<a></a>");
        xmlBuilder.append("<b></b>");
    }
    xmlBuilder.append("</root>");
    String xml = xmlBuilder.toString();
    StAXSource source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader(xml)));
    XMLReader is = new XMLReader(source, XMLOutputFactory.newFactory());
    String str = ObjectConverterUtil.convertToString(is);
    assertEquals(xml, str);
}
Also used : StringReader(java.io.StringReader) StAXSource(javax.xml.transform.stax.StAXSource) Test(org.junit.Test)

Example 30 with StAXSource

use of javax.xml.transform.stax.StAXSource in project sqlite-jna by gwenn.

the class SQLXMLFromRows method getSource.

@Override
public <T extends Source> T getSource(Class<T> sourceClass) throws SQLException {
    checkAndSwitchReadable();
    if (sourceClass == null || DOMSource.class.equals(sourceClass)) {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            // TODO builder.setErrorHandler();
            InputSource input = new InputSource(getReader());
            return (T) new DOMSource(builder.parse(input));
        } catch (ParserConfigurationException | SAXException | IOException e) {
            throw new SQLiteException(null, "Unable to decode xml data.", ErrCodes.WRAPPER_SPECIFIC, e);
        }
    } else if (SAXSource.class.equals(sourceClass)) {
        InputSource is = new InputSource(getReader());
        return (T) new SAXSource(is);
    } else if (StreamSource.class.equals(sourceClass)) {
        return (T) new StreamSource(getReader());
    } else if (StAXSource.class.equals(sourceClass)) {
        XMLInputFactory xif = XMLInputFactory.newInstance();
        try {
            XMLStreamReader xsr = xif.createXMLStreamReader(getReader());
            return (T) new StAXSource(xsr);
        } catch (XMLStreamException e) {
            throw new SQLiteException(null, "Unable to decode xml data.", ErrCodes.WRAPPER_SPECIFIC, e);
        }
    }
    throw new SQLiteException("Unknown XML Source class: " + sourceClass, ErrCodes.WRAPPER_SPECIFIC);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) StreamSource(javax.xml.transform.stream.StreamSource) IOException(java.io.IOException) StAXSource(javax.xml.transform.stax.StAXSource) SQLiteException(org.sqlite.SQLiteException) SAXException(org.xml.sax.SAXException) SAXSource(javax.xml.transform.sax.SAXSource) XMLStreamException(javax.xml.stream.XMLStreamException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

StAXSource (javax.xml.transform.stax.StAXSource)66 XMLStreamReader (javax.xml.stream.XMLStreamReader)27 XMLStreamException (javax.xml.stream.XMLStreamException)24 StringReader (java.io.StringReader)19 XMLInputFactory (javax.xml.stream.XMLInputFactory)19 XMLEventReader (javax.xml.stream.XMLEventReader)16 StreamSource (javax.xml.transform.stream.StreamSource)15 DOMSource (javax.xml.transform.dom.DOMSource)14 Source (javax.xml.transform.Source)13 SAXSource (javax.xml.transform.sax.SAXSource)12 Test (org.junit.Test)12 StreamResult (javax.xml.transform.stream.StreamResult)10 InputStream (java.io.InputStream)9 TransformerException (javax.xml.transform.TransformerException)8 IOException (java.io.IOException)7 Transformer (javax.xml.transform.Transformer)7 Test (org.junit.jupiter.api.Test)7 Document (org.w3c.dom.Document)7 InputSource (org.xml.sax.InputSource)7 StringWriter (java.io.StringWriter)6