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();
}
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"));
}
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"));
}
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);
}
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);
}
Aggregations