use of javax.xml.transform.stream.StreamSource in project spring-boot by spring-projects.
the class SampleWsApplicationTests method testSendingHolidayRequest.
@Test
public void testSendingHolidayRequest() {
final String request = "<hr:HolidayRequest xmlns:hr=\"http://mycompany.com/hr/schemas\">" + " <hr:Holiday>" + " <hr:StartDate>2013-10-20</hr:StartDate>" + " <hr:EndDate>2013-11-22</hr:EndDate>" + " </hr:Holiday>" + " <hr:Employee>" + " <hr:Number>1</hr:Number>" + " <hr:FirstName>John</hr:FirstName>" + " <hr:LastName>Doe</hr:LastName>" + " </hr:Employee>" + "</hr:HolidayRequest>";
StreamSource source = new StreamSource(new StringReader(request));
StreamResult result = new StreamResult(System.out);
this.webServiceTemplate.sendSourceAndReceiveToResult(source, result);
assertThat(this.output.toString()).contains("Booking holiday for");
}
use of javax.xml.transform.stream.StreamSource in project spring-framework by spring-projects.
the class StaxResultTests method eventWriterSource.
@Test
public void eventWriterSource() throws Exception {
StringWriter stringWriter = new StringWriter();
XMLEventWriter eventWriter = inputFactory.createXMLEventWriter(stringWriter);
Reader reader = new StringReader(XML);
Source source = new StreamSource(reader);
StaxResult result = new StaxResult(eventWriter);
assertEquals("Invalid eventWriter returned", eventWriter, result.getXMLEventWriter());
assertNull("StreamWriter returned", result.getXMLStreamWriter());
transformer.transform(source, result);
assertThat("Invalid result", stringWriter.toString(), isSimilarTo(XML));
}
use of javax.xml.transform.stream.StreamSource in project spring-framework by spring-projects.
the class JibxMarshaller method transformAndMarshal.
private void transformAndMarshal(Object graph, Result result) throws IOException {
try {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
marshalOutputStream(graph, os);
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
Transformer transformer = this.transformerFactory.newTransformer();
transformer.transform(new StreamSource(is), result);
} catch (TransformerException ex) {
throw new MarshallingFailureException("Could not transform to [" + ClassUtils.getShortName(result.getClass()) + "]", ex);
}
}
use of javax.xml.transform.stream.StreamSource in project spring-framework by spring-projects.
the class XStreamUnmarshallerTests method unmarshalStreamSourceInputStream.
@Test
public void unmarshalStreamSourceInputStream() throws Exception {
StreamSource source = new StreamSource(new ByteArrayInputStream(INPUT_STRING.getBytes("UTF-8")));
Object flights = unmarshaller.unmarshal(source);
testFlight(flights);
}
use of javax.xml.transform.stream.StreamSource in project spring-framework by spring-projects.
the class Jaxb2MarshallerTests method unmarshalStreamSourceWithXmlOptions.
// SPR-10806
@Test
public void unmarshalStreamSourceWithXmlOptions() throws Exception {
final javax.xml.bind.Unmarshaller unmarshaller = mock(javax.xml.bind.Unmarshaller.class);
Jaxb2Marshaller marshaller = new Jaxb2Marshaller() {
@Override
protected javax.xml.bind.Unmarshaller createUnmarshaller() {
return unmarshaller;
}
};
// 1. external-general-entities and dtd support disabled (default)
marshaller.unmarshal(new StreamSource("1"));
ArgumentCaptor<SAXSource> sourceCaptor = ArgumentCaptor.forClass(SAXSource.class);
verify(unmarshaller).unmarshal(sourceCaptor.capture());
SAXSource result = sourceCaptor.getValue();
assertEquals(true, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl"));
assertEquals(false, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities"));
// 2. external-general-entities and dtd support enabled
reset(unmarshaller);
marshaller.setProcessExternalEntities(true);
marshaller.setSupportDtd(true);
marshaller.unmarshal(new StreamSource("1"));
verify(unmarshaller).unmarshal(sourceCaptor.capture());
result = sourceCaptor.getValue();
assertEquals(false, result.getXMLReader().getFeature("http://apache.org/xml/features/disallow-doctype-decl"));
assertEquals(true, result.getXMLReader().getFeature("http://xml.org/sax/features/external-general-entities"));
}
Aggregations