Skip to content

Instantly share code, notes, and snippets.

@giacomolm
Created December 8, 2013 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save giacomolm/7859397 to your computer and use it in GitHub Desktop.
Save giacomolm/7859397 to your computer and use it in GitHub Desktop.
Patch resolving cargo/spring problems in https://github.com/Tirasa/SyncopeCamel/ , but not resolving camel route problems on exception
diff --git a/core/pom.xml b/core/pom.xml
index 7958413..af8d15d 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -532,7 +532,7 @@ under the License.
<deployable>
<location>${cargo.run.dir}</location>
<pingURL>http://localhost:${cargo.servlet.port}/syncope/cacheStats.jsp</pingURL>
- <pingTimeout>60000</pingTimeout>
+ <pingTimeout>180000</pingTimeout>
<properties>
<context>syncope</context>
</properties>
diff --git a/core/src/main/java/org/apache/syncope/core/camel/DefaultProvisioningManager.java b/core/src/main/java/org/apache/syncope/core/camel/DefaultProvisioningManager.java
index f14e227..5c39ab6 100644
--- a/core/src/main/java/org/apache/syncope/core/camel/DefaultProvisioningManager.java
+++ b/core/src/main/java/org/apache/syncope/core/camel/DefaultProvisioningManager.java
@@ -21,10 +21,12 @@ package org.apache.syncope.core.camel;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
+import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.PollingConsumer;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.impl.DefaultMessage;
import org.apache.camel.model.ModelCamelContext;
@@ -33,6 +35,7 @@ import org.apache.camel.spring.SpringCamelContext;
import org.apache.syncope.core.util.ApplicationContextProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
@@ -45,15 +48,18 @@ public class DefaultProvisioningManager implements ProvisioningManager {
*/
private static final Logger LOG = LoggerFactory.getLogger(DefaultProvisioningManager.class);
- private SpringCamelContext camelContext;
+ @Autowired
+ private DefaultCamelContext camelContext;
private RoutesDefinition routes;
private PollingConsumer pollingConsumer;
List<String> knownUri;
public DefaultProvisioningManager() throws Exception {
+
+ knownUri = new ArrayList<String>();
+ /*ApplicationContext context = ApplicationContextProvider.getApplicationContext();
+ camelContext = context.getBean("camel-context", DefaultCamelContext.class);
- ApplicationContext context = ApplicationContextProvider.getApplicationContext();
- camelContext = new SpringCamelContext(context);
knownUri = new ArrayList<String>();
try {
@@ -64,7 +70,7 @@ public class DefaultProvisioningManager implements ProvisioningManager {
// TODO Auto-generated catch block
LOG.error("Unexpected error", e);
}
- camelContext.start();
+ camelContext.start();*/
}
@Override
@@ -77,15 +83,14 @@ public class DefaultProvisioningManager implements ProvisioningManager {
camelContext.stop();
}
- @Override
- public ModelCamelContext getContext() {
- return camelContext;
+ public DefaultCamelContext getContext() {
+ ApplicationContext context = ApplicationContextProvider.getApplicationContext();
+ return context.getBean("camel-context", DefaultCamelContext.class);
}
@Override
public void changeRoute(String routePath) {
try {
- //InputStream is = getClass().getResourceAsStream("/camelRoute.xml");
camelContext.removeRouteDefinitions(routes.getRoutes());
InputStream is = getClass().getResourceAsStream(routePath);
routes = getContext().loadRoutesDefinition(is);
@@ -108,17 +113,23 @@ public class DefaultProvisioningManager implements ProvisioningManager {
@Override
public void startConsumer(String uri) throws Exception {
- if(!knownUri.contains(uri)){
+ if (!knownUri.contains(uri)) {
knownUri.add(uri);
Endpoint endpoint = getContext().getEndpoint(uri);
pollingConsumer = endpoint.createPollingConsumer();
- pollingConsumer.start();
+ pollingConsumer.start();
}
}
@Override
+ public void stopConsumer() throws Exception {
+ pollingConsumer.stop();
+ }
+
+ @Override
public Object getMessage(Class type) throws Exception {
- Exchange o = pollingConsumer.receive();
+ Exchange o = pollingConsumer.receive(10000);
+ LOG.error("EXCHANGE BODY {}", o.getIn().getBody());
return o.getIn().getBody();
}
diff --git a/core/src/main/java/org/apache/syncope/core/camel/ProvisioningManager.java b/core/src/main/java/org/apache/syncope/core/camel/ProvisioningManager.java
index 2d1c0cd..326be00 100644
--- a/core/src/main/java/org/apache/syncope/core/camel/ProvisioningManager.java
+++ b/core/src/main/java/org/apache/syncope/core/camel/ProvisioningManager.java
@@ -1,34 +1,34 @@
/*
- * Copyright 2013 The Apache Software Foundation.
+ * 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
*
- * Licensed 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
*
- * 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.
+ * 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.syncope.core.camel;
-import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+
-/**
- *
- * @author giacomolm
- */
public interface ProvisioningManager {
public void startContext() throws Exception;
public void stopContext() throws Exception;
- public ModelCamelContext getContext();
+ public DefaultCamelContext getContext();
public void changeRoute(String routePath);
@@ -36,5 +36,7 @@ public interface ProvisioningManager {
public void startConsumer(String uri) throws Exception;
+ public void stopConsumer() throws Exception;
+
public Object getMessage(Class type) throws Exception;
}
diff --git a/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java b/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
index c949c44..ba1a83f 100644
--- a/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
+++ b/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
@@ -26,10 +26,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultExchange;
import org.apache.syncope.common.mod.StatusMod;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.syncope.common.mod.UserMod;
@@ -222,15 +218,14 @@ public class UserController extends AbstractResourceAssociator<UserTO> {
provisioningManager.startConsumer("direct:uc-port");
provisioningManager.sendMessage("direct:provisioning-port", actual);
created = (WorkflowResult<Map.Entry<Long, Boolean>>)provisioningManager.getMessage(WorkflowResult.class);
+ //provisioningManager.stopConsumer();
} catch (Exception ex) {
- LOG.error("Unexpected error in UserworkFlow Creation ", ex);
+ LOG.error("Unexpected error in Userworkflow Creation ", ex);
}
/*
- * Actual operations: workflow, propagation, notification
- */
-
- //WorkflowResult<Map.Entry<Long, Boolean>> created = uwfAdapter.create(actual);
+ * Actual operations: propagation, notification
+ */
List<PropagationTask> tasks = propagationManager.getUserCreateTaskIds(
created, actual.getPassword(), actual.getVirAttrs());
diff --git a/core/src/main/resources/camelRoute.xml b/core/src/main/resources/camelRoute.xml
index bbb3de7..775649d 100644
--- a/core/src/main/resources/camelRoute.xml
+++ b/core/src/main/resources/camelRoute.xml
@@ -1,11 +1,42 @@
+<?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
-<routes xmlns="http://camel.apache.org/schema/spring">
- <!-- here we define the bar route -->
- <route id="bar">
- <from uri="direct:provisioning-port"/>
- <bean ref="uwfAdapter" method="create(${body})"/>
- <to uri="direct:uc-port"/>
- </route>
-</routes>
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+
+ <routeContext id="defaultRoutes" xmlns="http://camel.apache.org/schema/spring">
+ <route id="dafult-1">
+ <from uri="direct:provisioning-port"/>
+ <bean ref="uwfAdapter" method="create(${body})"/>
+ <onException>
+ <exception>org.apache.syncope.common.validation.SyncopeClientCompositeException</exception>
+ <to uri="direct:uc-port"/>
+ </onException>
+ <to uri="direct:uc-port"/>
+ </route>
+ </routeContext>
+
+</beans>
diff --git a/core/src/main/resources/syncopeContext.xml b/core/src/main/resources/syncopeContext.xml
index 1d902a0..e1090d4 100644
--- a/core/src/main/resources/syncopeContext.xml
+++ b/core/src/main/resources/syncopeContext.xml
@@ -20,13 +20,16 @@ under the License.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
+ xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task
- http://www.springframework.org/schema/task/spring-task.xsd">
+ http://www.springframework.org/schema/task/spring-task.xsd
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
@@ -121,5 +124,10 @@ under the License.
<constructor-arg value="60"/>
<constructor-arg value="5000"/>
</bean>
-
+
+ <import resource="camelRoute.xml"/>
+ <camel:camelContext id="camel-context" autoStartup="true">
+ <camel:routeContextRef ref="defaultRoutes"/>
+ </camel:camelContext>
+
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment