use of org.xml.sax.InputSource in project camel by apache.
the class JibxDataFormatSpringDslTest method testMarshall.
@Test
public void testMarshall() throws InterruptedException, ParserConfigurationException, IOException, SAXException {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
PurchaseOrder purchaseOrder = new PurchaseOrder();
String name = "foo";
purchaseOrder.setName(name);
double price = 49;
purchaseOrder.setPrice(price);
double amount = 3;
purchaseOrder.setAmount(amount);
template.sendBody("direct:marshall", purchaseOrder);
assertMockEndpointsSatisfied();
String body = mock.getReceivedExchanges().get(0).getIn().getBody(String.class);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Element root = builder.parse(new InputSource(new StringReader(body))).getDocumentElement();
assertEquals(name, root.getAttribute("name"));
assertEquals(price + "", root.getAttribute("price"));
assertEquals(amount + "", root.getAttribute("amount"));
}
use of org.xml.sax.InputSource 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 org.xml.sax.InputSource in project camel by apache.
the class XsltBuilderTest method testXsltTemplates.
public void testXsltTemplates() throws Exception {
File file = new File("src/test/resources/org/apache/camel/builder/xml/example.xsl");
Source source = new SAXSource(new InputSource(new FileInputStream(file)));
XmlConverter converter = new XmlConverter();
Templates styleSheet = converter.getTransformerFactory().newTemplates(source);
XsltBuilder builder = XsltBuilder.xslt(styleSheet);
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("<hello>world!</hello>");
builder.process(exchange);
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>", exchange.getOut().getBody());
}
use of org.xml.sax.InputSource in project camel by apache.
the class XPathTest method testXPathWithDocumentTypeInputSourceNoResultQName.
public void testXPathWithDocumentTypeInputSourceNoResultQName() throws Exception {
InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>bar</foo>");
InputSource doc = new InputSource(is);
XPathBuilder builder = xpath("/foo");
builder.setDocumentType(InputSource.class);
builder.setResultQName(null);
Object result = builder.evaluate(createExchange(doc));
assertNotNull(result);
String s = context.getTypeConverter().convertTo(String.class, result);
assertEquals("bar", s);
}
use of org.xml.sax.InputSource in project camel by apache.
the class StreamCacheConverterTest method testConvertToStreamCache.
public void testConvertToStreamCache() throws Exception {
context.start();
ByteArrayInputStream inputStream = new ByteArrayInputStream(MESSAGE.getBytes());
StreamCache streamCache = StreamCacheConverter.convertToStreamCache(new SAXSource(new InputSource(inputStream)), exchange);
String message = exchange.getContext().getTypeConverter().convertTo(String.class, streamCache);
assertNotNull(message);
assertEquals("The converted message is wrong", MESSAGE, message);
}
Aggregations