use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class JmsXMLRouteTest method testLondonWithFileStreamAsDefault.
@Test
public void testLondonWithFileStreamAsDefault() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:london");
mock.expectedMessageCount(1);
mock.message(0).body(String.class).contains("James");
Source source = new StreamSource(new FileInputStream(TEST_LONDON));
assertNotNull(source);
template.sendBody("direct:default", source);
assertMockEndpointsSatisfied();
}
use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class JmsXMLRouteTest method testTampaWithFileStreamAsDefault.
@Test
public void testTampaWithFileStreamAsDefault() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tampa");
mock.expectedMessageCount(1);
mock.message(0).body(String.class).contains("Hiram");
Source source = new StreamSource(new FileInputStream(TEST_TAMPA));
assertNotNull(source);
template.sendBody("direct:default", source);
assertMockEndpointsSatisfied();
}
use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class JmsXMLRouteTest method testTampaWithFileStreamAsObject.
@Test
public void testTampaWithFileStreamAsObject() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:tampa");
mock.expectedMessageCount(1);
mock.message(0).body(String.class).contains("Hiram");
Source source = new StreamSource(new FileInputStream(TEST_TAMPA));
assertNotNull(source);
template.sendBody("direct:object", source);
assertMockEndpointsSatisfied();
}
use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class XmlFixture method transform.
protected static Document transform(Document aDocument, String aResourcePath) throws Exception {
TransformerFactory tf = TransformerFactory.newInstance();
InputStream in = XmlFixture.class.getResourceAsStream(aResourcePath);
Source src = new StreamSource(in);
src.setSystemId(XmlFixture.class.getResource(aResourcePath).toExternalForm());
Transformer t = tf.newTransformer(src);
DOMResult result = new DOMResult();
t.transform(new DOMSource(aDocument), result);
return (Document) result.getNode();
}
use of javax.xml.transform.stream.StreamSource in project tomcat by apache.
the class DefaultServlet method findXsltSource.
/**
* Return a Source for the xsl template (if possible).
* @param directory The directory to search
* @return the source for the specified directory
* @throws IOException an IO error occurred
*/
protected Source findXsltSource(WebResource directory) throws IOException {
if (localXsltFile != null) {
WebResource resource = resources.getResource(directory.getWebappPath() + localXsltFile);
if (resource.isFile()) {
InputStream is = resource.getInputStream();
if (is != null) {
if (Globals.IS_SECURITY_ENABLED) {
return secureXslt(is);
} else {
return new StreamSource(is);
}
}
}
if (debug > 10) {
log("localXsltFile '" + localXsltFile + "' not found");
}
}
if (contextXsltFile != null) {
InputStream is = getServletContext().getResourceAsStream(contextXsltFile);
if (is != null) {
if (Globals.IS_SECURITY_ENABLED) {
return secureXslt(is);
} else {
return new StreamSource(is);
}
}
if (debug > 10)
log("contextXsltFile '" + contextXsltFile + "' not found");
}
/* Open and read in file in one fell swoop to reduce chance
* chance of leaving handle open.
*/
if (globalXsltFile != null) {
File f = validateGlobalXsltFile();
if (f != null) {
try (FileInputStream fis = new FileInputStream(f)) {
byte[] b = new byte[(int) f.length()];
/* danger! */
fis.read(b);
return new StreamSource(new ByteArrayInputStream(b));
}
}
}
return null;
}
Aggregations