[
https://issues.apache.org/jira/browse/CAMEL-20801?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-20801:
--------------------------------
Fix Version/s: 4.x
> camel-xpath: can't customize the underlying CamelXmlJaxpBulkConverterLoader
> ---------------------------------------------------------------------------
>
> Key: CAMEL-20801
> URL: https://issues.apache.org/jira/browse/CAMEL-20801
> Project: Camel
> Issue Type: Wish
> Affects Versions: 4.6.0
> Reporter: Cosimo Damiano Prete
> Priority: Minor
> Fix For: 4.x
>
>
> Hello.
> I've a route which gets in input an XML file (from a TCP connection) and I
> would like to dump its content on the disk, for debug purposes for example,
> before processing it.
> {code:java}
> @Override
> public void configure() {
> from(sourceEndpoint) // TCP connection
> .wireTap(rawMessageDumper) // File endpoint; see below
> .to(cdataWrapperEndpoint) // Saxon XSLT component to wrap some elements
> within CDATA
> .process(ackProcessor); // Send the ACK to the TCP client
> }{code}
> I've been implementing it with a {{wiretap}} to a {{file}} endpoint using as
> value for the {{fileName}} property an expression that builds the name of the
> file from some attributes within the XML itself:
> {code:java}
> @Bean
> public FileEndpoint rawMessageDumper(CamelContext context,
> MessageDumpProperties messageDumpProperties) {
> final FileComponent component = context.getComponent("file",
> FileComponent.class);
> final FileEndpoint endpoint = new FileEndpoint(null, component);
> endpoint.setFile(messageDumpProperties.getTargetPath());
> endpoint.setExchangePattern(InOut); // Dunno if it's really needed to
> keep the message also to the rest of the pipeline
> endpoint.setFileName(concatExpression(List.of(
> constantExpression("foo:"),
> xpath("/doc/fooml/@docdate", String.class),
> constantExpression(":"),
> xpath("/doc/fooml/@seq", String.class),
> constantExpression(".xml")
> )));
> return endpoint;
> } {code}
> Unfortunately, when the {{CamelXmlJaxpBulkConverterLoader}} runs to convert
> the String in input to a Document in order to evaluate the XPath expression,
> it fails because the [http://apache.org/xml/features/disallow-doctype-decl]
> feature is disabled and the XML has indeed a {{DOCTYPE}} declaration in it.
> The Saxon XSLT endpoint which I use in the {{to(cdataWrapperEndpoint)}} step
> of the pipeline is somehow able to automatically use the {{XmlInputFactory}}
> I've defined in the application context which solved this same issue. Below
> the code for some reference:
> {code:java}
> @Bean
> public XsltEndpoint cdataWrapperEndpoint(CamelContext context) {
> final XsltSaxonComponent component = context.getComponent("xslt-saxon",
> XsltSaxonComponent.class);
> final XsltSaxonEndpoint endpoint = new XsltSaxonEndpoint(null, component);
> endpoint.setUriResolver(new XsltUriResolver(context, XSL_FILENAME));
> // The line below is needed if you switch to the XSLT component instead
> of the Saxon one
> // Do not try to resolve external entities and DTDs
> //endpoint.setEntityResolver((publicId, systemId) -> new InputSource(new
> StringReader("")));
> return endpoint;
> }
> @Bean
> public XMLOutputFactory outputFactory() {
> return new WstxOutputFactory();
> }
> @Bean
> public XMLInputFactory inputFactory() {
> XMLInputFactory inputFactory = new WstxInputFactory();
> inputFactory.setProperty(IS_NAMESPACE_AWARE, false);
> inputFactory.setProperty(SUPPORT_DTD, false);
> inputFactory.setProperty(IS_SUPPORTING_EXTERNAL_ENTITIES, false);
> inputFactory.setProperty(IS_REPLACING_ENTITY_REFERENCES, false);
> return inputFactory;
> }{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)