geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwo...@apache.org
Subject svn commit: r1153761 - in /geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard: DatabasePoolPortlet.java DriverDownloader.java
Date Thu, 04 Aug 2011 06:29:35 GMT
Author: rwonly
Date: Thu Aug  4 06:29:34 2011
New Revision: 1153761

URL: http://svn.apache.org/viewvc?rev=1153761&view=rev
Log:
GERONIMO-6102 Convert downloaded jdbc driver to OSGi bundle

Modified:
    geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
    geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java

Modified: geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java?rev=1153761&r1=1153760&r2=1153761&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
(original)
+++ geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DatabasePoolPortlet.java
Thu Aug  4 06:29:34 2011
@@ -96,6 +96,9 @@ import org.apache.geronimo.deployment.se
 import org.apache.geronimo.deployment.tools.loader.ConnectorDeployable;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.KernelRegistry;
 import org.apache.geronimo.kernel.config.ConfigurationManager;
 import org.apache.geronimo.kernel.config.ConfigurationUtil;
 import org.apache.geronimo.kernel.management.State;
@@ -107,6 +110,7 @@ import org.apache.geronimo.kernel.reposi
 import org.apache.geronimo.kernel.util.XmlUtil;
 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
 import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
+import org.apache.geronimo.system.plugin.PluginInstallerGBean;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -249,7 +253,7 @@ public class DatabasePoolPortlet extends
         PortletSession session = request.getPortletSession(true);
         DriverDownloader.DriverInfo[] results = (DriverDownloader.DriverInfo[]) session.getAttribute(DRIVER_SESSION_KEY,
                 PortletSession.APPLICATION_SCOPE);
-        if (results == null) {
+        if (results == null || results.length ==0) {
             DriverDownloader downloader = new DriverDownloader();
             try {
                 results = downloader.loadDriverInfo(new URL(DRIVER_INFO_URL));
@@ -335,14 +339,23 @@ public class DatabasePoolPortlet extends
             }
             if (found != null) {
                 data.jars = new String[]{found.getRepositoryURI()};
-                WriteableRepository repo = PortletManager.getCurrentServer(actionRequest).getWritableRepositories()[0];
-                final PortletSession session = actionRequest.getPortletSession();
-                ProgressInfo progressInfo = new ProgressInfo();
-                progressInfo.setMainMessage("Downloading " + found.getName());
-                session.setAttribute(ProgressInfo.PROGRESS_INFO_KEY, progressInfo, PortletSession.APPLICATION_SCOPE);
-                // Start the download monitoring
-                new Thread(new Downloader(found, progressInfo, repo)).start();
-                actionResponse.setRenderParameter(MODE_KEY, DOWNLOAD_STATUS_MODE);
+                try {
+                    PluginInstallerGBean installer = KernelRegistry.getSingleKernel().getGBean(PluginInstallerGBean.class);
+                    //WriteableRepository repo = PortletManager.getCurrentServer(actionRequest).getWritableRepositories()[0];
+                    final PortletSession session = actionRequest.getPortletSession();
+                    ProgressInfo progressInfo = new ProgressInfo();
+                    progressInfo.setMainMessage("Downloading " + found.getName());
+                    session.setAttribute(ProgressInfo.PROGRESS_INFO_KEY, progressInfo, PortletSession.APPLICATION_SCOPE);
+                    // Start the download monitoring
+                    new Thread(new Downloader(found, progressInfo, installer)).start();
+                    actionResponse.setRenderParameter(MODE_KEY, DOWNLOAD_STATUS_MODE);
+                } catch (GBeanNotFoundException e) {
+                    throw new PortletException(e);
+                } catch (InternalKernelException e) {
+                    throw new PortletException(e);
+                } catch (IllegalStateException e) {
+                    throw new PortletException(e);
+                }
             } else {
                 actionResponse.setRenderParameter(MODE_KEY, DOWNLOAD_MODE);
             }
@@ -440,20 +453,20 @@ public class DatabasePoolPortlet extends
     }
 
     private static class Downloader implements Runnable {
-        private WriteableRepository repo;
+        private PluginInstallerGBean installer;
         private DriverDownloader.DriverInfo driver;
         private ProgressInfo progressInfo;
 
-        public Downloader(DriverDownloader.DriverInfo driver, ProgressInfo progressInfo,
WriteableRepository repo) {
+        public Downloader(DriverDownloader.DriverInfo driver, ProgressInfo progressInfo,
PluginInstallerGBean installer) {
             this.driver = driver;
             this.progressInfo = progressInfo;
-            this.repo = repo;
+            this.installer = installer;
         }
 
         public void run() {
             DriverDownloader downloader = new DriverDownloader();
             try {
-                downloader.loadDriver(repo, driver, new FileWriteMonitor() {
+                downloader.loadDriver(installer, driver, new FileWriteMonitor() {
                     private int fileSize;
 
                     public void writeStarted(String fileDescription, int fileSize) {

Modified: geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java?rev=1153761&r1=1153760&r2=1153761&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java
(original)
+++ geronimo/server/trunk/plugins/system-database/sysdb-portlets/src/main/java/org/apache/geronimo/console/databasemanager/wizard/DriverDownloader.java
Thu Aug  4 06:29:34 2011
@@ -41,6 +41,9 @@ import org.slf4j.LoggerFactory;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
 import org.apache.geronimo.kernel.repository.WriteableRepository;
+import org.apache.geronimo.kernel.util.FileUtils;
+import org.apache.geronimo.kernel.util.IOUtils;
+import org.apache.geronimo.system.plugin.PluginInstallerGBean;
 
 /**
  * A utility that handles listing and downloading available JDBC driver JARs.
@@ -117,7 +120,7 @@ public class DriverDownloader {
     /**
      * Downloads a driver and loads it into the local repository.
      */
-    public void loadDriver(WriteableRepository repo, DriverInfo driver, FileWriteMonitor
monitor) throws IOException {
+    public void loadDriver(PluginInstallerGBean installer, DriverInfo driver, FileWriteMonitor
monitor) throws IOException {
         int urlIndex = 0;
         if (driver.urls.length > 1) {
             if (random == null) {
@@ -167,8 +170,7 @@ public class DriverDownloader {
                 if (entry == null) {
                     log.error("Cannot extract driver JAR " + driver.unzipPath + " from download
file " + url);
                 } else {
-                    in = jar.getInputStream(entry);
-                    repo.copyToRepository(in, (int)entry.getSize(), Artifact.create(uri),
monitor);
+                    install(installer, jar.getInputStream(entry), Artifact.create(uri));
                 }
             } finally {
                 if (jar != null) try {
@@ -183,9 +185,27 @@ public class DriverDownloader {
         } else {
             URLConnection con = url.openConnection();
             in = con.getInputStream();
-            repo.copyToRepository(in, con.getContentLength(), Artifact.create(uri), monitor);
+            install(installer, in, Artifact.create(uri));
         }
     }
+    
+    private void install(PluginInstallerGBean installer, InputStream is, Artifact artifact)
throws IOException{
+        // convert input stream to file
+        File file = File.createTempFile("geronimo-driver-to-install", "");
+        file.deleteOnExit();
+        OutputStream os = new FileOutputStream(file);
+        int bytesRead = 0;
+        byte[] buffer = new byte[8192];
+        while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
+            os.write(buffer, 0, bytesRead);
+        }
+        IOUtils.close(os);
+        IOUtils.close(is);
+        
+        // install
+        installer.installLibrary(file, artifact);
+    }
+    
 
     public static class DriverInfo implements Comparable, Serializable {
         private final static long serialVersionUID = -1202452382992975449L;



Mime
View raw message