Index: src/main/java/org/ow2/petals/jbi/management/task/DownloadTask.java
===================================================================
--- src/main/java/org/ow2/petals/jbi/management/task/DownloadTask.java	(revision 16370)
+++ src/main/java/org/ow2/petals/jbi/management/task/DownloadTask.java	(working copy)
@@ -25,8 +25,10 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.HttpURLConnection;
 import java.net.URI;
 import java.net.URL;
+import java.net.URLConnection;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
@@ -34,18 +36,27 @@
 import org.ow2.petals.util.LoggingUtil;
 
 /**
- * This task download entity (component, shared lib, service assembly) archive
- * into the work directory, only if the URL protocol is http: or ftp: <br/>
+ * This task download entity (component, shared lib, service assembly) archive into the work directory, only if the URL
+ * protocol is http: or ftp: <br/>
  * Inputs : archive {@link URI} <br/>
  * Outputs : downloaded archive {@link URI}<br/>
  * The task has got a non-robust approach : it stops at the first subtask failed<br />
  * and have the undo capability.<br />
  * 
  * @author ofabre - EBM Websourcing
- * @author Frederic Gardes - eBM Websourcing
+ * @author Frederic Gardes - EBM Websourcing
+ * @author Christophe DENEUX - EBM Websourcing
  */
 public class DownloadTask extends AbstractFileManipulationTask {
 
+    private class InvalidArchive extends Exception {
+
+        public InvalidArchive(String message) {
+            super(message);
+        }
+
+    }
+
     public DownloadTask(LoggingUtil log, String petalsInstallDirectory) {
         super(log, petalsInstallDirectory);
     }
@@ -87,26 +98,62 @@
      * @param archiveUrl
      * @return
      * @throws IOException
+     *             An IOException occurs. See the exception message and stacktrace for more information.
+     * @throws InvalidArchive
+     *             The JBI archive associated to the provided URL is not valid. See the exception message for more
+     *             information.
      */
-    private URL downloadEntityPackage(URL archiveUrl) throws IOException {
+    private URL downloadEntityPackage(final URL archiveUrl) throws IOException, InvalidArchive {
+
+        // We define the name of the downloaded archive
+        final String path = archiveUrl.getPath();
+        String fileName = path.substring(path.lastIndexOf('/') + 1);
+        if (!fileName.contains(".")) {
+            // try to get the file name with the query
+            final String query = archiveUrl.getQuery();
+            if (query != null) {
+                fileName = query.substring(query.lastIndexOf('=') + 1);
+            }
+        }
+        final File outputFile = new File(this.getWorkDirectory(), fileName);
+        this.log.debug("Local temporary file name of the JBI archive: " + outputFile.getAbsolutePath());
+
+        final URLConnection urlConnection = archiveUrl.openConnection();
+        // We check if the remote resource exists.
+        if ("http".equalsIgnoreCase(archiveUrl.getProtocol())) {
+            final HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;
+            final int responseCode = httpUrlConnection.getResponseCode();
+            this.log.debug("HTTP Response code: " + responseCode);
+            if (responseCode != HttpURLConnection.HTTP_OK) {
+                throw new InvalidArchive("Unable to download the remote resource " + archiveUrl.toExternalForm()
+                        + " [HTTP " + responseCode + " " + httpUrlConnection.getResponseMessage() + "]");
+            } else {
+                // We check that the resource is a ZIP file
+                final String contentType = httpUrlConnection.getContentType();
+                if (contentType != null) {
+                    if (!contentType.startsWith("application/zip") &&
+                            !contentType.startsWith("application/x-zip") &&
+                            !contentType.startsWith("application/x-zip-compressed")) {
+                        throw new InvalidArchive("The remote resource [" + archiveUrl.toExternalForm()
+                                + "] is not a valid JBI archive. It's content-type is defined as: " + contentType
+                                + ", instead of application/[zip|x-zip|x-zip-compressed].");
+                    }
+                } else {
+                    throw new InvalidArchive("The remote resource [" + archiveUrl.toExternalForm()
+                            + "] is not a valid JBI archive. It's content-type is undefined.");
+                }
+            }
+        }
+
+        // We download the archive
         InputStream inputStream = null;
         FileOutputStream fileOutputStream = null;
-        URL url = null;
         try {
-            final String path = archiveUrl.getPath();
-            String fileName = path.substring(path.lastIndexOf('/') + 1);
-            if (!fileName.contains(".")) {
-                // try to get the file name with the query
-                final String query = archiveUrl.getQuery();
-                if (query != null) {
-                    fileName = query.substring(query.lastIndexOf('=') + 1);
-                }
-            }
-            inputStream = archiveUrl.openStream();
-            final File outputFile = new File(this.getWorkDirectory(), fileName);
+            inputStream = urlConnection.getInputStream();
             fileOutputStream = new FileOutputStream(outputFile);
             IOUtils.copy(inputStream, fileOutputStream);
-            url = outputFile.toURI().toURL();
+            this.log.debug("Archive downloaded.");
+            return outputFile.toURI().toURL();
         } finally {
             try {
                 if (inputStream != null) {
@@ -115,12 +162,11 @@
                 if (fileOutputStream != null) {
                     fileOutputStream.close();
                 }
-            } catch (IOException e) {
+            } catch (final IOException e) {
                 this.log.warning("Failed to clean the downloaded archive '"
                         + archiveUrl.toExternalForm() + "'", e);
             }
         }
-        return url;
     }
 
 }
