diff --git a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java index bccd61fe8dd98..9d3b8971a382d 100644 --- a/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java +++ b/components/camel-xslt/src/main/java/org/apache/camel/component/xslt/XsltEndpoint.java @@ -386,9 +386,7 @@ protected XsltBuilder createXsltBuilder() throws Exception { LOG.debug("Using TransformerFactory {}", factory); xslt.setTransformerFactory(factory); } - if (resultHandlerFactory != null) { - xslt.setResultHandlerFactory(resultHandlerFactory); - } + if (errorListener != null) { xslt.errorListener(errorListener); } @@ -400,6 +398,10 @@ protected XsltBuilder createXsltBuilder() throws Exception { configureOutput(xslt, output.name()); + if (resultHandlerFactory != null) { + xslt.setResultHandlerFactory(resultHandlerFactory); + } + // any additional transformer parameters then make a copy to avoid side-effects if (parameters != null) { Map copy = new HashMap<>(parameters); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/xslt/XsltResultHandlerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/xslt/XsltResultHandlerTest.java new file mode 100644 index 0000000000000..ae3efa43fc54e --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/component/xslt/XsltResultHandlerTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.xslt; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.TestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class XsltResultHandlerTest extends TestSupport { + + @Test + public void testResultHandlerFactory() throws Exception { + RouteBuilder builder = createRouteBuilder(); + CamelContext context = new DefaultCamelContext(); + ResultHandlerFactory factory = new DomResultHandlerFactory(); + context.getRegistry().bind("factory", factory); + context.addRoutes(builder); + context.start(); + + XsltEndpoint endpoint = null; + for (Endpoint ep : context.getEndpoints()) { + if (ep instanceof XsltEndpoint) { + endpoint = (XsltEndpoint) ep; + break; + } + } + + assertNotNull(endpoint); + assertEquals(DomResultHandlerFactory.class, factory.getClass()); + assertEquals(factory, endpoint.getResultHandlerFactory()); + assertEquals(factory, endpoint.getXslt().getResultHandlerFactory()); + } + + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("direct:start").to("xslt:org/apache/camel/component/xslt/example.xsl?output=bytes&resultHandlerFactory=#factory"); + } + }; + } + +}