dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18423
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7764: Make sure adding route replaces any existing route with same id. Removed deprecated method warni...
------------------------------------------------------------
revno: 7764
committer: Bob Jolliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-07-30 11:32:40 +0100
message:
Make sure adding route replaces any existing route with same id. Removed deprecated method warnings.
modified:
dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/integration/AddRouteAction.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/integration/AddRouteAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/integration/AddRouteAction.java 2012-05-24 09:45:14 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/integration/AddRouteAction.java 2012-07-30 10:32:40 +0000
@@ -27,15 +27,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import com.opensymphony.xwork2.Action;
import java.io.File;
import java.io.FileInputStream;
-
import org.apache.camel.CamelContext;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RoutesDefinition;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
-import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.system.util.StreamUtils;
/**
* @author Bob Jolliffe
@@ -50,11 +51,11 @@
// Dependencies
// -------------------------------------------------------------------------
- private CamelContext builtinCamelContext;
+ private ModelCamelContext builtinCamelContext;
public void setBuiltinCamelContext( CamelContext camelContext )
{
- this.builtinCamelContext = camelContext;
+ this.builtinCamelContext = (ModelCamelContext) camelContext;
}
private File file;
@@ -75,6 +76,7 @@
// Action implementation
// -------------------------------------------------------------------------
+ @Override
public String execute()
throws Exception
{
@@ -87,13 +89,27 @@
try
{
RoutesDefinition routes = builtinCamelContext.loadRoutesDefinition( is );
- builtinCamelContext.addRouteDefinitions( routes.getRoutes() );
+ for (RouteDefinition route : routes.getRoutes() )
+ {
+ // remove any existing route with this id before adding ...
+ RouteDefinition existingRoute = builtinCamelContext.getRouteDefinition( route.getId() );
+ if (existingRoute != null)
+ {
+ builtinCamelContext.stopRoute( route.getId());
+ builtinCamelContext.removeRouteDefinition( route );
+ }
+ builtinCamelContext.addRouteDefinitions( routes.getRoutes() );
+ }
}
catch ( Exception e )
{
log.info( "Unable to load route: " + e.getMessage() );
return ERROR;
}
+ finally
+ {
+ StreamUtils.closeInputStream( is );
+ }
}
return SUCCESS;