use of javax.xml.transform.Source in project camel by apache.
the class FallbackTypeConverter method unmarshal.
protected Object unmarshal(Unmarshaller unmarshaller, Exchange exchange, Object value) throws JAXBException, UnsupportedEncodingException, XMLStreamException {
try {
XMLStreamReader xmlReader;
if (value instanceof XMLStreamReader) {
xmlReader = (XMLStreamReader) value;
} else if (value instanceof InputStream) {
if (needFiltering(exchange)) {
xmlReader = staxConverter.createXMLStreamReader(new NonXmlFilterReader(new InputStreamReader((InputStream) value, IOHelper.getCharsetName(exchange))));
} else {
xmlReader = staxConverter.createXMLStreamReader((InputStream) value, exchange);
}
} else if (value instanceof Reader) {
Reader reader = (Reader) value;
if (needFiltering(exchange)) {
if (!(value instanceof NonXmlFilterReader)) {
reader = new NonXmlFilterReader((Reader) value);
}
}
xmlReader = staxConverter.createXMLStreamReader(reader);
} else if (value instanceof Source) {
xmlReader = staxConverter.createXMLStreamReader((Source) value);
} else {
throw new IllegalArgumentException("Cannot convert from " + value.getClass());
}
return unmarshaller.unmarshal(xmlReader);
} finally {
if (value instanceof Closeable) {
IOHelper.close((Closeable) value, "Unmarshalling", LOG);
}
}
}
use of javax.xml.transform.Source in project camel by apache.
the class JingValidator method process.
public void process(Exchange exchange) throws Exception {
Jaxp11XMLReaderCreator xmlCreator = new Jaxp11XMLReaderCreator();
DefaultValidationErrorHandler errorHandler = new DefaultValidationErrorHandler();
PropertyMapBuilder mapBuilder = new PropertyMapBuilder();
mapBuilder.put(ValidateProperty.XML_READER_CREATOR, xmlCreator);
mapBuilder.put(ValidateProperty.ERROR_HANDLER, errorHandler);
PropertyMap propertyMap = mapBuilder.toPropertyMap();
Validator validator = getSchema().createValidator(propertyMap);
Message in = exchange.getIn();
SAXSource saxSource = in.getBody(SAXSource.class);
if (saxSource == null) {
Source source = exchange.getIn().getMandatoryBody(Source.class);
saxSource = ExchangeHelper.convertToMandatoryType(exchange, SAXSource.class, source);
}
InputSource bodyInput = saxSource.getInputSource();
// now lets parse the body using the validator
XMLReader reader = xmlCreator.createXMLReader();
reader.setContentHandler(validator.getContentHandler());
reader.setDTDHandler(validator.getDTDHandler());
reader.setErrorHandler(errorHandler);
reader.parse(bodyInput);
errorHandler.handleErrors(exchange, schema);
}
use of javax.xml.transform.Source in project camel by apache.
the class JmsXMLRouteTest method testLondonWithFileStreamAsObject.
@Test
public void testLondonWithFileStreamAsObject() 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:object", source);
assertMockEndpointsSatisfied();
}
use of javax.xml.transform.Source 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.Source 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();
}
Aggregations