/** * Constructor to build a Schema instance around a given nodeName * * @param schemaFileURI a schema file URI. * @param nodeName the local name of the target node. * @throws Exception if there is an error loading the schema or if the root element count in the schema is less than * one. */ public SchemaLoader(String schemaFileURI, String nodeName) throws Exception { this.setSchemaFileURI(schemaFileURI); targetNode = nodeName; // get DOM Implementation using DOM Registry System.setProperty(DOMImplementationRegistry.PROPERTY, DOMXSImplementationSourceImpl.class.getName()); impRegistry = DOMImplementationRegistry.newInstance(); XSImplementation impl = (XSImplementation) impRegistry.getDOMImplementation("XS-Loader"); XSLoader schemaLoader = impl.createXSLoader(null); // schemaLoader.getConfig().setParameter("validate", Boolean.TRUE); String[] soapenvSchemaPath = { schemaFileURI, this.getClass().getResource(SOAP_11_SCHEMA_PATH).toExternalForm() }; StringList schemaList = new StringListImpl(soapenvSchemaPath, 2); xsModel = schemaLoader.loadURIList(schemaList); this.referenceNodes = new SchemaHelper(xsModel); if (nodeName != null && 0 < nodeName.trim().length()) { nodeChoiceList = referenceNodes.getAncestors(nodeName); } }
public static void main(String[] args) throws Exception { String format = "javax_imageio_1.0"; BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next(); IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null); DOMImplementationRegistry registry; registry = DOMImplementationRegistry.newInstance(); DOMImplementation impl = registry.getDOMImplementation("XML 3.0"); Document doc = impl.createDocument(null, format, null); Element root, text, entry; root = doc.getDocumentElement(); root.appendChild(text = doc.createElement("Text")); text.appendChild(entry = doc.createElement("TextEntry")); // keyword isn't #REQUIRED by the standard metadata format. // However, it is required by the PNG format, so we include it here. entry.setAttribute("keyword", "Comment"); entry.setAttribute("value", "Some demo comment"); meta.mergeTree(format, root); }
/** * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927 * DOMConfiguration.setParameter("well-formed",true) throws an exception. * * @throws Exception If any errors occur. */ @Test public void testCreateNewItem2Sell() throws Exception { String xmlFile = XML_DIR + "novelsInvalid.xml"; Document document = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(xmlFile); document.getDomConfig().setParameter("well-formed", true); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); MyDOMOutput domOutput = new MyDOMOutput(); domOutput.setByteStream(System.out); LSSerializer writer = impl.createLSSerializer(); writer.write(document, domOutput); }
/** * Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132 * test throws DOM Level 1 node error. * * @throws Exception If any errors occur. */ @Test public void testCreateNewItem2SellRetry() throws Exception { String xmlFile = XML_DIR + "accountInfo.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(xmlFile); DOMConfiguration domConfig = document.getDomConfig(); MyDOMErrorHandler errHandler = new MyDOMErrorHandler(); domConfig.setParameter("error-handler", errHandler); DOMImplementationLS impl = (DOMImplementationLS) DOMImplementationRegistry.newInstance() .getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); MyDOMOutput domoutput = new MyDOMOutput(); domoutput.setByteStream(System.out); writer.write(document, domoutput); document.normalizeDocument(); writer.write(document, domoutput); assertFalse(errHandler.isError()); }
/** * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927 * DOMConfiguration.setParameter("well-formed",true) throws an exception. * * @throws Exception If any errors occur. */ @Test(groups = {"readLocalFiles"}) public void testCreateNewItem2Sell() throws Exception { String xmlFile = XML_DIR + "novelsInvalid.xml"; Document document = DocumentBuilderFactory.newInstance() .newDocumentBuilder().parse(xmlFile); document.getDomConfig().setParameter("well-formed", true); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); MyDOMOutput domOutput = new MyDOMOutput(); domOutput.setByteStream(System.out); LSSerializer writer = impl.createLSSerializer(); writer.write(document, domOutput); }
/** * Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132 * test throws DOM Level 1 node error. * * @throws Exception If any errors occur. */ @Test(groups = {"readLocalFiles"}) public void testCreateNewItem2SellRetry() throws Exception { String xmlFile = XML_DIR + "accountInfo.xml"; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document document = dbf.newDocumentBuilder().parse(xmlFile); DOMConfiguration domConfig = document.getDomConfig(); MyDOMErrorHandler errHandler = new MyDOMErrorHandler(); domConfig.setParameter("error-handler", errHandler); DOMImplementationLS impl = (DOMImplementationLS) DOMImplementationRegistry.newInstance() .getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); MyDOMOutput domoutput = new MyDOMOutput(); domoutput.setByteStream(System.out); writer.write(document, domoutput); document.normalizeDocument(); writer.write(document, domoutput); assertFalse(errHandler.isError()); }
/** * ` * Serialize XML objects * * @param xmlObject : XACML or SAML objects to be serialized * @return serialized XACML or SAML objects * @throws EntitlementException */ private String marshall(XMLObject xmlObject) throws EntitlementException { try { doBootstrap(); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStream); writer.write(element, output); return byteArrayOutputStream.toString(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new EntitlementException("Error Serializing the SAML Response", e); } }
/** * Serializes the specified SAML 2.0 based XML content representation to its corresponding actual XML syntax * representation. * * @param xmlObject the SAML 2.0 based XML content object * @return a {@link String} representation of the actual XML representation of the SAML 2.0 based XML content * representation * @throws SSOException if an error occurs during the marshalling process */ public static String marshall(XMLObject xmlObject) throws SSOException { try { Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(xmlObject); Element element = null; if (marshaller != null) { element = marshaller.marshall(xmlObject); } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS implementation = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = implementation.createLSSerializer(); LSOutput output = implementation.createLSOutput(); output.setByteStream(byteArrayOutputStream); writer.write(element, output); return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); } catch (ClassNotFoundException | InstantiationException | MarshallingException | IllegalAccessException e) { throw new SSOException("Error in marshalling SAML 2.0 Assertion", e); } }
public DomDocumentBuilderFactory() { try { DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance(); impl = reg.getDOMImplementation("LS 3.0"); if (impl == null) { throw new FactoryConfigurationError("no LS implementations found"); } ls = (DOMImplementationLS) impl; } catch (Exception e) { throw new FactoryConfigurationError(e); } }
public static String format(String xml) { try { final InputSource src = new InputSource(new StringReader(xml)); final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement(); final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml")); //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer(); writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified. writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted. return writer.writeToString(document); } catch (Exception e) { return xml; } }
/** * Serializes a node using a certain character encoding. * * @param node * DOM node to serialize * @param os * output stream, to which the node is serialized * @param omitXmlDeclaration * indicator whether to omit the XML declaration or not * @param encoding * character encoding, can be <code>null</code>, if * <code>null</code> then "UTF-8" is used * @throws Exception */ public static void transformNonTextNodeToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration, String encoding) throws Exception { //NOPMD // previously we used javax.xml.transform.Transformer, however the JDK xalan implementation did not work correctly with a specified encoding // therefore we switched to DOMImplementationLS if (encoding == null) { encoding = "UTF-8"; } DOMImplementationRegistry domImplementationRegistry = DOMImplementationRegistry.newInstance(); DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementationRegistry.getDOMImplementation("LS"); LSOutput lsOutput = domImplementationLS.createLSOutput(); lsOutput.setEncoding(encoding); lsOutput.setByteStream(os); LSSerializer lss = domImplementationLS.createLSSerializer(); lss.getDomConfig().setParameter("xml-declaration", !omitXmlDeclaration); lss.write(node, lsOutput); }
protected String formatHtml(String html) throws MojoExecutionException { try { InputSource src = new InputSource(new StringReader(html)); Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement(); Boolean keepDeclaration = Boolean.valueOf(html.startsWith("<?xml")); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); return writer.writeToString(document); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }
/** * This method configures the CEP. * * @return It returns a well configured esper service provider instance. */ private EPServiceProvider configure() { // configure logging System.setProperty(DOMImplementationRegistry.PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); // configure supported event ids Configuration config = new Configuration(); config.addEventTypeAutoName(LogEvent.class.getPackage().getName()); // create provider EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config); // discover schema url URL schemaURL = ComplexEventProcessor.class.getClassLoader().getResource(eventLogFile); logger.info("xsd path is: " + schemaURL.toString()); // configure default xml stream ConfigurationEventTypeXMLDOM sensorcfg = new ConfigurationEventTypeXMLDOM(); sensorcfg.setRootElementName("log"); sensorcfg.setSchemaResource(schemaURL.toString()); epService.getEPAdministrator().getConfiguration() .addEventType(LogEvent.LogEventStream, sensorcfg); return epService; }
public void testEvent() throws Exception { //URL url = ResourceLoader.resolveClassPathOrURLResource("schema", "regression/typeTestSchema.xsd"); URL url = ResourceLoader.resolveClassPathOrURLResource("schema", "regression/simpleSchema.xsd", this.getClass().getClassLoader()); String uri = url.toURI().toString(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); registry.addSource(new DOMXSImplementationSourceImpl()); XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader"); XSLoader schemaLoader = impl.createXSLoader(null); XSModel xsModel = schemaLoader.loadURI(uri); XSNamedMap elements = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION); for (int i = 0; i < elements.getLength(); i++) { XSObject object = elements.item(i); //System.out.println("name '" + object.getName() + "' namespace '" + object.getNamespace()); } XSElementDeclaration dec = (XSElementDeclaration) elements.item(0); XSComplexTypeDefinition complexActualElement = (XSComplexTypeDefinition) dec.getTypeDefinition(); printSchemaDef(complexActualElement, 2); }
/** * Marshall a SAML XML object into a W3C DOM and then into a String * * @param pXMLObject SAML Object to marshall * @return XML version of the SAML Object in string form */ private String marshall(XMLObject pXMLObject) { try { MarshallerFactory lMarshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller lMarshaller = lMarshallerFactory.getMarshaller(pXMLObject); Element lElement = lMarshaller.marshall(pXMLObject); DOMImplementationLS lDOMImplementationLS = (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS"); LSSerializer lSerializer = lDOMImplementationLS.createLSSerializer(); LSOutput lOutput = lDOMImplementationLS.createLSOutput(); lOutput.setEncoding("UTF-8"); Writer lStringWriter = new StringWriter(); lOutput.setCharacterStream(lStringWriter); lSerializer.write(lElement, lOutput); return lStringWriter.toString(); } catch (Exception e) { throw new ExInternal("Error Serializing the SAML Response", e); } }
/** * Method to generated idented XML * Credit: Steve McLeod and DaoWen. * Code from http://stackoverflow.com/a/11519668 * @param xml input xml in string format * @return indented xml in string format */ public static String indentXML(String xml) { try { final InputSource src = new InputSource(new StringReader(xml)); final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement(); final Boolean keepDeclaration = xml.startsWith("<?xml"); //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer(); writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified. writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted. return writer.writeToString(document); } catch (Exception e) { throw new RuntimeException(e); } }
public XSParser(LSResourceResolver entityResolver, DOMErrorHandler errorHandler){ System.setProperty(DOMImplementationRegistry.PROPERTY, DOMXSImplementationSourceImpl.class.getName()); DOMImplementationRegistry registry; try{ registry = DOMImplementationRegistry.newInstance(); }catch(Exception ex){ throw new ImpossibleException(ex); } XSImplementationImpl xsImpl = (XSImplementationImpl)registry.getDOMImplementation("XS-Loader"); xsLoader = xsImpl.createXSLoader(null); DOMConfiguration config = xsLoader.getConfig(); config.setParameter(Constants.DOM_VALIDATE, Boolean.TRUE); if(entityResolver!=null) config.setParameter(Constants.DOM_RESOURCE_RESOLVER, entityResolver); if(errorHandler!=null) config.setParameter(Constants.DOM_ERROR_HANDLER, errorHandler); }
private static void assertDoctype( String name, String pubid, String systemId, String text) throws Exception { Function<DOMImplementation, DocumentType> maker = DoctypeMaker.parse(text); if (name == null) { assertNull(text, maker); return; } else { assertNotNull(text, maker); DOMImplementation impl = DOMImplementationRegistry.newInstance() .getDOMImplementation("XML 1.0 Traversal"); DocumentType doctype = maker.apply(impl); assertEquals(text, name, doctype.getName()); assertEquals(text, systemId, doctype.getSystemId()); assertEquals(text, pubid, doctype.getPublicId()); } }
@Override public void setUp() throws Exception { super.setUp(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementation domImpl = registry.getDOMImplementation( "XML 1.0 Traversal 2.0"); String qname = "html"; String systemId = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; String publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN"; DocumentType documentType = domImpl.createDocumentType( qname, publicId, systemId); Document doc = domImpl.createDocument(null, null, documentType); mq = new SimpleMessageQueue(); stack = new Html5ElementStack(doc, false, mq); stack.open(false); }
protected static String nodeToString(Node n, boolean pretty) { try { final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer(); writer.getDomConfig().setParameter("xml-declaration", false); if (pretty) { writer.getDomConfig().setParameter("format-pretty-print", true); } return writer.writeToString(n); } catch (final Exception e) { throw new RuntimeException(e); } }
/** Utility methods */ private void writeXmlDocumentToFile(Node node, String filename) { try { // find file or create one and save all info File file = new File(filename); if(!file.exists()) { file.createNewFile(); } DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS implementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSOutput output = implementationLS.createLSOutput(); output.setEncoding("UTF-8"); output.setCharacterStream(new FileWriter(file)); LSSerializer serializer = implementationLS.createLSSerializer(); serializer.getDomConfig().setParameter("format-pretty-print", true); serializer.write(node, output); } catch (Exception e1) { e1.printStackTrace(); } }
private String getXmlString(Node node) { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS implementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSOutput output = implementationLS.createLSOutput(); output.setEncoding(this.xmlEncoding); output.setCharacterStream(new StringWriter()); LSSerializer serializer = implementationLS.createLSSerializer(); serializer.write(node, output); return output.getCharacterStream().toString(); } catch (Exception e1) { e1.printStackTrace(); } return null; }
protected String serialize(Node n) throws ClassNotFoundException, InstantiationException, IllegalAccessException{ System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); String str = writer.writeToString(n); // sometimes we get processor directives, such as <?xml version="1.0"?> // strip these out Pattern directivePattern = Pattern.compile("<\\?xml.*$", Pattern.MULTILINE); Matcher m = directivePattern.matcher(str); str = m.replaceFirst(""); return str; }
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object * @throws SAMLSSOException */ public static String marshall(XMLObject xmlObject) throws SAMLSSOException { try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration .getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStrm); writer.write(element, output); return byteArrayOutputStrm.toString(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new SAMLSSOException("Error Serializing the SAML Response", e); } }
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object * @throws SAML2SSOUIAuthenticatorException */ public static String marshall(XMLObject xmlObject) throws SAML2SSOUIAuthenticatorException { try { doBootstrap(); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration .getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStrm); writer.write(element, output); return byteArrayOutputStrm.toString(); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new SAML2SSOUIAuthenticatorException("Error Serializing the SAML Response", e); } }
private static String marshall(XMLObject xmlObject) throws org.wso2.carbon.identity.base.IdentityException { try { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject); Element element = marshaller.marshall(xmlObject); ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream(); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setByteStream(byteArrayOutputStrm); writer.write(element, output); return byteArrayOutputStrm.toString("UTF-8"); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw IdentityException.error("Error Serializing the SAML Response", e); } }
private void loadContext(final Collection<String> routes) { try { DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance(); DOMImplementationLS domImpl = (DOMImplementationLS) reg.getDOMImplementation("LS"); LSParser parser = domImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); JAXBContext jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); List<RouteDefinition> routeDefs = new ArrayList<>(); for (String route : routes) { try (InputStream input = IOUtils.toInputStream(route, StandardCharsets.UTF_8)) { LSInput lsinput = domImpl.createLSInput(); lsinput.setByteStream(input); Node routeElement = parser.parse(lsinput).getDocumentElement(); routeDefs.add(unmarshaller.unmarshal(routeElement, RouteDefinition.class).getValue()); } } camelContext.addRouteDefinitions(routeDefs); } catch (Exception e) { LOG.error("While loading Camel context {}", e); throw new CamelException(e); } }