You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2006/05/15 02:36:46 UTC

svn commit: r406476 - in /geronimo/branches/1.1/applications/welcome: ./ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/geronimo/ src/java/org/apache/geronimo/welcome/ src/webapp/ src/webapp/WEB-INF/

Author: ammulder
Date: Sun May 14 17:36:46 2006
New Revision: 406476

URL: http://svn.apache.org/viewcvs?rev=406476&view=rev
Log:
Auto-install routine for sample apps (GERONIMO-1900)
 - could use a nicer JSP and some AJAX (or any kind of) progress
   for the download process

Added:
    geronimo/branches/1.1/applications/welcome/src/java/
    geronimo/branches/1.1/applications/welcome/src/java/org/
    geronimo/branches/1.1/applications/welcome/src/java/org/apache/
    geronimo/branches/1.1/applications/welcome/src/java/org/apache/geronimo/
    geronimo/branches/1.1/applications/welcome/src/java/org/apache/geronimo/welcome/
    geronimo/branches/1.1/applications/welcome/src/java/org/apache/geronimo/welcome/AbsentSampleServlet.java   (with props)
    geronimo/branches/1.1/applications/welcome/src/webapp/sampleNotInstalled.jsp   (with props)
Modified:
    geronimo/branches/1.1/applications/welcome/project.xml
    geronimo/branches/1.1/applications/welcome/src/webapp/WEB-INF/web.xml
    geronimo/branches/1.1/applications/welcome/src/webapp/main.css

Modified: geronimo/branches/1.1/applications/welcome/project.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/welcome/project.xml?rev=406476&r1=406475&r2=406476&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/welcome/project.xml (original)
+++ geronimo/branches/1.1/applications/welcome/project.xml Sun May 14 17:36:46 2006
@@ -32,6 +32,21 @@
     </description>
 
     <dependencies>
+        <dependency>
+            <groupId>geronimo</groupId>
+            <artifactId>geronimo-kernel</artifactId>
+            <version>${pom.currentVersion}</version>
+        </dependency>
+        <dependency>
+            <groupId>geronimo</groupId>
+            <artifactId>geronimo-system</artifactId>
+            <version>${pom.currentVersion}</version>
+        </dependency>
+        <dependency>
+            <groupId>mx4j</groupId>
+            <artifactId>mx4j</artifactId>
+            <version>${mx4j_version}</version>
+        </dependency>
       <dependency>
             <groupId>ant</groupId>
             <artifactId>ant</artifactId>

