use of org.xml.sax.InputSource in project camel by apache.
the class JibxDataFormatMarshallTest 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:start", 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 JibxDataFormatMarshallWithBindingNameTest 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:start", 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 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 groovy by apache.
the class XmlParser method parse.
/**
* Parses the content of the given file as XML turning it into a tree
* of Nodes.
*
* @param file the File containing the XML to be parsed
* @return the root node of the parsed tree of Nodes
* @throws SAXException Any SAX exception, possibly
* wrapping another exception.
* @throws IOException An IO exception from the parser,
* possibly from a byte stream or character stream
* supplied by the application.
*/
public Node parse(File file) throws IOException, SAXException {
InputSource input = new InputSource(new FileInputStream(file));
input.setSystemId("file://" + file.getAbsolutePath());
getXMLReader().parse(input);
return parent;
}
Aggregations