You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by wo...@apache.org on 2009/09/08 11:33:23 UTC

svn commit: r812414 - /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/portlet/deployer/impl/JetspeedPortletDeployer.java

Author: woonsan
Date: Tue Sep  8 09:33:22 2009
New Revision: 812414

URL: http://svn.apache.org/viewvc?rev=812414&view=rev
Log:
Fixing typo of messages and some clean up with commons-io's IOUtils#copy() method.

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/portlet/deployer/impl/JetspeedPortletDeployer.java

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/portlet/deployer/impl/JetspeedPortletDeployer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/portlet/deployer/impl/JetspeedPortletDeployer.java?rev=812414&r1=812413&r2=812414&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/portlet/deployer/impl/JetspeedPortletDeployer.java (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/portlet/deployer/impl/JetspeedPortletDeployer.java Tue Sep  8 09:33:22 2009
@@ -16,8 +16,8 @@
  */
 package org.apache.jetspeed.portlets.rpad.portlet.deployer.impl;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -27,6 +27,7 @@
 import java.net.URL;
 import java.util.Calendar;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jetspeed.deployment.DeploymentException;
 import org.apache.jetspeed.deployment.DeploymentManager;
 import org.apache.jetspeed.deployment.DeploymentStatus;
@@ -37,6 +38,8 @@
 
 public class JetspeedPortletDeployer implements PortletDeployer
 {
+    private static final long serialVersionUID = 1L;
+    
     /**
      * Logger for this class
      */
@@ -86,7 +89,7 @@
         public void run()
         {
             status = DEPLOYING;
-            setMessage("Stat deploying");
+            setMessage("Start deploying");
             try
             {
                 startTime = Calendar.getInstance().getTimeInMillis();
@@ -95,13 +98,32 @@
                     String binaryUrl = portletApplication.getBinaryUrl();
                     if (binaryUrl != null && !binaryUrl.equals(""))
                     {
-                        setMessage("Stat dowloading from " + binaryUrl);
+                        setMessage("Start dowloading from " + binaryUrl);
+                        
+                        URL targetURL = null;
+                        InputStream is = null;
+                        
                         File targetFile = null;
+                        OutputStream os = null;
+                        BufferedOutputStream bos = null;
+                        
                         try
                         {
+                            targetURL = new URL(portletApplication.getBinaryUrl());
+                            is = targetURL.openStream();
+                            
                             File tempFile = File.createTempFile("rpad_", "." + portletApplication.getPackaging());
-                            FileOutputStream out = new FileOutputStream(tempFile);
-                            drain(getInputStream(portletApplication.getBinaryUrl()), out);
+                            os = new FileOutputStream(tempFile);
+                            bos = new BufferedOutputStream(os);
+                            
+                            // Commons IO's IOUtils#copy() method buffers the input internally.
+                            IOUtils.copy(is, bos);
+                            
+                            bos.close();
+                            bos = null;
+                            is.close();
+                            is = null;
+                            
                             try
                             {
                                 targetFile = new File(tempFile.getParentFile(), portletApplication.getArtifactId() + "." + portletApplication.getPackaging());
@@ -111,7 +133,9 @@
                             {
                                 targetFile = tempFile;
                             }
+                            
                             setMessage(portletApplication.getName() + " deploying start");
+                            
                             if (getDeploymentManager().deploy(targetFile).getStatus() == DeploymentStatus.STATUS_OKAY)
                             {
                                 log.info(portletApplication.getName() + " was deployed.");
@@ -123,6 +147,11 @@
                                 log.error("Could not deploy " + portletApplication.getName());
                             }
                         }
+                        catch (MalformedURLException e)
+                        {
+                            setMessage("Malformed url: " + binaryUrl);
+                            log.error(e.getMessage(), e);
+                        }
                         catch (FileNotFoundException e)
                         {
                             setMessage("download fail from from " + binaryUrl);
@@ -138,6 +167,22 @@
                             setMessage("download fail from from " + binaryUrl);
                             log.error(e.getMessage(), e);
                         }
+                        finally
+                        {
+                            if (bos != null)
+                            {
+                                try { bos.close(); } catch (Exception ce) { }
+                            }
+                            if (os != null)
+                            {
+                                try { os.close(); } catch (Exception ce) { }
+                            }
+                            if (is != null)
+                            {
+                                try { is.close(); } catch (Exception ce) { }
+                            }
+                        }
+                        
                         if (targetFile != null && targetFile.exists())
                         {
                             targetFile.delete();
@@ -209,74 +254,6 @@
         }
     }
 
-    protected void drain(InputStream in, OutputStream out) throws IOException
-    {
-        try
-        {
-            byte[] buf = new byte[8192];
-            int len = in.read(buf);
-            while (len != -1)
-            {
-                out.write(buf, 0, len);
-                len = in.read(buf);
-            }
-            out.flush();
-        }
-        catch (IOException e)
-        {
-            throw e;
-        }
-        finally
-        {
-            try
-            {
-                out.close();
-            }
-            catch (IOException e)
-            {
-            }
-            try
-            {
-                in.close();
-            }
-            catch (IOException e)
-            {
-            }
-        }
-    }
-
-    protected InputStream getInputStream(String path)
-    {
-        if (path.startsWith("http:") || path.startsWith("https:"))
-        {
-            try
-            {
-                URL url = new URL(path);
-                return url.openStream();
-            }
-            catch (MalformedURLException e)
-            {
-                log.error("Wrong url: " + path, e);
-            }
-            catch (IOException e)
-            {
-                log.error("Could not load " + path, e);
-            }
-        }
-        else if (path.startsWith("file:"))
-        {
-            try
-            {
-                return new FileInputStream(new File(path.substring(5)));
-            }
-            catch (FileNotFoundException e)
-            {
-                log.error("Could not load " + path, e);
-            }
-        }
-        return null;
-    }
-
     public String getMessage()
     {
         return message;



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org