Added: geronimo/branches/1.1/applications/welcome/src/java/org/apache/geronimo/welcome/AbsentSampleServlet.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/welcome/src/java/org/apache/geronimo/welcome/AbsentSampleServlet.java?rev=406476&view=auto
==============================================================================
--- geronimo/branches/1.1/applications/welcome/src/java/org/apache/geronimo/welcome/AbsentSampleServlet.java (added)
+++ geronimo/branches/1.1/applications/welcome/src/java/org/apache/geronimo/welcome/AbsentSampleServlet.java Sun May 14 17:36:46 2006
@@ -0,0 +1,129 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.welcome;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Set;
+import javax.security.auth.login.FailedLoginException;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.NoSuchConfigException;
+import org.apache.geronimo.kernel.config.LifecycleException;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.system.plugin.PluginInstaller;
+import org.apache.geronimo.system.plugin.PluginList;
+import org.apache.geronimo.system.plugin.PluginMetadata;
+import org.apache.geronimo.system.plugin.PluginRepositoryList;
+import org.apache.geronimo.system.plugin.DownloadResults;
+
+/**
+ * Stands in for servlets that are not yet installed, offering to install them.
+ *
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class AbsentSampleServlet extends HttpServlet {
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        String install = request.getParameter("install");
+        if(install != null && !install.equals("")) {
+            doInstall(request, response);
+        } else {
+            doMessage(request, response);
+        }
+    }
+
+    private void doMessage(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
+        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/sampleNotInstalled.jsp");
+        dispatcher.forward(request, response);
+    }
+
+    private void doInstall(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        Kernel kernel = KernelRegistry.getSingleKernel();
+        PluginInstaller installer = getPluginInstaller(kernel);
+        String moduleIdName = getInitParameter("moduleId");
+        moduleIdName = moduleIdName.replaceAll("SERVER", getServerType());
+        URL repo = getFirstPluginRepository(kernel);
+        PluginMetadata target = new PluginMetadata("Sample Application", null, "Samples", "A sample application",
+                                                   null, null, null, false, true);
+        target.setDependencies(new String[]{moduleIdName});
+        DownloadResults results = installer.install(new PluginList(new URL[]{repo, new URL("http://www.ibiblio.org/maven2/")},
+                                                    new PluginMetadata[]{target}), null, null);
+        if(results.isFailed()) {
+            throw new ServletException("Unable to install sample application", results.getFailure());
+        }
+        ConfigurationManager mgr = ConfigurationUtil.getConfigurationManager(kernel);
+        for (int i = 0; i < results.getInstalledConfigIDs().length; i++) {
+            Artifact artifact = results.getInstalledConfigIDs()[i];
+            if(mgr.isConfiguration(artifact)) {
+                try {
+                    if(!mgr.isLoaded(artifact)) {
+                        mgr.loadConfiguration(artifact);
+                    }
+                    if(!mgr.isRunning(artifact)) {
+                        mgr.startConfiguration(artifact);
+                    }
+                } catch (NoSuchConfigException e) {
+                    throw new ServletException("Unable to start sample application", e);
+                } catch (LifecycleException e) {
+                    throw new ServletException("Unable to start sample application", e);
+                }
+            }
+        }
+        response.sendRedirect(request.getContextPath()+request.getServletPath()+"/");
+    }
+
+    private String getServerType() {
+        return getServletContext().getServerInfo().toLowerCase().indexOf("jetty") > -1 ? "jetty" : "tomcat";
+    }
+
+    private PluginInstaller getPluginInstaller(Kernel kernel) throws ServletException {
+        Set installers = kernel.listGBeans(new AbstractNameQuery(PluginInstaller.class.getName()));
+        if(installers.size() == 0) {
+            throw new ServletException("Unable to install sample application; no plugin installer found");
+        }
+       return (PluginInstaller)kernel.getProxyManager().createProxy((AbstractName) installers.iterator().next(),
+                                                                    PluginInstaller.class);
+    }
+
+    private URL getFirstPluginRepository(Kernel kernel) throws ServletException {
+        Set installers = kernel.listGBeans(new AbstractNameQuery(PluginRepositoryList.class.getName()));
+        if(installers.size() == 0) {
+            throw new ServletException("Unable to install sample application; no plugin repository list found");
+        }
+        PluginRepositoryList repos = ((PluginRepositoryList) kernel.getProxyManager().createProxy((AbstractName) installers.iterator().next(),
+                PluginRepositoryList.class));
+
+        URL[] urls = repos.getRepositories();
+        if(urls.length == 0) {
+            repos.refresh();
+            urls = repos.getRepositories();
+            if(urls.length == 0) {
+                throw new ServletException("Unable to install sample applicatoin; unable to download repository list");
+            }
+        }
+        return urls[0];
+    }
+}

Propchange: geronimo/branches/1.1/applications/welcome/src/java/org/apache/geronimo/welcome/AbsentSampleServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/branches/1.1/applications/welcome/src/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/welcome/src/webapp/WEB-INF/web.xml?rev=406476&r1=406475&r2=406476&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/welcome/src/webapp/WEB-INF/web.xml (original)
+++ geronimo/branches/1.1/applications/welcome/src/webapp/WEB-INF/web.xml Sun May 14 17:36:46 2006
@@ -10,4 +10,46 @@
         Welcome to Geronimo
     </description>
 
+    <servlet>
+        <servlet-name>jsp_sample_installer</servlet-name>
+        <servlet-class>org.apache.geronimo.welcome.AbsentSampleServlet</servlet-class>
+        <init-param>
+            <param-name>moduleId</param-name>
+            <param-value>geronimo/jsp-examples-SERVER//car</param-value>
+        </init-param>
+    </servlet>
+
+    <servlet>
+        <servlet-name>servlet_sample_installer</servlet-name>
+        <servlet-class>org.apache.geronimo.welcome.AbsentSampleServlet</servlet-class>
+        <init-param>
+            <param-name>moduleId</param-name>
+            <param-value>geronimo/servlets-examples-SERVER//car</param-value>
+        </init-param>
+    </servlet>
+
+    <servlet>
+        <servlet-name>ldap_sample_installer</servlet-name>
+        <servlet-class>org.apache.geronimo.welcome.AbsentSampleServlet</servlet-class>
+        <init-param>
+            <param-name>moduleId</param-name>
+            <param-value>geronimo/ldap-demo-SERVER//car</param-value>
+        </init-param>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>jsp_sample_installer</servlet-name>
+        <url-pattern>/jsp-examples/*</url-pattern>
+    </servlet-mapping>
+
+    <servlet-mapping>
+        <servlet-name>servlet_sample_installer</servlet-name>
+        <url-pattern>/servlets-examples/*</url-pattern>
+    </servlet-mapping>
+
+    <servlet-mapping>
+        <servlet-name>ldap_sample_installer</servlet-name>
+        <url-pattern>/ldap-demo/*</url-pattern>
+    </servlet-mapping>
+
 </web-app>

Modified: geronimo/branches/1.1/applications/welcome/src/webapp/main.css
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/welcome/src/webapp/main.css?rev=406476&r1=406475&r2=406476&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/welcome/src/webapp/main.css (original)
+++ geronimo/branches/1.1/applications/welcome/src/webapp/main.css Sun May 14 17:36:46 2006
@@ -46,7 +46,7 @@
 
 .Logo
 {
-	background-image:url("images/head_left_754x86.gif");
+	background-image:url("/images/head_left_754x86.gif");
 	background-repeat: no-repeat;
 	width: 570px;
 	height: 86px;
@@ -60,7 +60,7 @@
 
 .LoginLogo
 {
-	background-image:url("images/head_left_login_586x86.gif");
+	background-image:url("/images/head_left_login_586x86.gif");
 	background-repeat: no-repeat;
 	width: 570px;
 	height: 86px;
@@ -74,7 +74,7 @@
 
 .WelcomeLogo
 {
-	background-image:url("images/welcome_head_570x86.gif");
+	background-image:url("/images/welcome_head_570x86.gif");
 	background-repeat: no-repeat;
 	width: 570px;
 	height: 86px;
@@ -88,7 +88,7 @@
 
 .Top
 {
-	background-image:url("images/head_bgstretch_1x86.gif");
+	background-image:url("/images/head_bgstretch_1x86.gif");
 	background-repeat: repeat-x;
 	height: 86px;
 	font-size: 11px;

Added: geronimo/branches/1.1/applications/welcome/src/webapp/sampleNotInstalled.jsp
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/welcome/src/webapp/sampleNotInstalled.jsp?rev=406476&view=auto
==============================================================================
--- geronimo/branches/1.1/applications/welcome/src/webapp/sampleNotInstalled.jsp (added)
+++ geronimo/branches/1.1/applications/welcome/src/webapp/sampleNotInstalled.jsp Sun May 14 17:36:46 2006
@@ -0,0 +1,53 @@
+<%--
+    Copyright 2005 The Apache Software Foundation
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+--%>
+<!-- $Rev: 357437 $ $Date: 2005-12-18 00:23:31 -0500 (Sun, 18 Dec 2005) $ -->
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/TR/REC-html40/strict.dtd">
+<%@ page session="false" %>
+<html>
+    <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+    <title>Apache Geronimo Sample Application</title>
+    <link rel="stylesheet" href="/main.css" type="text/css"/>
+</head>
+
+<body>
+
+<!-- Header -->
+<table width="100%">
+  <tr>
+    <td>
+      <table width="100%" height="86"  border="0" cellpadding="0" cellspacing="0">
+        <tr>
+          <td height="86" class="WelcomeLogo" border="0"></td>
+          <td height="86" class="Top"  border="0">&nbsp;</TD>
+        </tr>
+        <tr>
+          <td align="right" border="0">&nbsp;</td>
+          <td align="right" border="0"><b><%= application.getServerInfo() %>&nbsp;&nbsp;&nbsp;&nbsp;</b></td>
+        </tr>
+      </table>
+    </td>
+  </tr>
+</table>
+
+<br />
+
+<p>This sample has not been installed yet.  If this server can connect to the internet,
+<a href="?install=true">click here</a> to install and connect to the sample application.
+It will take a few minutes to download and install the sample and then load it.</p>
+
+</body>
+</html>

Propchange: geronimo/branches/1.1/applications/welcome/src/webapp/sampleNotInstalled.jsp
------------------------------------------------------------------------------
    svn:eol-style = native