You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/12/07 11:50:04 UTC

[camel] branch camel-2.23.x updated (b0b2c1e -> 2717575)

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

acosentino pushed a change to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from b0b2c1e  CAMEL-12979 - support for service beans with custom lifecycle on CxfRsEndpoint, Thanks to Jens Kleine-Herzbruch
     new 76bece6  CAMEL-12978 - Add support to configure CamelContext created by KIE-Server extension
     new e908acd  CAMEL-12978 - Fixed CS
     new 2717575  Regen

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel-cxf/src/main/docs/cxfrs-component.adoc   |   3 +-
 .../apache/camel/component/jbpm/JBPMConstants.java |   2 +
 .../component/jbpm/config/CamelContextBuilder.java |  17 +-
 .../jbpm/server/CamelKieServerExtension.java       |  69 +++++++-
 .../jbpm/server/CamelKieServerExtensionTest.java   | 197 +++++++++++++++++++++
 .../camel-jbpm/src/test/resources/camel-routes.xml |  10 +-
 .../src/test/resources/global-camel-routes.xml     |  10 +-
 .../camel-nsq/src/main/docs/nsq-component.adoc     |   6 +-
 8 files changed, 291 insertions(+), 23 deletions(-)
 copy camel-core/src/main/java/org/apache/camel/spi/HasCamelContext.java => components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/config/CamelContextBuilder.java (64%)
 create mode 100644 components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
 copy camel-core/src/test/resources/org/apache/camel/model/convertBody.xml => components/camel-jbpm/src/test/resources/camel-routes.xml (77%)
 copy camel-core/src/test/resources/org/apache/camel/model/convertBody.xml => components/camel-jbpm/src/test/resources/global-camel-routes.xml (77%)


[camel] 01/03: CAMEL-12978 - Add support to configure CamelContext created by KIE-Server extension

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 76bece6ceacf1c796ea523807278067651463fd2
Author: Maciej Swiderski <sw...@gmail.com>
AuthorDate: Wed Dec 5 12:41:59 2018 +0100

    CAMEL-12978 - Add support to configure CamelContext created by KIE-Server extension
---
 .../apache/camel/component/jbpm/JBPMConstants.java |   2 +
 .../component/jbpm/config/CamelContextBuilder.java |  35 ++++
 .../jbpm/server/CamelKieServerExtension.java       |  73 +++++++-
 .../jbpm/server/CamelKieServerExtensionTest.java   | 197 +++++++++++++++++++++
 .../camel-jbpm/src/test/resources/camel-routes.xml |   7 +
 .../src/test/resources/global-camel-routes.xml     |   7 +
 6 files changed, 316 insertions(+), 5 deletions(-)

diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
index 94ff0ca..b984ebf 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
@@ -49,6 +49,8 @@ public interface JBPMConstants {
     String CAMEL_ENDPOINT_ID_WI_PARAM = "CamelEndpointId";
     String RESPONSE_WI_PARAM = "Response";
     String MESSAGE_WI_PARAM = "Message";
+    
+    String CAMEL_CONTEXT_BUILDER_KEY = "CamelContextBuilder";
 
     
 }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/config/CamelContextBuilder.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/config/CamelContextBuilder.java
new file mode 100644
index 0000000..badac07
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/config/CamelContextBuilder.java
@@ -0,0 +1,35 @@
+/**
+ * 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.jbpm.config;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * Allows to specify alternative configuration for CamelContext
+ */
+public interface CamelContextBuilder {
+
+    /**
+     * Default implementation that allows to simply return <code>DefaultCamelContext</code> instance
+     * @return returns <code>DefaultCamelContext</code> instance
+     */
+    default CamelContext buildCamelContext() {
+        
+        return new DefaultCamelContext();
+    }
+}
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
index 1783b04..f338aed 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
@@ -19,15 +19,21 @@ package org.apache.camel.component.jbpm.server;
 import java.io.InputStream;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceLoader;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.component.jbpm.JBPMConstants;
+import org.apache.camel.component.jbpm.config.CamelContextBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
 import org.jbpm.services.api.service.ServiceRegistry;
