use of javax.xml.transform.stream.StreamResult in project camel by apache.
the class ConsumerEndpointMappingResponseHandlingRouteTest method testAction.
@Test
public void testAction() throws Exception {
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
webServiceTemplate.sendSourceAndReceiveToResult(getDefaultRequestSource(), new ActionCallback("http://www.webserviceX.NET/GetQuote"), result);
assertNotNull(result);
TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString());
}
use of javax.xml.transform.stream.StreamResult in project camel by apache.
the class AbstractWSATests method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
// initialize beans for catching results
webServiceTemplate = applicationContext.getBean("webServiceTemplate", WebServiceTemplate.class);
newReply = getMandatoryBean(OutputChannelReceiver.class, "replyReceiver");
response = getMandatoryBean(OutputChannelReceiver.class, "responseReceiver");
// sample data
source = new StreamSource(new StringReader(xmlBody));
result = new StreamResult(new StringWriter());
// reset from previous test
response.clear();
newReply.clear();
requestInputAction = null;
}
use of javax.xml.transform.stream.StreamResult in project liquibase by liquibase.
the class DefaultXmlWriter method write.
@Override
public void write(Document doc, OutputStream outputStream) throws IOException {
try {
TransformerFactory factory = TransformerFactory.newInstance();
try {
factory.setAttribute("indent-number", 4);
} catch (Exception e) {
//guess we can't set it, that's ok
;
}
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
//need to nest outputStreamWriter to get around JDK 5 bug. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6296446
OutputStreamWriter writer = new OutputStreamWriter(outputStream, LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
transformer.transform(new DOMSource(doc), new StreamResult(writer));
writer.flush();
writer.close();
} catch (TransformerException e) {
throw new IOException(e.getMessage());
}
}
use of javax.xml.transform.stream.StreamResult in project CoreNLP by stanfordnlp.
the class Ssurgeon method writeToString.
public static String writeToString(SsurgeonPattern pattern) {
try {
List<SsurgeonPattern> patterns = new LinkedList<>();
patterns.add(pattern);
Document domDoc = createPatternXMLDoc(patterns);
if (domDoc != null) {
Transformer tformer = TransformerFactory.newInstance().newTransformer();
tformer.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter sw = new StringWriter();
tformer.transform(new DOMSource(domDoc), new StreamResult(sw));
return sw.toString();
} else {
log.warning("Was not able to create XML document for pattern list.");
}
} catch (Exception e) {
log.info("Error in writeToString, could not process pattern=" + pattern);
log.info(e);
return null;
}
return "";
}
use of javax.xml.transform.stream.StreamResult in project bazel by bazelbuild.
the class XmlOutputFormatter method createPostFactoStreamCallback.
@Override
public OutputFormatterCallback<Target> createPostFactoStreamCallback(final OutputStream out, final QueryOptions options) {
return new OutputFormatterCallback<Target>() {
private Document doc;
private Element queryElem;
@Override
public void start() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
doc = factory.newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
// This shouldn't be possible: all the configuration is hard-coded.
throw new IllegalStateException("XML output failed", e);
}
doc.setXmlVersion("1.1");
queryElem = doc.createElement("query");
queryElem.setAttribute("version", "2");
doc.appendChild(queryElem);
}
@Override
public void processOutput(Iterable<Target> partialResult) throws IOException, InterruptedException {
for (Target target : partialResult) {
queryElem.appendChild(createTargetElement(doc, target));
}
}
@Override
public void close(boolean failFast) throws IOException {
if (!failFast) {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(new DOMSource(doc), new StreamResult(out));
} catch (TransformerFactoryConfigurationError | TransformerException e) {
// This shouldn't be possible: all the configuration is hard-coded.
throw new IllegalStateException("XML output failed", e);
}
}
}
};
}
Aggregations