Index: components/core/src/main/java/org/hippoecm/hst/configuration/channel/ChannelManagerImpl.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- components/core/src/main/java/org/hippoecm/hst/configuration/channel/ChannelManagerImpl.java	(revision 40622)
+++ components/core/src/main/java/org/hippoecm/hst/configuration/channel/ChannelManagerImpl.java	(revision )
@@ -158,7 +158,7 @@
             }
         } else {
             log.warn("Cannot load channels because node '{}' does not exist",
-                     configNode.getPath() + "/" + HstNodeTypes.NODENAME_HST_CHANNELS);
+                    configNode.getPath() + "/" + HstNodeTypes.NODENAME_HST_CHANNELS);
         }
     }
 
@@ -225,7 +225,7 @@
             for (Node mainConfigNode : new NodeIterable(channelRootConfigNode.getNodes())) {
                 final String lockedBy = JcrUtils.getStringProperty(mainConfigNode, HstNodeTypes.GENERAL_PROPERTY_LOCKED_BY, null);
                 if (lockedBy != null) {
-                 mainConfigNodesLockedBySet.add(lockedBy);
+                    mainConfigNodesLockedBySet.add(lockedBy);
                 }
             }
         } catch (RepositoryException e) {
@@ -451,7 +451,7 @@
                         if (e.getStatus() == Status.STOP_CHANNEL_PROCESSING) {
                             session.refresh(false);
                             throw new ChannelException(e.getMessage(), e, Type.STOPPED_BY_LISTENER,
-                                                       "Channel creation stopped by listener '" + listener.getClass().getName() + "'");
+                                    "Channel creation stopped by listener '" + listener.getClass().getName() + "'");
                         } else {
                             log.warn(
                                     "Channel created event listener, " + listener + ", failed to handle the event. Continue channel processing",
@@ -459,7 +459,7 @@
                         }
                     } catch (Exception listenerEx) {
                         log.warn("Channel created event listener, " + listener + ", failed to handle the event",
-                                 listenerEx);
+                                listenerEx);
                     }
                 }
 
@@ -531,7 +531,7 @@
                         if (e.getStatus() == Status.STOP_CHANNEL_PROCESSING) {
                             session.refresh(false);
                             throw new ChannelException(e.getMessage(), e, Type.STOPPED_BY_LISTENER,
-                                                       "Channel '" + channel.getId() + "' update stopped by listener '" + listener.getClass().getName() + "'");
+                                    "Channel '" + channel.getId() + "' update stopped by listener '" + listener.getClass().getName() + "'");
                         } else {
                             log.warn(
                                     "Channel created event listener, " + listener + ", failed to handle the event. Continue channel processing",
@@ -539,12 +539,12 @@
                         }
                     } catch (Exception listenerEx) {
                         log.error("Channel updated event listener, " + listener + ", failed to handle the event",
-                                  listenerEx);
+                                listenerEx);
                     }
                 }
                 String[] pathsToBeChanged = JcrSessionUtils.getPendingChangePaths(session, session.getNode(rootPath), true);
                 session.save();
-                 hstManager.invalidate(pathsToBeChanged);
+                hstManager.invalidate(pathsToBeChanged);
             } catch (RepositoryException e) {
                 throw new ChannelException("Unable to save channel to the repository", e);
             }
@@ -584,7 +584,7 @@
             throw new ChannelException("Configured class " + channelInfoClassName + " was not found", cnfe);
         } catch (ClassCastException cce) {
             throw new ChannelException("Configured class " + channelInfoClassName + " does not extend ChannelInfo",
-                                       cce);
+                    cce);
         }
     }
 
