camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [camel] branch master updated: [CAMEL-13385] Move the rest registry to the rest component
Date Mon, 08 Apr 2019 08:57:33 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new c27abb9  [CAMEL-13385] Move the rest registry to the rest component
c27abb9 is described below

commit c27abb9fb02ab1b24ed438d466f3d10f27ff965d
Author: Guillaume Nodet <gnodet@gmail.com>
AuthorDate: Mon Apr 1 13:29:00 2019 +0200

    [CAMEL-13385] Move the rest registry to the rest component
---
 .../camel/component/rest}/DefaultRestRegistry.java |  4 +-
 .../component/rest/DefaultRestRegistryFactory.java | 29 +++++++++
 .../org/apache/camel/rest-registry-factory         | 19 ++++++
 .../org/apache/camel/spi/RestRegistryFactory.java  | 29 +++++++++
 .../org/apache/camel/impl/DefaultCamelContext.java |  2 +-
 .../camel/impl/RestRegistryFactoryResolver.java    | 74 ++++++++++++++++++++++
 6 files changed, 153 insertions(+), 4 deletions(-)

diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistry.java
similarity index 98%
rename from core/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
rename to components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistry.java
index 2b3f33c..848806f 100644
--- a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultRestRegistry.java
+++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistry.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.impl;
+package org.apache.camel.component.rest;
 
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
@@ -33,8 +33,6 @@ import org.apache.camel.Service;
 import org.apache.camel.ServiceStatus;
 import org.apache.camel.StatefulService;
 import org.apache.camel.StaticService;
-import org.apache.camel.component.rest.RestApiEndpoint;
-import org.apache.camel.component.rest.RestEndpoint;
 import org.apache.camel.spi.RestConfiguration;
 import org.apache.camel.spi.RestRegistry;
 import org.apache.camel.support.LifecycleStrategySupport;
diff --git a/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistryFactory.java
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistryFactory.java
new file mode 100644
index 0000000..b85efae
--- /dev/null
+++ b/components/camel-rest/src/main/java/org/apache/camel/component/rest/DefaultRestRegistryFactory.java
@@ -0,0 +1,29 @@
+/*
+ * 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.rest;
+
+import org.apache.camel.spi.RestRegistry;
+import org.apache.camel.spi.RestRegistryFactory;
+
+public class DefaultRestRegistryFactory implements RestRegistryFactory {
+
+    @Override
+    public RestRegistry createRegistry() {
+        return new DefaultRestRegistry();
+    }
+
+}
diff --git a/components/camel-rest/src/main/resources/META-INF/services/org/apache/camel/rest-registry-factory
b/components/camel-rest/src/main/resources/META-INF/services/org/apache/camel/rest-registry-factory
new file mode 100644
index 0000000..2ec9069
--- /dev/null
+++ b/components/camel-rest/src/main/resources/META-INF/services/org/apache/camel/rest-registry-factory
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.rest.DefaultRestRegistryFactory
+
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/RestRegistryFactory.java b/core/camel-api/src/main/java/org/apache/camel/spi/RestRegistryFactory.java
new file mode 100644
index 0000000..1f12319
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/RestRegistryFactory.java
@@ -0,0 +1,29 @@
+/*
+ * 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.spi;
+
+/**
+ * A factory for {@link RestRegistry}.
+ */
+public interface RestRegistryFactory {
+
+    /**
+     * Create a new {@link RestRegistry}.
+     */
+    RestRegistry createRegistry();
+
+}
diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 3ebe193..4c64ba9 100644
--- a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -282,7 +282,7 @@ public class DefaultCamelContext extends AbstractCamelContext {
 
     @Override
     protected RestRegistry createRestRegistry() {
-        return new DefaultRestRegistry();
+        return new RestRegistryFactoryResolver().resolve(this).createRegistry();
     }
 
     protected EndpointRegistry<EndpointKey> createEndpointRegistry(Map<EndpointKey,
Endpoint> endpoints) {
diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/RestRegistryFactoryResolver.java
b/core/camel-core/src/main/java/org/apache/camel/impl/RestRegistryFactoryResolver.java
new file mode 100644
index 0000000..f61b3b2
--- /dev/null
+++ b/core/camel-core/src/main/java/org/apache/camel/impl/RestRegistryFactoryResolver.java
@@ -0,0 +1,74 @@
+/*
+ * 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.io.IOException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.FactoryFinder;
+import org.apache.camel.spi.HeadersMapFactory;
+import org.apache.camel.spi.RestRegistryFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Factory to create the {@link RestRegistryFactory} implementation to be used.
+ *
+ * @see RestRegistryFactory
+ */
+public class RestRegistryFactoryResolver {
+
+    public static final String RESOURCE_PATH = "META-INF/services/org/apache/camel/";
+
+    private static final Logger LOG = LoggerFactory.getLogger(RestRegistryFactoryResolver.class);
+
+    private FactoryFinder factoryFinder;
+
+    public RestRegistryFactory resolve(CamelContext context) {
+        // use factory finder to find a custom implementations
+        Class<?> type = null;
+        try {
+            type = findFactory("rest-registry-factory", context);
+        } catch (Exception e) {
+            // ignore
+        }
+
+        if (type != null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Found RestRegistryFactory: {} via: {}{}", type.getName(), factoryFinder.getResourcePath(),
"headers-map-factory");
+            }
+            if (RestRegistryFactory.class.isAssignableFrom(type)) {
+                RestRegistryFactory answer = (RestRegistryFactory) context.getInjector().newInstance(type);
+                LOG.info("Detected and using custom RestRegistryFactory: {}", answer);
+                return answer;
+            } else {
+                throw new IllegalArgumentException("Type is not a RestRegistryFactory implementation.
Found: " + type.getName());
+            }
+        }
+
+        throw new IllegalArgumentException("No RestRegistryFactory implementation found.
 You need to add camel-rest to the classpath.");
+    }
+
+    private Class<?> findFactory(String name, CamelContext context) throws ClassNotFoundException,
IOException {
+        if (factoryFinder == null) {
+            factoryFinder = context.getFactoryFinder(RESOURCE_PATH);
+        }
+        return factoryFinder.findClass(name);
+    }
+
+}
+


Mime
View raw message