This is an automated email from the ASF dual-hosted git repository. Croway pushed a commit to branch camel-4.18.6-recipes in repository https://gitbox.apache.org/repos/asf/camel-upgrade-recipes.git
commit 9e2447fd50b6a41113a52eceb3ac2e4b99088902 Author: croway <[email protected]> AuthorDate: Mon Nov 30 11:27:51 2026 +0100 Migrate the camel-cxf operationName and operationNamespace headers Camel 4.18.3 and 4.21.0 renamed the CxfConstants OPERATION_NAME and OPERATION_NAMESPACE header values, shared by camel-cxf and camel-cxfrs, from operationName / operationNamespace to CamelCxfOperationName / CamelCxfOperationNamespace, and no recipe covered it. Since 4.18.6 (and 4.22.3, 4.24.0) the former names are also filtered out of the HTTP headers, so a route that still sets them silently invokes the first operation. Following RECIPE-CONVENTIONS.md the recipe lives in camel418_3, chained by camel418_3.CamelMigrationRecipe and referenced from camel421: it renames the literal header names (Java header methods, Simple, XML and YAML DSL) and the cxf() / cxfrs() Endpoint DSL header name builders, gated on camel-cxf*. The header names are generic, and since 4.18.3 a route may read an incoming header named operationName on purpose to map it to CamelCxfOperationName. The 4.18 LTS aggregate runs camel418_3 on every upgrade, so a plain rename would turn such a mapping into a copy of the header onto itself. The new RenameHeadersInUnmigratedFiles renames like RenameHeaders but leaves alone a file that already mentions one of the new names, checked once on the file as it was, so a file is migrated completely or not at all. --- .../camel418_3/RenameHeadersInUnmigratedFiles.java | 157 +++++++++++++ .../main/resources/META-INF/rewrite/4.18.3.yaml | 38 +++- .../src/main/resources/META-INF/rewrite/4.21.yaml | 1 + .../apache/camel/upgrade/CamelUpdate418_3Test.java | 251 +++++++++++++++++++++ release_notes.adoc | 4 + 5 files changed, 450 insertions(+), 1 deletion(-) diff --git a/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel418_3/RenameHeadersInUnmigratedFiles.java b/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel418_3/RenameHeadersInUnmigratedFiles.java new file mode 100644 index 0000000..6948863 --- /dev/null +++ b/camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel418_3/RenameHeadersInUnmigratedFiles.java @@ -0,0 +1,157 @@ +/* + * 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.upgrade.camel418_3; + +import org.jspecify.annotations.Nullable; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Option; +import org.openrewrite.Recipe; +import org.openrewrite.SourceFile; +import org.openrewrite.Tree; +import org.openrewrite.TreeVisitor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Renames Camel headers like {@link RenameHeaders}, in the same places, but only in a source file that mentions the + * component ({@code requiredText}) and does not look migrated already: it mentions neither one of the new header + * names nor one of the {@code migratedText}, such as the constant or the Endpoint DSL method that holds a new name. + * <p> + * Use it when the old header names are generic and stay valid as application headers after the rename, so that code + * written for the new names may still read an old one on purpose: for example a route that maps an incoming + * {@code operationName} header to {@code CamelCxfOperationName} (or {@code CxfConstants.OPERATION_NAME}). Renaming + * that file again would turn the mapping into a copy of the header onto itself. The LTS aggregates run every patch + * recipe of their line, including the ones the project was already migrated by, so this matters on each upgrade, not + * only on the first one. + * <p> + * The checks are made once per file, on the file as it was before any of the renames, so a file is migrated + * completely or not at all. + */ +public class RenameHeadersInUnmigratedFiles extends Recipe { + + @Option(displayName = "Header mappings", + description = "Map of old header names to new header names", + example = "operationName: CamelCxfOperationName") + Map<String, String> headerMappings; + + @Option(displayName = "Required text", + description = "Only a source file containing one of these texts is renamed, for example the scheme of the " + + "component, so that a header of the same name in unrelated routes of the module is left alone.", + example = "[\"cxf:\", \"cxfrs:\"]", + required = false) + List<String> requiredText; + + @Option(displayName = "Migrated text", + description = "Besides the new header names, texts that show a source file is migrated already, such as " + + "the constant or the Endpoint DSL method holding a new header name.", + example = "[CxfConstants.OPERATION_NAME, cxfOperationName(]", + required = false) + List<String> migratedText; + + public RenameHeadersInUnmigratedFiles() { + } + + public RenameHeadersInUnmigratedFiles(Map<String, String> headerMappings) { + this.headerMappings = headerMappings; + } + + public void setHeaderMappings(Map<String, String> headerMappings) { + this.headerMappings = headerMappings; + } + + public void setRequiredText(List<String> requiredText) { + this.requiredText = requiredText; + } + + public void setMigratedText(List<String> migratedText) { + this.migratedText = migratedText; + } + + @Override + public String getDisplayName() { + return "Rename Camel header(s) across all DSLs in files not migrated yet"; + } + + @Override + public String getDescription() { + return "Renames Camel header(s) like RenameHeaders (Java header methods, Simple expressions, XML and YAML DSL), " + + "but only in a source file that contains one of the required texts and skips a source file that already " + + "mentions one of the new header names or of the migrated texts, where the old name may be read on purpose."; + } + + @Override + public TreeVisitor<?, ExecutionContext> getVisitor() { + List<TreeVisitor<?, ExecutionContext>> renames = new ArrayList<>(); + for (Map.Entry<String, String> mapping : headerMappings.entrySet()) { + renames.add(new RenameHeaderInJavaMethod(mapping.getKey(), mapping.getValue()).getVisitor()); + renames.add(new RenameHeaderInSimpleExpression(mapping.getKey(), mapping.getValue()).getVisitor()); + renames.add(new RenameHeaderInXmlDsl(mapping.getKey(), mapping.getValue()).getVisitor()); + renames.add(new RenameHeaderInYamlDsl(mapping.getKey(), mapping.getValue()).getVisitor()); + } + List<String> migrated = new ArrayList<>(headerMappings.values()); + if (migratedText != null) { + migrated.addAll(migratedText); + } + return new UnmigratedFileVisitor(requiredText == null ? List.of() : List.copyOf(requiredText), migrated, renames); + } + + private static class UnmigratedFileVisitor extends TreeVisitor<Tree, ExecutionContext> { + private final List<String> requiredText; + private final List<String> migratedText; + private final List<TreeVisitor<?, ExecutionContext>> renames; + + UnmigratedFileVisitor(List<String> requiredText, List<String> migratedText, + List<TreeVisitor<?, ExecutionContext>> renames) { + this.requiredText = requiredText; + this.migratedText = migratedText; + this.renames = renames; + } + + @Override + public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) { + for (TreeVisitor<?, ExecutionContext> rename : renames) { + if (rename.isAcceptable(sourceFile, ctx)) { + return true; + } + } + return false; + } + + @Override + public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { + if (!(tree instanceof SourceFile)) { + return tree; + } + String source = ((SourceFile) tree).printAll(); + if (!requiredText.isEmpty() && requiredText.stream().noneMatch(source::contains)) { + return tree; + } + if (migratedText.stream().anyMatch(source::contains)) { + return tree; + } + Tree t = tree; + for (TreeVisitor<?, ExecutionContext> rename : renames) { + if (t instanceof SourceFile && rename.isAcceptable((SourceFile) t, ctx)) { + t = rename.visit(t, ctx); + } + } + return t; + } + } +} diff --git a/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.18.3.yaml b/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.18.3.yaml index ec74778..18b3234 100644 --- a/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.18.3.yaml +++ b/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.18.3.yaml @@ -41,6 +41,7 @@ recipeList: - org.apache.camel.upgrade.camel418_3.upgradeMongoDbGridFsHeaders - org.apache.camel.upgrade.camel418_3.upgradeOpenstackHeaders - org.apache.camel.upgrade.camel418_3.upgradeWeb3jHeaders + - org.apache.camel.upgrade.camel418_3.upgradeCxfHeaders # Partial automation - header string literals migrated, DSL accessor methods require manual update - org.apache.camel.upgrade.camel418_3.upgradeLuceneHeaders --- @@ -297,4 +298,39 @@ recipeList: TO_BLOCK: CamelWeb3jToBlock PRIVATE_FOR: CamelWeb3jPrivateFor PRIVATE_FROM: CamelWeb3jPrivateFrom - ETH_HASHRATE: CamelWeb3jEthHashrate \ No newline at end of file + ETH_HASHRATE: CamelWeb3jEthHashrate +--- +## https://github.com/apache/camel/blob/main/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc#camel-cxf---potential-breaking-change +type: specs.openrewrite.org/v1beta/recipe +name: org.apache.camel.upgrade.camel418_3.upgradeCxfHeaders +displayName: Migrate the camel-cxf operationName and operationNamespace headers +description: >- + Camel 4.18.3 and 4.21.0 renamed the CxfConstants OPERATION_NAME and OPERATION_NAMESPACE header values, shared by + camel-cxf and camel-cxfrs, from operationName and operationNamespace to CamelCxfOperationName and + CamelCxfOperationNamespace; since 4.18.6, 4.22.3 and 4.24.0 the former names are also filtered out of the HTTP + headers. Renames the Endpoint DSL header name builder methods (the former ones no longer exist), and the literal + header names (Java header methods, Simple expressions, XML and YAML DSL); CxfConstants usages need no change. The + header names are generic, so they are renamed only in a source file that mentions a cxf or cxfrs endpoint and does + not look migrated already (it mentions a new name, CxfConstants.OPERATION_NAME or OPERATION_NAMESPACE, or + cxfOperationName() / cxfOperationNamespace()), because such a file may read an application header named + operationName on purpose, for example to map it to CamelCxfOperationName. +preconditions: + - org.openrewrite.java.dependencies.search.ModuleHasDependency: + groupIdPattern: org.apache.camel + artifactIdPattern: camel-cxf* +recipeList: + - org.apache.camel.upgrade.camel418_3.RenameHeadersInUnmigratedFiles: + headerMappings: + operationName: CamelCxfOperationName + operationNamespace: CamelCxfOperationNamespace + requiredText: ["cxf:", "cxfrs:", "cxf(", "cxfrs("] + migratedText: [CxfConstants.OPERATION_NAME, CxfConstants.OPERATION_NAMESPACE, "cxfOperationName(", "cxfOperationNamespace("] + - org.openrewrite.java.ChangeMethodName: + methodPattern: org.apache.camel.builder.endpoint.dsl.CxfEndpointBuilderFactory.CxfHeaderNameBuilder operationName() + newMethodName: cxfOperationName + - org.openrewrite.java.ChangeMethodName: + methodPattern: org.apache.camel.builder.endpoint.dsl.CxfEndpointBuilderFactory.CxfHeaderNameBuilder operationNamespace() + newMethodName: cxfOperationNamespace + - org.openrewrite.java.ChangeMethodName: + methodPattern: org.apache.camel.builder.endpoint.dsl.CxfRsEndpointBuilderFactory.CxfRsHeaderNameBuilder operationName() + newMethodName: cxfOperationName diff --git a/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.21.yaml b/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.21.yaml index 959421f..2261ea5 100644 --- a/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.21.yaml +++ b/camel-upgrade-recipes/src/main/resources/META-INF/rewrite/4.21.yaml @@ -41,6 +41,7 @@ recipeList: - org.apache.camel.upgrade.camel418_3.upgradeLuceneHeaders - org.apache.camel.upgrade.camel418_3.upgradeOpenstackHeaders - org.apache.camel.upgrade.camel418_3.upgradeWeb3jHeaders + - org.apache.camel.upgrade.camel418_3.upgradeCxfHeaders ## defined here - org.apache.camel.upgrade.camel421.upgradeKafkaRecipes - org.apache.camel.upgrade.camel421.upgradeDnsHeaders diff --git a/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate418_3Test.java b/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate418_3Test.java index c347f85..b7ca011 100644 --- a/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate418_3Test.java +++ b/camel-upgrade-recipes/src/test/java/org/apache/camel/upgrade/CamelUpdate418_3Test.java @@ -23,6 +23,8 @@ import org.openrewrite.test.TypeValidation; import static org.openrewrite.java.Assertions.java; import static org.openrewrite.java.Assertions.mavenProject; +import static org.openrewrite.xml.Assertions.xml; +import static org.openrewrite.yaml.Assertions.yaml; /** * Tests for migrating from Camel 4.18.1 to 4.18.3. @@ -569,5 +571,254 @@ public class CamelUpdate418_3Test implements RewriteTest { ); } + @Test + void cxfHeadersMigrationJava() { + //language=java + rewriteRun( + mavenProject("test-cxf", + CamelTestUtil.pomXmlSpec("camel-cxf-soap", CamelTestUtil.CamelVersion.v4_18_1), + java( + """ + import org.apache.camel.builder.RouteBuilder; + + public class CxfRoute extends RouteBuilder { + @Override + public void configure() { + from("cxf:bean:orderService") + .choice() + .when(header("operationName").isEqualTo("placeOrder")).to("direct:place") + .end() + .log("operation ${header.operationName} in ${header.operationNamespace}"); + + from("direct:call") + .setHeader("operationName", constant("getOrder")) + .setHeader("operationNamespace", constant("http://example.com/orders")) + .to("cxf:bean:orderClient"); + } + } + """, + """ + import org.apache.camel.builder.RouteBuilder; + + public class CxfRoute extends RouteBuilder { + @Override + public void configure() { + from("cxf:bean:orderService") + .choice() + .when(header("CamelCxfOperationName").isEqualTo("placeOrder")).to("direct:place") + .end() + .log("operation ${header.CamelCxfOperationName} in ${header.CamelCxfOperationNamespace}"); + + from("direct:call") + .setHeader("CamelCxfOperationName", constant("getOrder")) + .setHeader("CamelCxfOperationNamespace", constant("http://example.com/orders")) + .to("cxf:bean:orderClient"); + } + } + """ + ) + ) + ); + } + + @Test + void cxfHeadersMigrationXmlAndYaml() { + rewriteRun( + mavenProject("test-cxf-dsl", + CamelTestUtil.pomXmlSpec("camel-cxf-rest", CamelTestUtil.CamelVersion.v4_18_1), + //language=xml + xml( + """ + <routes xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:call"/> + <setHeader name="operationName"> + <constant>getCustomer</constant> + </setHeader> + <to uri="cxfrs:bean:customerClient"/> + </route> + </routes> + """, + """ + <routes xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:call"/> + <setHeader name="CamelCxfOperationName"> + <constant>getCustomer</constant> + </setHeader> + <to uri="cxfrs:bean:customerClient"/> + </route> + </routes> + """ + ), + //language=yaml + yaml( + """ + - route: + from: + uri: "cxfrs:bean:customerService" + steps: + - toD: + uri: "direct:${header.operationName}" + """, + """ + - route: + from: + uri: "cxfrs:bean:customerService" + steps: + - toD: + uri: "direct:${header.CamelCxfOperationName}" + """ + ) + ) + ); + } + + @Test + void cxfHeadersMigrationEndpointDsl() { + //language=java + rewriteRun( + // camel-endpointdsl 4.0.3 still has the former header name builder methods + spec -> spec.parser(CamelTestUtil.parserFromClasspath(CamelTestUtil.CamelVersion.v4_18_1, "camel-api", + "camel-core-model", "camel-support", "camel-endpointdsl")), + mavenProject("test-cxf-endpoint-dsl", + CamelTestUtil.pomXmlSpec("camel-cxf-soap", CamelTestUtil.CamelVersion.v4_18_1), + java( + """ + import org.apache.camel.builder.endpoint.EndpointRouteBuilder; + public class CxfDslRoute extends EndpointRouteBuilder { + @Override + public void configure() { + from(direct("call")) + .setHeader(cxf().operationName(), constant("getOrder")) + .setHeader(cxf().operationNamespace(), constant("http://example.com/orders")) + .setHeader(cxfrs().operationName(), constant("getCustomer")) + .to(cxf("bean:orderClient")); + } + } + """, + """ + import org.apache.camel.builder.endpoint.EndpointRouteBuilder; + + public class CxfDslRoute extends EndpointRouteBuilder { + @Override + public void configure() { + from(direct("call")) + .setHeader(cxf().cxfOperationName(), constant("getOrder")) + .setHeader(cxf().cxfOperationNamespace(), constant("http://example.com/orders")) + .setHeader(cxfrs().cxfOperationName(), constant("getCustomer")) + .to(cxf("bean:orderClient")); + } + } + """ + ) + ) + ); + } + + @Test + void cxfHeadersLeaveMigratedFilesAlone() { + // a file written for the new names may read an application header named operationName on purpose + //language=java + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(CamelTestUtil.isRecipeOverridden() ? 1 : 0), + mavenProject("test-cxf-migrated", + CamelTestUtil.pomXmlSpec("camel-cxf-soap", CamelTestUtil.CamelVersion.v4_18_3), + java( + """ + import org.apache.camel.builder.RouteBuilder; + + public class JmsToCxfRoute extends RouteBuilder { + @Override + public void configure() { + from("jms:queue:orders") + .setHeader("CamelCxfOperationName", header("operationName")) + .to("cxf:bean:orderClient"); + } + } + """ + ), + java( + """ + import org.apache.camel.builder.RouteBuilder; + import org.apache.camel.component.cxf.common.message.CxfConstants; + + public class JmsToCxfConstantRoute extends RouteBuilder { + @Override + public void configure() { + from("jms:queue:invoices") + .setHeader(CxfConstants.OPERATION_NAME, header("operationName")) + .to("cxf:bean:invoiceClient"); + } + } + """ + ), + java( + """ + import org.apache.camel.builder.endpoint.EndpointRouteBuilder; + + public class JmsToCxfDslRoute extends EndpointRouteBuilder { + @Override + public void configure() { + from(jms("queue:payments")) + .setHeader(cxf().cxfOperationName(), header("operationName")) + .to(cxf("bean:paymentClient")); + } + } + """ + ) + ) + ); + } + + @Test + void cxfHeadersLeaveRoutesWithoutCxfAlone() { + // a module with camel-cxf may have other routes that use an application header named operationName + //language=java + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(CamelTestUtil.isRecipeOverridden() ? 1 : 0), + mavenProject("test-cxf-other-routes", + CamelTestUtil.pomXmlSpec("camel-cxf-soap", CamelTestUtil.CamelVersion.v4_18_1), + java( + """ + import org.apache.camel.builder.RouteBuilder; + + public class DispatchRoute extends RouteBuilder { + @Override + public void configure() { + from("jms:queue:commands") + .toD("direct:${header.operationName}"); + } + } + """ + ) + ) + ); + } + + @Test + void preconditionBlocksCxfHeadersWithoutDependency() { + //language=java + rewriteRun( + spec -> spec.expectedCyclesThatMakeChanges(CamelTestUtil.isRecipeOverridden() ? 1 : 0), + mavenProject("test-no-cxf", + CamelTestUtil.pomXmlSpec("camel-http", CamelTestUtil.CamelVersion.v4_18_1), + java( + """ + import org.apache.camel.builder.RouteBuilder; + + public class HttpRoute extends RouteBuilder { + @Override + public void configure() { + from("direct:call") + .setHeader("operationName", constant("getOrder")) + .to("http://example.com/orders"); + } + } + """ + ) + ) + ); + } } diff --git a/release_notes.adoc b/release_notes.adoc index 34429f5..d665375 100644 --- a/release_notes.adoc +++ b/release_notes.adoc @@ -245,6 +245,10 @@ Patch recipes for Camel 4.18.6 (`camel418_6.CamelMigrationRecipe`). The backport | https://github.com/apache/camel/blob/main/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc#camel-pqc---bouncy-castle-185[camel-pqc: Bouncy Castle 1.85] | ⚠️ Partial | `camel418_6.migratePqcParameterSpecs`: `KyberParameterSpec`, `DilithiumParameterSpec` and `SPHINCSPlusParameterSpec` of `org.bouncycastle.pqc.jcajce.spec` -> `MLKEMParameterSpec`, `MLDSAParameterSpec` and `SLHDSAParameterSpec` of `org.bouncycastle.jcajce.spec` (`ChangeType`), and their parameter sets -> the ones camel-pqc 4.18.6 uses (`kyber768` -> `ml_kem_768`, `dilithium2` -> `ml_dsa_44`, `sha2_128s` -> `slh_dsa_sha2_128s`, ...; `ReplaceConstantWithAnotherConstant`), gated on `camel- [...] + +| https://github.com/apache/camel/blob/main/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc#camel-cxf-camel-cxfrs---the-former-operationname-and-operationnamespace-headers-are-not-sent[camel-cxf, camel-cxfrs: the former `operationName` and `operationNamespace` headers are not sent] +| ⚠️ Partial +| The rename to `CamelCxfOperationName` / `CamelCxfOperationNamespace` shipped in 4.18.3 and 4.21.0 without a recipe; 4.18.6 (and 4.22.3, 4.24.0) also filters the former names out of the HTTP headers. New `camel418_3.upgradeCxfHeaders`, chained by `camel418_3` and referenced from `camel421`: the Endpoint DSL builders `cxf().operationName()` / `operationNamespace()` and `cxfrs().operationName()`, and the literal header names in Java header methods, Simple, XML and YAML DSL, gated on `came [...] |=== NOTE: At the time of writing Camel 4.18.6 was not on Maven Central yet; the tests that resolve 4.18.6 artifacts were run against the staging repositories of the vote (`orgapachecamel-2094`, `orgapachecamel-2095`).
