This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch fix-handlerchain-resource-resolution in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 5f51c3094bbf8288b698f3a37eb4497af1dc3de5 Author: Guillaume Nodet <[email protected]> AuthorDate: Thu Mar 12 13:44:19 2026 +0100 Fix @HandlerChain resource resolution for cross-package SEI When @HandlerChain annotation is declared on the SEI (interface) and the implementation class is in a different package, the handler chain XML file could not be found because it was resolved relative to the implementation class instead of the declaring class (SEI). Fix resolveHandlerChainFile to use hcAnn.getDeclaringClass() instead of the passed-in implementation class. Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../handler/AnnotationHandlerChainBuilder.java | 3 +- .../JakartaAnnotationHandlerChainBuilderTest.java | 36 +++++++++++++++++++++- .../cxf/jaxws/handler/sei/HandlerChainTestSEI.java | 32 +++++++++++++++++++ .../apache/cxf/jaxws/handler/sei/sei-handlers.xml | 29 +++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java index a2a0ce5ea7..3128cae8af 100644 --- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java +++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java @@ -78,7 +78,8 @@ public class AnnotationHandlerChainBuilder extends HandlerChainBuilder { try { - URL handlerFileURL = resolveHandlerChainFile(clz, hcAnn.getFileName()); + URL handlerFileURL = resolveHandlerChainFile( + hcAnn.getDeclaringClass(), hcAnn.getFileName()); if (handlerFileURL == null) { throw new WebServiceException(new Message("HANDLER_CFG_FILE_NOT_FOUND_EXC", BUNDLE, hcAnn .getFileName()).toString()); diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JakartaAnnotationHandlerChainBuilderTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JakartaAnnotationHandlerChainBuilderTest.java index f74ae32dd4..18809a56e3 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JakartaAnnotationHandlerChainBuilderTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JakartaAnnotationHandlerChainBuilderTest.java @@ -30,6 +30,8 @@ import jakarta.xml.ws.handler.LogicalHandler; import jakarta.xml.ws.handler.LogicalMessageContext; import jakarta.xml.ws.handler.MessageContext; +import org.apache.cxf.jaxws.handler.sei.HandlerChainTestSEI; + import org.junit.Before; import org.junit.Test; @@ -137,9 +139,41 @@ public class JakartaAnnotationHandlerChainBuilderTest { } } + @Test + public void testHandlerChainResolvedFromSEI() { + // When @HandlerChain is on the SEI (in a different + // package) and the impl class is passed to the builder, + // the handler file must be resolved relative to the + // SEI, not the impl class. + AnnotationHandlerChainBuilder chainBuilder = + new AnnotationHandlerChainBuilder(); + @SuppressWarnings("rawtypes") + List<Handler> handlers = chainBuilder + .buildHandlerChainFromClass( + CrossPackageHandlerTestImpl.class, + null, null, null); + assertNotNull(handlers); + assertEquals(1, handlers.size()); + assertEquals(TestLogicalHandler.class, + handlers.get(0).getClass()); + } + @WebService() - @HandlerChain(file = "./jakarta-handlers.xml", name = "TestHandlerChain") + @HandlerChain(file = "./jakarta-handlers.xml", + name = "TestHandlerChain") public class JakartaHandlerTestImpl { } + + // Impl in this package references SEI in the 'sei' + // sub-package where the handler XML file lives. + @WebService(endpointInterface + = "org.apache.cxf.jaxws.handler.sei" + + ".HandlerChainTestSEI") + public static class CrossPackageHandlerTestImpl + implements HandlerChainTestSEI { + public String echo(String input) { + return input; + } + } } diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/sei/HandlerChainTestSEI.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/sei/HandlerChainTestSEI.java new file mode 100644 index 0000000000..1014af91ab --- /dev/null +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/sei/HandlerChainTestSEI.java @@ -0,0 +1,32 @@ +/** + * 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.cxf.jaxws.handler.sei; + +import jakarta.jws.HandlerChain; +import jakarta.jws.WebService; + +/** + * SEI with @HandlerChain pointing to a handler config file + * in the same package as this interface. + */ +@WebService() +@HandlerChain(file = "./sei-handlers.xml") +public interface HandlerChainTestSEI { + String echo(String input); +} diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/sei/sei-handlers.xml b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/sei/sei-handlers.xml new file mode 100644 index 0000000000..cfe75c6de9 --- /dev/null +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/sei/sei-handlers.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<handler-chains xmlns="https://jakarta.ee/xml/ns/jakartaee"> + <handler-chain> + <handler> + <handler-name>TestHandler</handler-name> + <handler-class> + org.apache.cxf.jaxws.handler.JakartaAnnotationHandlerChainBuilderTest$TestLogicalHandler + </handler-class> + </handler> + </handler-chain> +</handler-chains>