@@ -651,64 +651,77 @@
 
     public void invalidate() {
         synchronized (HstManagerImpl.MUTEX) {
-          channels = null;
-          blueprints = null;
+            channels = null;
+            blueprints = null;
         }
     }
 
     // private - internal - methods
 
     private void createChannel(Node configRoot, Blueprint blueprint, Session session, final String channelId, final Channel channel) throws ChannelException, RepositoryException {
+        Node contentRootNode = null;
+        Boolean contentCreated = false;
+        try {
-        // Create virtual host
-        final URI channelUri = getChannelUri(channel);
-        final Node virtualHost = getOrCreateVirtualHost(configRoot, channelUri.getHost());
+            // Create virtual host
+            final URI channelUri = getChannelUri(channel);
+            final Node virtualHost = getOrCreateVirtualHost(configRoot, channelUri.getHost());
 
-        // Create channel
-        copyOrCreateChannelNode(configRoot, channelId, channel);
+            // Create channel
+            copyOrCreateChannelNode(configRoot, channelId, channel);
 
-        // Create or reuse HST configuration
-        final Node blueprintNode = BlueprintHandler.getNode(session, blueprint);
-        final String hstConfigPath = reuseOrCopyConfiguration(session, configRoot, blueprintNode, channelId);
-        channel.setHstConfigPath(hstConfigPath);
+            // Create or reuse HST configuration
+            final Node blueprintNode = BlueprintHandler.getNode(session, blueprint);
+            final String hstConfigPath = reuseOrCopyConfiguration(session, configRoot, blueprintNode, channelId);
+            channel.setHstConfigPath(hstConfigPath);
 
-        // Create content if the blueprint contains a content prototype. The path of the created content node has to
-        // be set on the HST site nodes.
-        final String channelContentRootPath;
-        if (blueprint.getHasContentPrototype()) {
+            // Create content if the blueprint contains a content prototype. The path of the created content node has to
+            // be set on the HST site nodes.
+            final String channelContentRootPath;
+            if (blueprint.getHasContentPrototype()) {
-            final Node contentRootNode = createContent(blueprint, session, channelId, channel);
+                contentRootNode = createContent(blueprint, session, channelId, channel);
+                contentCreated = true;
-            channelContentRootPath = contentRootNode.getPath();
-            channel.setContentRoot(channelContentRootPath);
-        } else {
-            channelContentRootPath = channel.getContentRoot();
-        }
+                channelContentRootPath = contentRootNode.getPath();
+                channel.setContentRoot(channelContentRootPath);
+            } else {
+                channelContentRootPath = channel.getContentRoot();
+            }
 
-        final Node sitesNode = configRoot.getNode(sites);
-        final Node liveSiteNode = createSiteNode(sitesNode, channelId, channelContentRootPath);
-        final Node previewSiteNode = createSiteNode(sitesNode, channelId + "-preview",
-                channelContentRootPath);
+            final Node sitesNode = configRoot.getNode(sites);
+            final Node liveSiteNode = createSiteNode(sitesNode, channelId, channelContentRootPath);
+            final Node previewSiteNode = createSiteNode(sitesNode, channelId + "-preview",
+                    channelContentRootPath);
 
-        if (blueprintNode.hasNode(HstNodeTypes.NODENAME_HST_SITE)) {
-            Node blueprintSiteNode = blueprintNode.getNode(HstNodeTypes.NODENAME_HST_SITE);
-            if (blueprintSiteNode.hasProperty(HstNodeTypes.SITE_CONFIGURATIONPATH)) {
-                String explicitConfigPath = blueprintSiteNode.getProperty(HstNodeTypes.SITE_CONFIGURATIONPATH).getString();
-                liveSiteNode.setProperty(HstNodeTypes.SITE_CONFIGURATIONPATH, explicitConfigPath);
-                previewSiteNode.setProperty(HstNodeTypes.SITE_CONFIGURATIONPATH, explicitConfigPath);
-            }
-        }
+            if (blueprintNode.hasNode(HstNodeTypes.NODENAME_HST_SITE)) {
+                Node blueprintSiteNode = blueprintNode.getNode(HstNodeTypes.NODENAME_HST_SITE);
+                if (blueprintSiteNode.hasProperty(HstNodeTypes.SITE_CONFIGURATIONPATH)) {
+                    String explicitConfigPath = blueprintSiteNode.getProperty(HstNodeTypes.SITE_CONFIGURATIONPATH).getString();
+                    liveSiteNode.setProperty(HstNodeTypes.SITE_CONFIGURATIONPATH, explicitConfigPath);
+                    previewSiteNode.setProperty(HstNodeTypes.SITE_CONFIGURATIONPATH, explicitConfigPath);
+                }
+            }
 
-        final String mountPointPath = liveSiteNode.getPath();
-        channel.setHstMountPoint(mountPointPath);
+            final String mountPointPath = liveSiteNode.getPath();
+            channel.setHstMountPoint(mountPointPath);
 
-        final String previewMountPointPath = previewSiteNode.getPath();
-        channel.setHstPreviewMountPoint(previewMountPointPath);
+            final String previewMountPointPath = previewSiteNode.getPath();
+            channel.setHstPreviewMountPoint(previewMountPointPath);
 
-        // Create mount
-        Node mount = createMountNode(virtualHost, blueprintNode, channelUri.getPath());
-        mount.setProperty(HstNodeTypes.MOUNT_PROPERTY_CHANNELPATH, channelsRoot + channelId);
-        mount.setProperty(HstNodeTypes.MOUNT_PROPERTY_MOUNTPOINT, mountPointPath);
-        final String locale = channel.getLocale();
-        if (locale != null) {
-            mount.setProperty(HstNodeTypes.GENERAL_PROPERTY_LOCALE, locale);
+            // Create mount
+            Node mount = createMountNode(virtualHost, blueprintNode, channelUri.getPath());
+            mount.setProperty(HstNodeTypes.MOUNT_PROPERTY_CHANNELPATH, channelsRoot + channelId);
+            mount.setProperty(HstNodeTypes.MOUNT_PROPERTY_MOUNTPOINT, mountPointPath);
+            final String locale = channel.getLocale();
+            if (locale != null) {
+                mount.setProperty(HstNodeTypes.GENERAL_PROPERTY_LOCALE, locale);
+            }
+        } catch (ChannelException e) {
+            if(contentCreated && contentRootNode!=null){
+                Session s = contentRootNode.getSession();
+                s.refresh(false);           //remove the new configuration
+                contentRootNode.remove();   //remove the new content
+                s.save();
+            }
+            throw e;
         }
 
 
@@ -719,7 +732,7 @@
             configRoot.addNode(HstNodeTypes.NODENAME_HST_CHANNELS, HstNodeTypes.NODETYPE_HST_CHANNELS);
         }
         Node channelNode = configRoot.getNode(HstNodeTypes.NODENAME_HST_CHANNELS).addNode(channelId,
-                                                                                          HstNodeTypes.NODETYPE_HST_CHANNEL);
+                HstNodeTypes.NODETYPE_HST_CHANNEL);
         ChannelPropertyMapper.saveChannel(channelNode, channel);
     }
 
@@ -981,7 +994,7 @@
      */
     static ChannelException mountNotFoundException(String missingMount) {
         return new ChannelException("Mount not found: " + missingMount, ChannelException.Type.MOUNT_NOT_FOUND,
-                                    missingMount);
+                missingMount);
     }
 
     /**
@@ -992,7 +1005,7 @@
      */
     static ChannelException mountExistsException(String existingMount) {
         return new ChannelException("Mount already exists: " + existingMount, ChannelException.Type.MOUNT_EXISTS,
-                                    existingMount);
+                existingMount);
     }
 
     /**
@@ -1003,7 +1016,7 @@
      */
     static ChannelException cannotCreateContent(String contentRoot, Throwable cause) {
         return new ChannelException("Could not create content at '" + contentRoot + "'", cause,
-                                    ChannelException.Type.CANNOT_CREATE_CONTENT, contentRoot);
+                ChannelException.Type.CANNOT_CREATE_CONTENT, contentRoot);
     }
 
 
