This is an automated email from the ASF dual-hosted git repository. reta pushed a commit to branch 4.1.x-fixes in repository https://gitbox.apache.org/repos/asf/cxf.git
commit fe95db3e44b6b194141ac43f4f2af443b3b46e37 Author: Guillaume Nodet <[email protected]> AuthorDate: Wed Mar 18 15:06:50 2026 +0100 Fix @HandlerChain resource resolution for cross-package SEI (#2961) * 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]> (cherry picked from commit ee61a8522ec02eb5377418cae553790795521b91) --- .../handler/AnnotationHandlerChainBuilder.java | 3 +- .../JakartaAnnotationHandlerChainBuilderTest.java | 35 +++++++++++++++++++++- .../cxf/jaxws/handler/sei/HandlerChainTestSEI.java | 32 ++++++++++++++++++++ .../apache/cxf/jaxws/handler/sei/sei-handlers.xml | 29 ++++++++++++++++++ 4 files changed, 97 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 a2a0ce5ea75..3128cae8af3 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 f74ae32dd40..13e613ee0c5 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 @@ -29,6 +29,7 @@ import jakarta.xml.ws.handler.Handler; 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 +138,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 00000000000..1014af91ab0 --- /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 00000000000..cfe75c6de97 --- /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>
