This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f49be0f02753497e76ee2636cbbf10f8cfd88802
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sun Feb 20 10:00:17 2022 +0100

    Removed deprecated RouteIdFactory
---
 .../java/org/apache/camel/impl/RouteIdFactory.java | 218 ---------------------
 .../apache/camel/model/RouteDefinitionHelper.java  |   5 +-
 .../apache/camel/model/rest/VerbDefinition.java    |   9 -
 .../camel/impl/model/RouteIdFactoryTest.java       |  80 --------
 .../ROOT/pages/camel-3x-upgrade-guide-3_16.adoc    |   2 +
 5 files changed, 3 insertions(+), 311 deletions(-)

diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/RouteIdFactory.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/RouteIdFactory.java
deleted file mode 100644
index 4a50771..0000000
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/RouteIdFactory.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * 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.impl;
-
-import java.util.Optional;
-
-import org.apache.camel.NamedNode;
-import org.apache.camel.impl.engine.DefaultNodeIdFactory;
-import org.apache.camel.model.FromDefinition;
-import org.apache.camel.model.RouteDefinition;
-import org.apache.camel.model.rest.RestDefinition;
-import org.apache.camel.model.rest.VerbDefinition;
-import org.apache.camel.spi.NodeIdFactory;
-
-/**
- * Factory for generating route ids based on uris.
- * <p>
- * For direct/seda routes it returns route name (direct:start -> start). For 
rest routes it returns its method and
- * context path formatted as one string.
- * <p>
- * When id cannot be generated, falls back to other {@link NodeIdFactory} 
implementation. If none is passed in the
- * constructor, then {@link DefaultNodeIdFactory} is used.
- */
-@Deprecated
-public class RouteIdFactory implements NodeIdFactory {
-
-    private static final char SEPARATOR = '-';
-    private NodeIdFactory defaultNodeIdFactory;
-
-    public RouteIdFactory() {
-        defaultNodeIdFactory = new DefaultNodeIdFactory();
-    }
-
-    public RouteIdFactory(NodeIdFactory defaultNodeIdFactory) {
-        this.defaultNodeIdFactory = defaultNodeIdFactory;
-    }
-
-    @Override
-    public String createId(NamedNode definition) {
-        if (definition instanceof RouteDefinition) {
-            Optional<String> id = extractId((RouteDefinition) definition);
-
-            if (id.isPresent()) {
-                return id.get();
-            }
-
-            id = extractIdFromRestDefinition((RouteDefinition) definition);
-
-            if (id.isPresent()) {
-                return id.get();
-            }
-        }
-
-        if (definition instanceof VerbDefinition) {
-            Optional<String> id = extractIdFromVerb((VerbDefinition) 
definition);
-
-            if (id.isPresent()) {
-                return id.get();
-            }
-        }
-
-        return defaultNodeIdFactory.createId(definition);
-    }
-
-    /**
-     * Extract id from routes
-     */
-    private Optional<String> extractId(RouteDefinition routeDefinition) {
-        if (routeDefinition.getRestDefinition() != null) {
-            return Optional.empty();
-        }
-
-        if (routeDefinition.getInput() == null) {
-            return Optional.empty();
-        }
-
-        FromDefinition from = routeDefinition.getInput();
-        String uri = from.getEndpointUri();
-
-        // we want to use the context-path of the route
-        int colon = uri.indexOf(':');
-
-        if (colon > 0) {
-            String name = uri.substring(colon + 1);
-
-            int questionMark = name.indexOf('?');
-
-            if (questionMark > 0) {
-                return Optional.of(name.substring(0, questionMark));
-            } else {
-                return Optional.of(name);
-            }
-        }
-
-        return Optional.empty();
-    }
-
-    /**
-     * Extract id from a rest route.
-     */
-    private Optional<String> extractIdFromRestDefinition(RouteDefinition 
route) {
-        if (route.getRestDefinition() != null) {
-            return extractIdFromInput(route);
-        }
-
-        return Optional.empty();
-    }
-
-    /**
-     * Extract id from a rest verb definition.
-     */
-    private Optional<String> extractIdFromVerb(VerbDefinition verb) {
-        RestDefinition restDefinition = verb.getRest();
-
-        if (restDefinition != null) {
-            StringBuilder routeId = new StringBuilder();
-            routeId.append(verb.asVerb());
-            appendWithSeparator(routeId, prepareUri(restDefinition.getPath()));
-
-            if (verb.getPath() != null && verb.getPath().length() > 0) {
-                appendWithSeparator(routeId, prepareUri(verb.getPath()));
-            }
-
-            verb.setUsedForGeneratingNodeId(true);
-
-            return Optional.of(routeId.toString());
-        }
-
-        return Optional.empty();
-
-    }
-
-    /**
-     * Extract id from rest input uri.
-     */
-    private Optional<String> extractIdFromInput(RouteDefinition route) {
-        if (route.getInput() == null) {
-            return Optional.empty();
-        }
-
-        FromDefinition from = route.getInput();
-        String uri = from.getEndpointUri();
-
-        String[] uriSplitted = uri.split(":");
-
-        // needs to have at least 3 fields
-        if (uriSplitted.length < 3) {
-            return Optional.empty();
-        }
-
-        String verb = uriSplitted[1];
-        String contextPath = uriSplitted[2];
-        String additionalUri = "";
-
-        if (uriSplitted.length > 3 && uriSplitted[3].startsWith("/")) {
-            additionalUri = uriSplitted[3];
-        }
-
-        StringBuilder routeId = new StringBuilder(verb.length() + 
contextPath.length() + additionalUri.length());
-
-        routeId.append(verb);
-        appendWithSeparator(routeId, prepareUri(contextPath));
-
-        if (additionalUri.length() > 0) {
-            appendWithSeparator(routeId, prepareUri(additionalUri));
-        }
-
-        return Optional.of(routeId.toString());
-    }
-
-    /**
-     * Prepares uri to be part of the id.
-     */
-    private String prepareUri(String uri) {
-        if (uri == null) {
-            return "";
-        }
-
-        if (uri.contains("?")) {
-            uri = uri.substring(0, uri.indexOf('?'));
-        }
-
-        return uri.replace('/', SEPARATOR);
-    }
-
-    /**
-     * Appends new element to the builder.
-     */
-    private void appendWithSeparator(StringBuilder builder, String str) {
-        if (builder.charAt(builder.length() - 1) == SEPARATOR) {
-            if (str.startsWith(String.valueOf(SEPARATOR))) {
-                builder.append(str.replaceFirst(String.valueOf(SEPARATOR), 
""));
-            } else {
-                builder.append(str);
-            }
-        } else {
-            if (!str.startsWith(String.valueOf(SEPARATOR))) {
-                builder.append(SEPARATOR);
-            }
-
-            builder.append(str);
-        }
-    }
-}
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
index 1194d2c..efb178f 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
@@ -197,11 +197,8 @@ public final class RouteDefinitionHelper {
             RestDefinition rest = route.getRestDefinition();
             if (rest != null && route.isRest()) {
                 VerbDefinition verb = findVerbDefinition(rest, 
route.getInput().getEndpointUri());
-                if (verb != null) {
+                if (verb != null && verb.getRouteId() == null) {
                     String id = verb.idOrCreate(ecc.getNodeIdFactory());
-                    if (!verb.getUsedForGeneratingNodeId()) {
-                        id = route.getId();
-                    }
                     verb.setRouteId(id);
                 }
 
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
index cd4a187..d9b831e 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
@@ -103,8 +103,6 @@ public abstract class VerbDefinition extends 
OptionalIdentifiedDefinition<VerbDe
     private RouteDefinition route;
     @XmlTransient
     private RestDefinition rest;
-    @XmlTransient
-    private Boolean usedForGeneratingNodeId = Boolean.FALSE;
 
     @Override
     public String getShortName() {
@@ -462,11 +460,4 @@ public abstract class VerbDefinition extends 
OptionalIdentifiedDefinition<VerbDe
 
     public abstract String asVerb();
 
-    public Boolean getUsedForGeneratingNodeId() {
-        return usedForGeneratingNodeId;
-    }
-
-    public void setUsedForGeneratingNodeId(Boolean usedForGeneratingNodeId) {
-        this.usedForGeneratingNodeId = usedForGeneratingNodeId;
-    }
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/model/RouteIdFactoryTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/impl/model/RouteIdFactoryTest.java
deleted file mode 100644
index d5e9c6b..0000000
--- 
a/core/camel-core/src/test/java/org/apache/camel/impl/model/RouteIdFactoryTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.impl.model;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.ExtendedCamelContext;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.rest.DummyRestConsumerFactory;
-import org.apache.camel.component.rest.DummyRestProcessorFactory;
-import org.apache.camel.impl.RouteIdFactory;
-import org.apache.camel.spi.Registry;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class RouteIdFactoryTest extends ContextTestSupport {
-
-    @Override
-    protected Registry createRegistry() throws Exception {
-        Registry jndi = super.createRegistry();
-        jndi.bind("dummy-rest", new DummyRestConsumerFactory());
-        jndi.bind("dummy-rest-api", new DummyRestProcessorFactory());
-        return jndi;
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                context.adapt(ExtendedCamelContext.class).setNodeIdFactory(new 
RouteIdFactory());
-                from("direct:start1?timeout=30000").to("mock:result");
-                from("direct:start2").to("mock:result");
-                rest("/say/hello").get("/bar").to("mock:result");
-                rest("/say/hello").get().to("mock:result");
-                rest().get("/hello").to("mock:result");
-            }
-        };
-    }
-
-    @Test
-    public void testDirectRouteIdWithOptions() {
-        assertEquals("start1", context.getRouteDefinitions().get(0).getId());
-    }
-
-    @Test
-    public void testDirectRouteId() {
-        assertEquals("start2", context.getRouteDefinitions().get(1).getId());
-    }
-
-    @Test
-    public void testRestRouteIdWithVerbUri() {
-        assertEquals("get-say-hello-bar", 
context.getRouteDefinitions().get(2).getId());
-    }
-
-    @Test
-    public void testRestRouteIdWithoutVerbUri() {
-        assertEquals("get-say-hello", 
context.getRouteDefinitions().get(3).getId());
-    }
-
-    @Test
-    public void testRestRouteIdWithoutPathUri() {
-        assertEquals("get-hello", 
context.getRouteDefinitions().get(4).getId());
-    }
-
-}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc
index 5c32eda..8ac2aa2 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_16.adoc
@@ -15,6 +15,8 @@ Previously when Camel detected a duplicate type converter 
during startup, Camel
 override the existing converter and log a WARN. A more correct behaviour would 
be
 to keep the existing and ignore the duplicate.
 
+Removed the deprecated class `org.apache.camel.impl.RouteIdFactory`.
+
 ==== Rest DSL
 
 The generic verb-based definition, where the HTTP verb can be specified as a 
string value

Reply via email to