+import org.kie.internal.runtime.manager.InternalRuntimeManager;
+import org.kie.internal.runtime.manager.RuntimeManagerRegistry;
 import org.kie.server.services.api.KieContainerInstance;
 import org.kie.server.services.api.KieServerExtension;
 import org.kie.server.services.api.KieServerRegistry;
@@ -48,14 +54,29 @@ public class CamelKieServerExtension implements KieServerExtension {
     protected boolean managedCamel;
 
     protected Map<String, DefaultCamelContext> camelContexts = new HashMap<>();
+    
+    protected CamelContextBuilder camelContextBuilder;
 
     public CamelKieServerExtension() {
         this.managedCamel = true;
+        this.camelContextBuilder = discoverCamelContextBuilder();
+    }
+    
+    public CamelKieServerExtension(CamelContextBuilder camelContextBuilder) {
+        this.managedCamel = true;
+        this.camelContextBuilder = camelContextBuilder;
     }
 
     public CamelKieServerExtension(DefaultCamelContext camelContext) {
         this.camelContext = camelContext;
         this.managedCamel = false;
+        this.camelContextBuilder = discoverCamelContextBuilder();
+    }
+
+    public CamelKieServerExtension(DefaultCamelContext camelContext, CamelContextBuilder camelContextBuilder) {
+        this.camelContext = camelContext;
+        this.managedCamel = false;
+        this.camelContextBuilder = camelContextBuilder;
     }
 
     @Override
@@ -71,7 +92,7 @@ public class CamelKieServerExtension implements KieServerExtension {
     @Override
     public void init(KieServerImpl kieServer, KieServerRegistry registry) {
         if (this.managedCamel && this.camelContext == null) {
-            this.camelContext = new DefaultCamelContext();
+            this.camelContext = (DefaultCamelContext) buildGlobalContext();
             this.camelContext.setName("KIE Server Camel context");
 
             try (InputStream is = this.getClass().getResourceAsStream("/global-camel-routes.xml")) {
@@ -108,7 +129,7 @@ public class CamelKieServerExtension implements KieServerExtension {
         try (InputStream is = classloader.getResourceAsStream("camel-routes.xml")) {
             if (is != null) {
 
-                DefaultCamelContext context = new DefaultCamelContext();
+                DefaultCamelContext context = (DefaultCamelContext) buildDeploymentContext(id);
                 context.setName("KIE Server Camel context for container " + kieContainerInstance.getContainerId());
 
                 RoutesDefinition routes = context.loadRoutesDefinition(is);
@@ -196,6 +217,14 @@ public class CamelKieServerExtension implements KieServerExtension {
     public String toString() {
         return EXTENSION_NAME + " KIE Server extension";
     }
+    
+    public DefaultCamelContext getCamelContext() {
+        return camelContext;
+    }
+    
+    public CamelContextBuilder getCamelContextBuilder() {
+        return camelContextBuilder;
+    }
 
     protected void annotateKJarRoutes(RoutesDefinition routes, String deploymentId) {
         for (RouteDefinition route : routes.getRoutes()) {
@@ -215,10 +244,44 @@ public class CamelKieServerExtension implements KieServerExtension {
                     }
                     uri.append("deploymentId=").append(deploymentId);
                     from.setUri(uri.toString());
-                }
-
-                System.out.println(from.getUri());
+                }                
             }
         }
     }
+    
+    protected CamelContext buildGlobalContext() {
+        if (camelContextBuilder != null) {
+            return camelContextBuilder.buildCamelContext();
+        }
+        
+        return new CamelContextBuilder(){}.buildCamelContext();
+    }
+    
+    protected CamelContext buildDeploymentContext(String identifier) {
+        
+        InternalRuntimeManager runtimeManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(identifier);
+        
+        if (runtimeManager != null) {
+            
+            CamelContextBuilder deploymentContextBuilder = (CamelContextBuilder) runtimeManager.getEnvironment()
+                                                                                        .getEnvironment()
+                                                                                        .get(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY);
+            if (deploymentContextBuilder != null) {
+                return deploymentContextBuilder.buildCamelContext();
+            }
+        }
+        
+        return new CamelContextBuilder(){}.buildCamelContext();
+    }
+    
+    protected CamelContextBuilder discoverCamelContextBuilder() {
+        
+        ServiceLoader<CamelContextBuilder> builders = ServiceLoader.load(CamelContextBuilder.class);
+        Iterator<CamelContextBuilder> it = builders.iterator();
+        if (it.hasNext()) {
+            return it.next();
+        }
+        
+        return null;
+    }
 }
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
new file mode 100644
index 0000000..fbbb7ed
--- /dev/null
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
@@ -0,0 +1,197 @@
+/**
+ * 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.jbpm.server;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.when;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.jbpm.JBPMConstants;
+import org.apache.camel.component.jbpm.config.CamelContextBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.kie.api.KieServices;
+import org.kie.api.runtime.Environment;
+import org.kie.api.runtime.KieContainer;
+import org.kie.internal.runtime.manager.InternalRuntimeManager;
+import org.kie.internal.runtime.manager.RuntimeEnvironment;
+import org.kie.internal.runtime.manager.RuntimeManagerRegistry;
+import org.kie.server.services.api.KieContainerInstance;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CamelKieServerExtensionTest {
+    
+    private String identifier = "test";
+    
+    @Mock
+    InternalRuntimeManager runtimeManager;
+    
+    @Mock
+    RuntimeEnvironment runtimeEnvironment;
+
+    @Mock
+    private KieContainerInstance kieContainerInstance;
+    
+    @Mock
+    private KieContainer kieContainer;
+
+    @After
+    public void cleanup() {
+        RuntimeManagerRegistry.get().remove(identifier);
+    }
+    
+    
+    @Test
+    public void testInit() {
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        extension.init(null, null);
+        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+        List<RouteDefinition> globalRestDefinitions = globalCamelContext.getRouteDefinitions();
+        assertThat(globalRestDefinitions.size(), equalTo(1));
+        assertThat(globalCamelContext.getRouteDefinition("unitTestRoute"), is(notNullValue()));
+    }
+    
+    @Test
+    public void testCreateContainer() {
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        final String containerId = "testContainer";
+        
+        when(kieContainerInstance.getKieContainer()).thenReturn(kieContainer);
+        when(kieContainer.getClassLoader()).thenReturn(this.getClass().getClassLoader());
+        
+        extension.createContainer(containerId, kieContainerInstance, new HashMap<String, Object>());
+        
+        CamelContext camelContext = (CamelContext) ServiceRegistry.get().service("testContainer" + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX);
+        List<RouteDefinition> restDefinitions = camelContext.getRouteDefinitions();
+        assertThat(restDefinitions.size(), equalTo(1));
+        
+        assertThat(camelContext.getRoute("unitTestRoute"), is(notNullValue()));
+    }
+    
+    @Test
+    public void testDefaultSetup() {
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        
+        assertNull(extension.getCamelContextBuilder());
+    }
+    
+    @Test
+    public void testDefaultSetupCustomDiscovery() {
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension() {
+
+            @Override
+            protected CamelContextBuilder discoverCamelContextBuilder() {
+                return new CamelContextBuilder() {
+
+                    @Override
+                    public CamelContext buildCamelContext() {
+                        // for test purpose return simply null as camel context
+                        return null;
+                    }
+                    
+                };
+            }
+            
+        };
+        
+        assertNotNull(extension.getCamelContextBuilder());
+        assertNull(extension.getCamelContextBuilder().buildCamelContext());
+    }
+    
+    @Test
+    public void testBuildGlobalCamelContext() throws Exception {
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        CamelContext context = extension.buildGlobalContext();
+        assertNotNull(context);
+        
+        context.stop();
+    }
+    
+    @Test
+    public void testBuildGlobalCamelContextCustomBuilder() throws Exception {
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension(new CamelContextBuilder() {
+
+            @Override
+            public CamelContext buildCamelContext() {
+                // for test purpose return simply null as camel context
+                return null;
+            }
+            
+        });
+        CamelContext context = extension.buildGlobalContext();
+        assertNull(context);        
+    }
+    
+    @Test
+    public void testBuildDeploymentCamelContext() throws Exception {
+        
+        when(runtimeManager.getIdentifier()).thenReturn(identifier);
+        when(runtimeManager.getEnvironment()).thenReturn(runtimeEnvironment);
+        
+        Environment environment = KieServices.get().newEnvironment();
+        when(runtimeEnvironment.getEnvironment()).thenReturn(environment);
+        
+        RuntimeManagerRegistry.get().register(runtimeManager);
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        CamelContext context = extension.buildDeploymentContext(identifier);
+        assertNotNull(context);
+        
+        context.stop();
+    }
+    
+    @Test
+    public void testBuildDeploymentCamelContextCustomBuilder() throws Exception {
+        
+        when(runtimeManager.getIdentifier()).thenReturn(identifier);
+        when(runtimeManager.getEnvironment()).thenReturn(runtimeEnvironment);
+        
+        Environment environment = KieServices.get().newEnvironment();
+        environment.set(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY, new CamelContextBuilder() {
+
+            @Override
+            public CamelContext buildCamelContext() {
+                // for test purpose return simply null as camel context
+                return null;
+            }
+            
+        });
+        when(runtimeEnvironment.getEnvironment()).thenReturn(environment);
+        
+        RuntimeManagerRegistry.get().register(runtimeManager);
+        
+        CamelKieServerExtension extension = new CamelKieServerExtension();
+        CamelContext context = extension.buildDeploymentContext(identifier);
+        assertNull(context);
+        
+    }
+}
diff --git a/components/camel-jbpm/src/test/resources/camel-routes.xml b/components/camel-jbpm/src/test/resources/camel-routes.xml
new file mode 100644
index 0000000..710d40a
--- /dev/null
+++ b/components/camel-jbpm/src/test/resources/camel-routes.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<routes id="routes-c6e723e3-4841-48cd-aefe-dfd8cada3e7e" xmlns="http://camel.apache.org/schema/spring">
+  <route id="unitTestRoute">
+    <from id="direct-unitTestRoute" uri="direct:unitTest" />
+    <to uri="log:org.apache.camel.com?level=WARN" />
+  </route>
+</routes>
\ No newline at end of file
diff --git a/components/camel-jbpm/src/test/resources/global-camel-routes.xml b/components/camel-jbpm/src/test/resources/global-camel-routes.xml
new file mode 100644
index 0000000..710d40a
--- /dev/null
+++ b/components/camel-jbpm/src/test/resources/global-camel-routes.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<routes id="routes-c6e723e3-4841-48cd-aefe-dfd8cada3e7e" xmlns="http://camel.apache.org/schema/spring">
+  <route id="unitTestRoute">
+    <from id="direct-unitTestRoute" uri="direct:unitTest" />
+    <to uri="log:org.apache.camel.com?level=WARN" />
+  </route>
+</routes>
\ No newline at end of file


[camel] 03/03: Regen

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 2717575337c7a81427bf45aa52521e06ee4f306d
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Dec 7 12:48:42 2018 +0100

    Regen
---
 components/camel-cxf/src/main/docs/cxfrs-component.adoc | 3 ++-
 components/camel-nsq/src/main/docs/nsq-component.adoc   | 6 ++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/components/camel-cxf/src/main/docs/cxfrs-component.adoc b/components/camel-cxf/src/main/docs/cxfrs-component.adoc
index 0bfdfa9..34a4e4e 100644
--- a/components/camel-cxf/src/main/docs/cxfrs-component.adoc
+++ b/components/camel-cxf/src/main/docs/cxfrs-component.adoc
@@ -91,7 +91,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (29 parameters):
+==== Query Parameters (30 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -110,6 +110,7 @@ with the following path and query parameters:
 | *publishedEndpointUrl* (consumer) | This option can override the endpointUrl that published from the WADL which can be accessed with resource address url plus _wadl |  | String
 | *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
+| *serviceBeans* (consumer) | The service beans which you want to export as REST service. Multiple beans can be separated by comma. |  | List
 | *cookieHandler* (producer) | Configure a cookie handler to maintain a HTTP session |  | CookieHandler
 | *hostnameVerifier* (producer) | The hostname verifier to be used. Use the # notation to reference a HostnameVerifier from the registry. |  | HostnameVerifier
 | *sslContextParameters* (producer) | The Camel SSL setting reference. Use the # notation to reference the SSL Context. |  | SSLContextParameters
diff --git a/components/camel-nsq/src/main/docs/nsq-component.adoc b/components/camel-nsq/src/main/docs/nsq-component.adoc
index 7f81b7b..ef4336b 100644
--- a/components/camel-nsq/src/main/docs/nsq-component.adoc
+++ b/components/camel-nsq/src/main/docs/nsq-component.adoc
@@ -1,6 +1,8 @@
+[[nsq-component]]
 == NSQ Component
 
-*Available as of Camel version 2.22*
+*Available as of Camel version 2.23*
+
 *Available as of Camel version 2.23*
 
 
@@ -107,4 +109,4 @@ The component supports 3 options, which are listed below.
 | *camel.component.nsq.resolve-property-placeholders* | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean
 | *camel.component.nsq.use-global-ssl-context-parameters* | Enable usage of global SSL context parameters. | false | Boolean
 |===
-// spring-boot-auto-configure options: END
+// spring-boot-auto-configure options: END
\ No newline at end of file


[camel] 02/03: CAMEL-12978 - Fixed CS

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e908acd946e0f6a844f656fa269fe46b05a8f910
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Dec 7 12:28:21 2018 +0100

    CAMEL-12978 - Fixed CS
---
 .../jbpm/server/CamelKieServerExtension.java       | 46 +++++------
 .../jbpm/server/CamelKieServerExtensionTest.java   | 96 +++++++++++-----------
 .../camel-jbpm/src/test/resources/camel-routes.xml | 18 ++++
 .../src/test/resources/global-camel-routes.xml     | 18 ++++
 4 files changed, 107 insertions(+), 71 deletions(-)

diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
index f338aed..607867e 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
@@ -54,14 +54,14 @@ public class CamelKieServerExtension implements KieServerExtension {
     protected boolean managedCamel;
 
     protected Map<String, DefaultCamelContext> camelContexts = new HashMap<>();
-    
+
     protected CamelContextBuilder camelContextBuilder;
 
     public CamelKieServerExtension() {
         this.managedCamel = true;
         this.camelContextBuilder = discoverCamelContextBuilder();
     }
-    
+
     public CamelKieServerExtension(CamelContextBuilder camelContextBuilder) {
         this.managedCamel = true;
         this.camelContextBuilder = camelContextBuilder;
@@ -92,7 +92,7 @@ public class CamelKieServerExtension implements KieServerExtension {
     @Override
     public void init(KieServerImpl kieServer, KieServerRegistry registry) {
         if (this.managedCamel && this.camelContext == null) {
-            this.camelContext = (DefaultCamelContext) buildGlobalContext();
+            this.camelContext = (DefaultCamelContext)buildGlobalContext();
             this.camelContext.setName("KIE Server Camel context");
 
             try (InputStream is = this.getClass().getResourceAsStream("/global-camel-routes.xml")) {
@@ -129,7 +129,7 @@ public class CamelKieServerExtension implements KieServerExtension {
         try (InputStream is = classloader.getResourceAsStream("camel-routes.xml")) {
             if (is != null) {
 
-                DefaultCamelContext context = (DefaultCamelContext) buildDeploymentContext(id);
+                DefaultCamelContext context = (DefaultCamelContext)buildDeploymentContext(id);
                 context.setName("KIE Server Camel context for container " + kieContainerInstance.getContainerId());
 
                 RoutesDefinition routes = context.loadRoutesDefinition(is);
@@ -217,11 +217,11 @@ public class CamelKieServerExtension implements KieServerExtension {
     public String toString() {
         return EXTENSION_NAME + " KIE Server extension";
     }
-    
+
     public DefaultCamelContext getCamelContext() {
         return camelContext;
     }
-    
+
     public CamelContextBuilder getCamelContextBuilder() {
         return camelContextBuilder;
     }
@@ -244,44 +244,44 @@ public class CamelKieServerExtension implements KieServerExtension {
                     }
                     uri.append("deploymentId=").append(deploymentId);
                     from.setUri(uri.toString());
-                }                
+                }
             }
         }
     }
-    
+
     protected CamelContext buildGlobalContext() {
         if (camelContextBuilder != null) {
             return camelContextBuilder.buildCamelContext();
         }
-        
-        return new CamelContextBuilder(){}.buildCamelContext();
+
+        return new CamelContextBuilder() {
+        }.buildCamelContext();
     }
-    
+
     protected CamelContext buildDeploymentContext(String identifier) {
-        
-        InternalRuntimeManager runtimeManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(identifier);
-        
+
+        InternalRuntimeManager runtimeManager = (InternalRuntimeManager)RuntimeManagerRegistry.get().getManager(identifier);
+
         if (runtimeManager != null) {
-            
-            CamelContextBuilder deploymentContextBuilder = (CamelContextBuilder) runtimeManager.getEnvironment()
-                                                                                        .getEnvironment()
-                                                                                        .get(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY);
+
+            CamelContextBuilder deploymentContextBuilder = (CamelContextBuilder)runtimeManager.getEnvironment().getEnvironment().get(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY);
             if (deploymentContextBuilder != null) {
                 return deploymentContextBuilder.buildCamelContext();
             }
         }
-        
-        return new CamelContextBuilder(){}.buildCamelContext();
+
+        return new CamelContextBuilder() {
+        }.buildCamelContext();
     }
-    
+
     protected CamelContextBuilder discoverCamelContextBuilder() {
-        
+
         ServiceLoader<CamelContextBuilder> builders = ServiceLoader.load(CamelContextBuilder.class);
         Iterator<CamelContextBuilder> it = builders.iterator();
         if (it.hasNext()) {
             return it.next();
         }
-        
+
         return null;
     }
 }
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
index fbbb7ed..596f05e 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/server/CamelKieServerExtensionTest.java
@@ -16,12 +16,6 @@
  */
 package org.apache.camel.component.jbpm.server;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.when;
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
-
 import java.util.HashMap;
 import java.util.List;
 
@@ -43,67 +37,73 @@ import org.kie.server.services.api.KieContainerInstance;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.when;
+
 @RunWith(MockitoJUnitRunner.class)
 public class CamelKieServerExtensionTest {
-    
-    private String identifier = "test";
-    
     @Mock
     InternalRuntimeManager runtimeManager;
-    
+
     @Mock
     RuntimeEnvironment runtimeEnvironment;
 
     @Mock
     private KieContainerInstance kieContainerInstance;
-    
+
     @Mock
     private KieContainer kieContainer;
+    
+    private String identifier = "test";
 
     @After
     public void cleanup() {
         RuntimeManagerRegistry.get().remove(identifier);
     }
-    
-    
+
     @Test
     public void testInit() {
         CamelKieServerExtension extension = new CamelKieServerExtension();
         extension.init(null, null);
-        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+        CamelContext globalCamelContext = (CamelContext)ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
         List<RouteDefinition> globalRestDefinitions = globalCamelContext.getRouteDefinitions();
         assertThat(globalRestDefinitions.size(), equalTo(1));
         assertThat(globalCamelContext.getRouteDefinition("unitTestRoute"), is(notNullValue()));
     }
-    
+
     @Test
     public void testCreateContainer() {
         CamelKieServerExtension extension = new CamelKieServerExtension();
         final String containerId = "testContainer";
-        
+
         when(kieContainerInstance.getKieContainer()).thenReturn(kieContainer);
         when(kieContainer.getClassLoader()).thenReturn(this.getClass().getClassLoader());
-        
+
         extension.createContainer(containerId, kieContainerInstance, new HashMap<String, Object>());
-        
-        CamelContext camelContext = (CamelContext) ServiceRegistry.get().service("testContainer" + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX);
+
+        CamelContext camelContext = (CamelContext)ServiceRegistry.get().service("testContainer" + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX);
         List<RouteDefinition> restDefinitions = camelContext.getRouteDefinitions();
         assertThat(restDefinitions.size(), equalTo(1));
-        
+
         assertThat(camelContext.getRoute("unitTestRoute"), is(notNullValue()));
     }
-    
+
     @Test
     public void testDefaultSetup() {
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension();
-        
+
         assertNull(extension.getCamelContextBuilder());
     }
-    
+
     @Test
     public void testDefaultSetupCustomDiscovery() {
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension() {
 
             @Override
@@ -115,29 +115,29 @@ public class CamelKieServerExtensionTest {
                         // for test purpose return simply null as camel context
                         return null;
                     }
-                    
+
                 };
             }
-            
+
         };
-        
+
         assertNotNull(extension.getCamelContextBuilder());
         assertNull(extension.getCamelContextBuilder().buildCamelContext());
     }
-    
+
     @Test
     public void testBuildGlobalCamelContext() throws Exception {
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension();
         CamelContext context = extension.buildGlobalContext();
         assertNotNull(context);
-        
+
         context.stop();
     }
-    
+
     @Test
     public void testBuildGlobalCamelContextCustomBuilder() throws Exception {
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension(new CamelContextBuilder() {
 
             @Override
@@ -145,36 +145,36 @@ public class CamelKieServerExtensionTest {
                 // for test purpose return simply null as camel context
                 return null;
             }
-            
+
         });
         CamelContext context = extension.buildGlobalContext();
-        assertNull(context);        
+        assertNull(context);
     }
-    
+
     @Test
     public void testBuildDeploymentCamelContext() throws Exception {
-        
+
         when(runtimeManager.getIdentifier()).thenReturn(identifier);
         when(runtimeManager.getEnvironment()).thenReturn(runtimeEnvironment);
-        
+
         Environment environment = KieServices.get().newEnvironment();
         when(runtimeEnvironment.getEnvironment()).thenReturn(environment);
-        
+
         RuntimeManagerRegistry.get().register(runtimeManager);
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension();
         CamelContext context = extension.buildDeploymentContext(identifier);
         assertNotNull(context);
-        
+
         context.stop();
     }
-    
+
     @Test
     public void testBuildDeploymentCamelContextCustomBuilder() throws Exception {
-        
+
         when(runtimeManager.getIdentifier()).thenReturn(identifier);
         when(runtimeManager.getEnvironment()).thenReturn(runtimeEnvironment);
-        
+
         Environment environment = KieServices.get().newEnvironment();
         environment.set(JBPMConstants.CAMEL_CONTEXT_BUILDER_KEY, new CamelContextBuilder() {
 
@@ -183,15 +183,15 @@ public class CamelKieServerExtensionTest {
                 // for test purpose return simply null as camel context
                 return null;
             }
-            
+
         });
         when(runtimeEnvironment.getEnvironment()).thenReturn(environment);
-        
+
         RuntimeManagerRegistry.get().register(runtimeManager);
-        
+
         CamelKieServerExtension extension = new CamelKieServerExtension();
         CamelContext context = extension.buildDeploymentContext(identifier);
         assertNull(context);
-        
+
     }
 }
diff --git a/components/camel-jbpm/src/test/resources/camel-routes.xml b/components/camel-jbpm/src/test/resources/camel-routes.xml
index 710d40a..d4ff17d 100644
--- a/components/camel-jbpm/src/test/resources/camel-routes.xml
+++ b/components/camel-jbpm/src/test/resources/camel-routes.xml
@@ -1,4 +1,22 @@
 <?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.
+
+-->
 <routes id="routes-c6e723e3-4841-48cd-aefe-dfd8cada3e7e" xmlns="http://camel.apache.org/schema/spring">
   <route id="unitTestRoute">
     <from id="direct-unitTestRoute" uri="direct:unitTest" />
diff --git a/components/camel-jbpm/src/test/resources/global-camel-routes.xml b/components/camel-jbpm/src/test/resources/global-camel-routes.xml
index 710d40a..d4ff17d 100644
--- a/components/camel-jbpm/src/test/resources/global-camel-routes.xml
+++ b/components/camel-jbpm/src/test/resources/global-camel-routes.xml
@@ -1,4 +1,22 @@
 <?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.
+
+-->
 <routes id="routes-c6e723e3-4841-48cd-aefe-dfd8cada3e7e" xmlns="http://camel.apache.org/schema/spring">
   <route id="unitTestRoute">
     <from id="direct-unitTestRoute" uri="direct:unitTest" />