Repository: incubator-unomi Updated Branches: refs/heads/master 79ba27236 -> b190a4f77
UNOMI-128 : Refactoring save/update/delete running import/export config Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/b190a4f7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/b190a4f7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/b190a4f7 Branch: refs/heads/master Commit: b190a4f7712d3c44fea74bdfb8eec44a88c295f8 Parents: 79ba272 Author: Abdelkader Midani <[email protected]> Authored: Wed Oct 18 19:35:37 2017 +0200 Committer: Abdelkader Midani <[email protected]> Committed: Wed Oct 18 19:36:08 2017 +0200 ---------------------------------------------------------------------- buildAndRun.sh | 2 +- buildAndRunNoTests.sh | 2 +- .../unomi/router/api/IRouterCamelContext.java | 27 +++++++ .../ImportExportConfigurationService.java | 16 +++- extensions/router/router-core/pom.xml | 6 -- .../router/core/context/RouterCamelContext.java | 24 +++--- .../core/processor/ConfigDeleteProcessor.java | 43 ----------- .../core/processor/ConfigUpdateProcessor.java | 43 ----------- .../core/route/ConfigUpdateRouteBuilder.java | 80 -------------------- .../resources/OSGI-INF/blueprint/blueprint.xml | 19 ----- .../AbstractConfigurationServiceEndpoint.java | 4 +- .../ExportConfigurationServiceEndPoint.java | 66 +--------------- .../ImportConfigurationServiceEndPoint.java | 66 +--------------- extensions/router/router-service/pom.xml | 5 -- .../AbstractConfigurationServiceImpl.java | 8 +- .../ExportConfigurationServiceImpl.java | 16 ++++ .../ImportConfigurationServiceImpl.java | 18 +++++ 17 files changed, 99 insertions(+), 346 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/buildAndRun.sh ---------------------------------------------------------------------- diff --git a/buildAndRun.sh b/buildAndRun.sh index e7128f9..69106f4 100755 --- a/buildAndRun.sh +++ b/buildAndRun.sh @@ -32,7 +32,7 @@ pushd package/target echo Uncompressing Unomi package... tar zxvf unomi-$UNOMI_VERSION.tar.gz cd unomi-$UNOMI_VERSION/bin -echo Starting Unomi... +echo Apache Unomi features installed, use [unomi:start] to start it. ./karaf debug popd http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/buildAndRunNoTests.sh ---------------------------------------------------------------------- diff --git a/buildAndRunNoTests.sh b/buildAndRunNoTests.sh index 4bb0028..c948d4d 100755 --- a/buildAndRunNoTests.sh +++ b/buildAndRunNoTests.sh @@ -40,7 +40,7 @@ if [ -f "../../allCountries.zip" ]; then cp ../../allCountries.zip unomi-$UNOMI_VERSION/etc fi cd unomi-$UNOMI_VERSION/bin -echo Starting Unomi... +echo echo Apache Unomi features installed, use [unomi:start] to start it. ./karaf debug popd http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/IRouterCamelContext.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/IRouterCamelContext.java b/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/IRouterCamelContext.java new file mode 100644 index 0000000..d2d3249 --- /dev/null +++ b/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/IRouterCamelContext.java @@ -0,0 +1,27 @@ +/* + * 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.unomi.router.api; + +/** + * Created by amidani on 18/10/2017. + */ +public interface IRouterCamelContext { + + void killExistingRoute(String routeId) throws Exception; + + void updateProfileReaderRoute(Object configuration) throws Exception; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/services/ImportExportConfigurationService.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/services/ImportExportConfigurationService.java b/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/services/ImportExportConfigurationService.java index 7868b9c..7d2a82d 100644 --- a/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/services/ImportExportConfigurationService.java +++ b/extensions/router/router-api/src/main/java/org/apache/unomi/router/api/services/ImportExportConfigurationService.java @@ -17,6 +17,7 @@ package org.apache.unomi.router.api.services; import org.apache.unomi.router.api.ExportConfiguration; +import org.apache.unomi.router.api.IRouterCamelContext; import org.apache.unomi.router.api.ImportConfiguration; import java.util.List; @@ -31,7 +32,7 @@ public interface ImportExportConfigurationService<T> { * * @return the list of import/export configurations */ - public List<T> getAll(); + List<T> getAll(); /** * Retrieves the import/export configuration identified by the specified identifier. @@ -40,7 +41,7 @@ public interface ImportExportConfigurationService<T> { * @return the import/export configuration identified by the specified identifier or * {@code null} if no such import/export configuration exists */ - public T load(String configId); + T load(String configId); /** * Saves the specified import/export configuration in the context server. @@ -48,14 +49,21 @@ public interface ImportExportConfigurationService<T> { * @param configuration the import/export configuration to be saved * @return the newly saved import/export configuration */ - public T save(T configuration); + T save(T configuration); /** * Deletes the import/export configuration identified by the specified identifier. * * @param configId the identifier of the import/export configuration to delete */ - public void delete(String configId); + void delete(String configId); + + /** + * Set the router camel context to share + * + * @param routerCamelContext + */ + void setRouterCamelContext(IRouterCamelContext routerCamelContext); } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-core/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/router/router-core/pom.xml b/extensions/router/router-core/pom.xml index 1f86696..42e10dc 100644 --- a/extensions/router/router-core/pom.xml +++ b/extensions/router/router-core/pom.xml @@ -88,12 +88,6 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-servlet</artifactId> - <version>${camel.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> <artifactId>camel-ftp</artifactId> <version>${camel.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java index a8e0b81..3b18803 100644 --- a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java +++ b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java @@ -25,6 +25,7 @@ import org.apache.unomi.api.services.ConfigSharingService; import org.apache.unomi.api.services.ProfileService; import org.apache.unomi.persistence.spi.PersistenceService; import org.apache.unomi.router.api.ExportConfiguration; +import org.apache.unomi.router.api.IRouterCamelContext; import org.apache.unomi.router.api.ImportConfiguration; import org.apache.unomi.router.api.RouterConstants; import org.apache.unomi.router.api.services.ImportExportConfigurationService; @@ -43,12 +44,11 @@ import org.slf4j.LoggerFactory; import java.util.Arrays; import java.util.Map; -import java.util.concurrent.TimeUnit; /** * Created by amidani on 04/05/2017. */ -public class RouterCamelContext implements SynchronousBundleListener { +public class RouterCamelContext implements SynchronousBundleListener, IRouterCamelContext { private Logger logger = LoggerFactory.getLogger(RouterCamelContext.class.getName()); private CamelContext camelContext; @@ -155,24 +155,22 @@ public class RouterCamelContext implements SynchronousBundleListener { } } bundleContext.addBundleListener(this); - logger.info("Camel Context {} initialized successfully."); - } + importConfigurationService.setRouterCamelContext(this); + exportConfigurationService.setRouterCamelContext(this); + + logger.info("Camel Context {} initialized successfully."); - private boolean stopRoute(String routeId) throws Exception { - return camelContext.stopRoute(routeId, 10L, TimeUnit.SECONDS, true); } public void killExistingRoute(String routeId) throws Exception { //Active routes Route route = camelContext.getRoute(routeId); - if (route != null && stopRoute(routeId)) { - camelContext.removeRoute(routeId); - } - //Inactive routes - RouteDefinition routeDefinition = camelContext.getRouteDefinition(routeId); - if (routeDefinition != null) { - camelContext.removeRouteDefinition(routeDefinition); + if (route != null) { + RouteDefinition routeDefinition = camelContext.getRouteDefinition(routeId); + if (routeDefinition != null) { + camelContext.removeRouteDefinition(routeDefinition); + } } } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigDeleteProcessor.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigDeleteProcessor.java b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigDeleteProcessor.java deleted file mode 100644 index 1022113..0000000 --- a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigDeleteProcessor.java +++ /dev/null @@ -1,43 +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.unomi.router.core.processor; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.unomi.router.core.context.RouterCamelContext; - -/** - * Created by amidani on 03/10/2017. - */ -public class ConfigDeleteProcessor implements Processor { - - private RouterCamelContext routerCamelContext; - - @Override - public void process(Exchange exchange) throws Exception { - if (exchange.getIn() != null) { - Message message = exchange.getIn(); - String routeId = message.getHeader("id", String.class); - routerCamelContext.killExistingRoute(routeId); - } - } - - public void setRouterCamelContext(RouterCamelContext routerCamelContext) { - this.routerCamelContext = routerCamelContext; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigUpdateProcessor.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigUpdateProcessor.java b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigUpdateProcessor.java deleted file mode 100644 index 76bd8a6..0000000 --- a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigUpdateProcessor.java +++ /dev/null @@ -1,43 +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.unomi.router.core.processor; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.unomi.router.core.context.RouterCamelContext; - -/** - * Created by amidani on 10/05/2017. - */ -public class ConfigUpdateProcessor implements Processor { - - private RouterCamelContext routerCamelContext; - - @Override - public void process(Exchange exchange) throws Exception { - if (exchange.getIn() != null) { - Message message = exchange.getIn(); - Object configuration = message.getBody(); - routerCamelContext.updateProfileReaderRoute(configuration); - } - } - - public void setRouterCamelContext(RouterCamelContext routerCamelContext) { - this.routerCamelContext = routerCamelContext; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.java b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.java deleted file mode 100644 index eff48c2..0000000 --- a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.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.unomi.router.core.route; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.model.rest.RestBindingMode; -import org.apache.unomi.router.api.ExportConfiguration; -import org.apache.unomi.router.api.ImportConfiguration; -import org.apache.unomi.router.core.context.RouterCamelContext; -import org.apache.unomi.router.core.processor.ConfigDeleteProcessor; -import org.apache.unomi.router.core.processor.ConfigUpdateProcessor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Created by amidani on 10/05/2017. - */ -public class ConfigUpdateRouteBuilder extends RouteBuilder { - - private static final Logger logger = LoggerFactory.getLogger(ConfigUpdateRouteBuilder.class.getName()); - private RouterCamelContext routerCamelContext; - - @Override - public void configure() throws Exception { - logger.info("Preparing REST Configuration for servlet with context path [/configUpdate]"); - restConfiguration().component("servlet") - .contextPath("/configUpdate") - .enableCORS(false) - .bindingMode(RestBindingMode.json) - .dataFormatProperty("prettyPrint", "true"); - - rest("/importConfigAdmin") - .put().consumes("application/json").type(ImportConfiguration.class) - .to("direct:configUpdateRestDeposit") - .delete("/{id}").to("direct:configDeleteRestDeposit"); - - rest("/exportConfigAdmin") - .put().consumes("application/json").type(ExportConfiguration.class) - .to("direct:configUpdateRestDeposit") - .delete("/{id}").to("direct:configDeleteRestDeposit"); - - - ConfigUpdateProcessor profileConfigUpdateProcessor = new ConfigUpdateProcessor(); - profileConfigUpdateProcessor.setRouterCamelContext(routerCamelContext); - from("direct:configUpdateRestDeposit") - .process(profileConfigUpdateProcessor) - .transform().constant("Success.") - .onException(Exception.class) - .transform().constant("Failure!"); - - - ConfigDeleteProcessor profileConfigDeleteProcessor = new ConfigDeleteProcessor(); - profileConfigDeleteProcessor.setRouterCamelContext(routerCamelContext); - from("direct:configDeleteRestDeposit") - .process(profileConfigDeleteProcessor) - .transform().constant("Success.") - .onException(Exception.class) - .transform().constant("Failure!"); - - } - - public void setRouterCamelContext(RouterCamelContext routerCamelContext) { - this.routerCamelContext = routerCamelContext; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/extensions/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 1d3ddca..3f81b5a 100644 --- a/extensions/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/extensions/router/router-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -80,16 +80,6 @@ <property name="library" value="Jackson"/> </bean> - <bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer" - init-method="register" - destroy-method="unregister"> - <property name="alias" value="/configUpdate"/> - <property name="httpService" ref="httpService"/> - <property name="servlet" ref="camelServlet"/> - </bean> - - <bean id="camelServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/> - <bean id="camelContext" class="org.apache.unomi.router.core.context.RouterCamelContext" init-method="initCamelContext" destroy-method="preDestroy"> @@ -124,20 +114,11 @@ <property name="profileService" ref="profileService"/> </bean> - <camel:camelContext id="httpEndpoint" xmlns="http://camel.apache.org/schema/blueprint"> - <camel:routeBuilder ref="configUpdateRouteBuilder" /> - </camel:camelContext> - - <bean id="configUpdateRouteBuilder" class="org.apache.unomi.router.core.route.ConfigUpdateRouteBuilder"> - <property name="routerCamelContext" ref="camelContext"/> - </bean> - <bean id="collectProfileBean" class="org.apache.unomi.router.core.bean.CollectProfileBean"> <property name="persistenceService" ref="persistenceService"/> </bean> <reference id="configSharingService" interface="org.apache.unomi.api.services.ConfigSharingService" /> - <reference id="httpService" interface="org.osgi.service.http.HttpService"/> <reference id="profileImportService" interface="org.apache.unomi.router.api.services.ProfileImportService"/> <reference id="profileExportService" interface="org.apache.unomi.router.api.services.ProfileExportService"/> <reference id="profileService" interface="org.apache.unomi.api.services.ProfileService"/> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java index 4bc3e24..8875294 100644 --- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java +++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java @@ -61,7 +61,7 @@ public abstract class AbstractConfigurationServiceEndpoint<T> { @Path("/") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) - public abstract T saveConfiguration(T configuration, @Context MessageContext context) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException; + public abstract T saveConfiguration(T configuration); /** * Retrieves a configuration by id. @@ -86,6 +86,6 @@ public abstract class AbstractConfigurationServiceEndpoint<T> { @Path("/{configId}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) - public abstract void deleteConfiguration(@PathParam("configId") String configId, @Context MessageContext context); + public abstract void deleteConfiguration(@PathParam("configId") String configId); } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java index 522a6a5..b796d22 100644 --- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java +++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java @@ -16,17 +16,7 @@ */ package org.apache.unomi.router.rest; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.cxf.jaxrs.ext.MessageContext; import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContextBuilder; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.HttpClients; import org.apache.unomi.api.services.ProfileService; import org.apache.unomi.router.api.ExportConfiguration; import org.apache.unomi.router.api.services.ImportExportConfigurationService; @@ -36,7 +26,6 @@ import org.slf4j.LoggerFactory; import javax.jws.WebMethod; import javax.jws.WebService; -import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -66,12 +55,6 @@ public class ExportConfigurationServiceEndPoint extends AbstractConfigurationSer public ExportConfigurationServiceEndPoint() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { logger.info("Initializing export configuration service endpoint..."); - SSLContextBuilder builder = new SSLContextBuilder(); - builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - httpClient = HttpClients.custom().setSSLSocketFactory( - sslsf).build(); } @WebMethod(exclude = true) @@ -95,60 +78,15 @@ public class ExportConfigurationServiceEndPoint extends AbstractConfigurationSer * @return the export configuration saved. */ @Override - public ExportConfiguration saveConfiguration(ExportConfiguration exportConfiguration, MessageContext context) { - - HttpServletRequest request = context.getHttpServletRequest(); - String localBasePath = request.getScheme() + "://127.0.0.1:" + request.getLocalPort(); - + public ExportConfiguration saveConfiguration(ExportConfiguration exportConfiguration) { ExportConfiguration exportConfigSaved = configurationService.save(exportConfiguration); - try { - HttpPut httpPut = new HttpPut(localBasePath + "/configUpdate/exportConfigAdmin"); - StringEntity input = new StringEntity(new ObjectMapper().writeValueAsString(exportConfigSaved)); - input.setContentType(MediaType.APPLICATION_JSON); - httpPut.setEntity(input); - - HttpResponse response = httpClient.execute(httpPut); - - if (response.getStatusLine().getStatusCode() != 200) { - logger.error("Failed to update the running config: Please check the acceccibilty to the URI: \n{}", - localBasePath + "/configUpdate/importConfigAdmin"); - logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode()); - throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); - } - } catch (Exception e) { - logger.warn("Unable to update Camel route [{}]", exportConfiguration.getItemId()); - logger.debug("Unable to update Camel route", e); - throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); - - } return exportConfigSaved; } @Override - public void deleteConfiguration(String configId, MessageContext context) { + public void deleteConfiguration(String configId) { this.configurationService.delete(configId); - - HttpServletRequest request = context.getHttpServletRequest(); - String localBasePath = request.getScheme() + "://127.0.0.1:" + request.getLocalPort(); - - try { - HttpDelete httpDelete = new HttpDelete(localBasePath + "/configUpdate/exportConfigAdmin/" + configId); - - HttpResponse response = httpClient.execute(httpDelete); - - if (response.getStatusLine().getStatusCode() != 200) { - logger.error("Failed to update the running config: Please check the accessibility to the URI: \n{}", - localBasePath + "/configUpdate/exportConfigAdmin/" + configId); - logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode()); - throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); - } - } catch (Exception e) { - logger.warn("Unable to delete Camel route [{}]", configId); - logger.debug("Unable to delete Camel route", e); - throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); - - } } /** http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java index 4b4f62a..c148997 100644 --- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java +++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java @@ -16,19 +16,9 @@ */ package org.apache.unomi.router.rest; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.cxf.jaxrs.ext.MessageContext; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContextBuilder; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.HttpClients; import org.apache.unomi.router.api.ImportConfiguration; import org.apache.unomi.router.api.RouterConstants; import org.apache.unomi.router.api.services.ImportExportConfigurationService; @@ -37,7 +27,6 @@ import org.slf4j.LoggerFactory; import javax.jws.WebMethod; import javax.jws.WebService; -import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -66,12 +55,6 @@ public class ImportConfigurationServiceEndPoint extends AbstractConfigurationSer public ImportConfigurationServiceEndPoint() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { logger.info("Initializing import configuration service endpoint..."); - SSLContextBuilder builder = new SSLContextBuilder(); - builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - httpClient = HttpClients.custom().setSSLSocketFactory( - sslsf).build(); } @WebMethod(exclude = true) @@ -85,61 +68,16 @@ public class ImportConfigurationServiceEndPoint extends AbstractConfigurationSer * @return the import configuration saved. */ @Override - public ImportConfiguration saveConfiguration(ImportConfiguration importConfiguration, MessageContext context) { - - HttpServletRequest request = context.getHttpServletRequest(); - String localBasePath = request.getScheme() + "://127.0.0.1:" + request.getLocalPort(); + public ImportConfiguration saveConfiguration(ImportConfiguration importConfiguration) { ImportConfiguration importConfigSaved = configurationService.save(importConfiguration); - try { - HttpPut httpPut = new HttpPut(localBasePath + "/configUpdate/importConfigAdmin"); - StringEntity input = new StringEntity(new ObjectMapper().writeValueAsString(importConfigSaved)); - input.setContentType(MediaType.APPLICATION_JSON); - httpPut.setEntity(input); - - HttpResponse response = httpClient.execute(httpPut); - - if (response.getStatusLine().getStatusCode() != 200) { - logger.error("Failed to update the running config: Please check the accessibility to the URI: \n{}", - localBasePath + "/configUpdate/importConfigAdmin"); - logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode()); - throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); - } - } catch (Exception e) { - logger.warn("Unable to update Camel route [{}]", importConfiguration.getItemId()); - logger.debug("Unable to update Camel route", e); - throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); - - } - return importConfigSaved; } @Override - public void deleteConfiguration(String configId, MessageContext context) { + public void deleteConfiguration(String configId) { this.configurationService.delete(configId); - - HttpServletRequest request = context.getHttpServletRequest(); - String localBasePath = request.getScheme() + "://127.0.0.1:" + request.getLocalPort(); - - try { - HttpDelete httpDelete = new HttpDelete(localBasePath + "/configUpdate/importConfigAdmin/" + configId); - - HttpResponse response = httpClient.execute(httpDelete); - - if (response.getStatusLine().getStatusCode() != 200) { - logger.error("Failed to update the running config: Please check the accessibility to the URI: \n{}", - localBasePath + "/configUpdate/importConfigAdmin/" + configId); - logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode()); - throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); - } - } catch (Exception e) { - logger.warn("Unable to delete Camel route [{}]", configId); - logger.debug("Unable to delete Camel route", e); - throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); - - } } /** http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-service/pom.xml ---------------------------------------------------------------------- diff --git a/extensions/router/router-service/pom.xml b/extensions/router/router-service/pom.xml index 13f9c6f..ce5615d 100644 --- a/extensions/router/router-service/pom.xml +++ b/extensions/router/router-service/pom.xml @@ -91,11 +91,6 @@ </dependency> <dependency> - <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/AbstractConfigurationServiceImpl.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/AbstractConfigurationServiceImpl.java b/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/AbstractConfigurationServiceImpl.java index 3b87e85..09b1d37 100644 --- a/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/AbstractConfigurationServiceImpl.java +++ b/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/AbstractConfigurationServiceImpl.java @@ -17,6 +17,7 @@ package org.apache.unomi.router.services; import org.apache.unomi.persistence.spi.PersistenceService; +import org.apache.unomi.router.api.IRouterCamelContext; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; @@ -27,12 +28,13 @@ import org.slf4j.LoggerFactory; /** * Created by amidani on 26/06/2017. */ -public class AbstractConfigurationServiceImpl implements SynchronousBundleListener { +public abstract class AbstractConfigurationServiceImpl implements SynchronousBundleListener { private static final Logger logger = LoggerFactory.getLogger(AbstractConfigurationServiceImpl.class.getName()); protected BundleContext bundleContext; protected PersistenceService persistenceService; + protected IRouterCamelContext routerCamelContext; public void setBundleContext(BundleContext bundleContext) { this.bundleContext = bundleContext; @@ -42,6 +44,10 @@ public class AbstractConfigurationServiceImpl implements SynchronousBundleListen this.persistenceService = persistenceService; } + public void setRouterCamelContext(IRouterCamelContext routerCamelContext) { + this.routerCamelContext = routerCamelContext; + } + public void postConstruct() { logger.debug("postConstruct {" + bundleContext.getBundle() + "}"); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ExportConfigurationServiceImpl.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ExportConfigurationServiceImpl.java b/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ExportConfigurationServiceImpl.java index 762a65f..e9e236c 100644 --- a/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ExportConfigurationServiceImpl.java +++ b/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ExportConfigurationServiceImpl.java @@ -17,6 +17,7 @@ package org.apache.unomi.router.services; import org.apache.unomi.router.api.ExportConfiguration; +import org.apache.unomi.router.api.IRouterCamelContext; import org.apache.unomi.router.api.services.ImportExportConfigurationService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,12 +51,27 @@ public class ExportConfigurationServiceImpl extends AbstractConfigurationService if (exportConfiguration.getItemId() == null) { exportConfiguration.setItemId(UUID.randomUUID().toString()); } + try { + routerCamelContext.updateProfileReaderRoute(exportConfiguration); + } catch (Exception e) { + logger.error("Error when trying to save/update running Apache Camel Route: {}", exportConfiguration.getItemId()); + } persistenceService.save(exportConfiguration); return persistenceService.load(exportConfiguration.getItemId(), ExportConfiguration.class); } @Override public void delete(String configId) { + try { + routerCamelContext.killExistingRoute(configId); + } catch (Exception e) { + logger.error("Error when trying to delete running Apache Camel Route: {}", configId); + } persistenceService.remove(configId, ExportConfiguration.class); } + + @Override + public void setRouterCamelContext(IRouterCamelContext routerCamelContext) { + super.setRouterCamelContext(routerCamelContext); + } } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/b190a4f7/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java b/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java index 5275919..2d7f96e 100644 --- a/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java +++ b/extensions/router/router-service/src/main/java/org/apache/unomi/router/services/ImportConfigurationServiceImpl.java @@ -16,6 +16,7 @@ */ package org.apache.unomi.router.services; +import org.apache.unomi.router.api.IRouterCamelContext; import org.apache.unomi.router.api.ImportConfiguration; import org.apache.unomi.router.api.services.ImportExportConfigurationService; import org.slf4j.Logger; @@ -50,12 +51,29 @@ public class ImportConfigurationServiceImpl extends AbstractConfigurationService if (importConfiguration.getItemId() == null) { importConfiguration.setItemId(UUID.randomUUID().toString()); } + + try { + routerCamelContext.updateProfileReaderRoute(importConfiguration); + } catch (Exception e) { + logger.error("Error when trying to save/update running Apache Camel Route: {}", importConfiguration.getItemId()); + } + persistenceService.save(importConfiguration); return persistenceService.load(importConfiguration.getItemId(), ImportConfiguration.class); } @Override public void delete(String configId) { + try { + routerCamelContext.killExistingRoute(configId); + } catch (Exception e) { + logger.error("Error when trying to delete running Apache Camel Route: {}", configId); + } persistenceService.remove(configId, ImportConfiguration.class); } + + @Override + public void setRouterCamelContext(IRouterCamelContext routerCamelContext) { + super.setRouterCamelContext(routerCamelContext); + } }
