001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.tomcat.installer;
018:
019: import static org.apache.openejb.tomcat.installer.Installer.Status.NONE;
020:
021: import javax.servlet.ServletConfig;
022: import javax.servlet.ServletException;
023: import javax.servlet.RequestDispatcher;
024: import javax.servlet.ServletOutputStream;
025: import javax.servlet.http.HttpServlet;
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028: import java.io.IOException;
029: import java.io.File;
030:
031: /**
032: * Installs OpenEJB into Tomcat.
033: * <p/>
034: * NOTE: This servlet can not use any classes from OpenEJB since it is installing OpenEJB itself.
035: */
036: public class InstallerServlet extends HttpServlet {
037: protected Paths paths;
038: protected Installer installer;
039: protected int attempts;
040: private ServletConfig servletConfig;
041:
042: public void init(ServletConfig servletConfig)
043: throws ServletException {
044: this .servletConfig = servletConfig;
045:
046: String path = servletConfig.getServletContext()
047: .getRealPath("/");
048:
049: File openejbWarDir = null;
050: if (path != null) {
051: openejbWarDir = new File(path);
052: }
053:
054: paths = new Paths(openejbWarDir);
055: installer = new Installer(paths);
056: }
057:
058: protected void doGet(HttpServletRequest httpServletRequest,
059: HttpServletResponse httpServletResponse)
060: throws ServletException, IOException {
061: doIt(httpServletRequest, httpServletResponse);
062: }
063:
064: protected void doPost(HttpServletRequest httpServletRequest,
065: HttpServletResponse httpServletResponse)
066: throws ServletException, IOException {
067: doIt(httpServletRequest, httpServletResponse);
068: }
069:
070: protected void doIt(HttpServletRequest req, HttpServletResponse res)
071: throws ServletException, IOException {
072: // if they clicked the install button...
073: if ("install".equalsIgnoreCase(req.getParameter("action"))) {
074: // If not already installed, try to install
075: if (installer.getStatus() == NONE) {
076: attempts++;
077:
078: paths.reset();
079: installer.reset();
080:
081: paths.setCatalinaHomeDir(req
082: .getParameter("catalinaHome"));
083: paths.setCatalinaBaseDir(req
084: .getParameter("catalinaBase"));
085: paths.setServerXmlFile(req.getParameter("serverXml"));
086:
087: if (paths.verify()) {
088: installer.installAll();
089: }
090: }
091:
092: // send redirect to avoid double post lameness
093: res.sendRedirect(req.getRequestURI());
094: } else {
095:
096: req.setAttribute("installer", installer);
097: req.setAttribute("paths", paths);
098: RequestDispatcher rd = servletConfig.getServletContext()
099: .getRequestDispatcher("/installer-view.jsp");
100: rd.forward(req, res);
101: }
102: }
103:
104: public void dump(ServletOutputStream out) throws IOException {
105: printFile(out, "Catalina home: ", paths.getCatalinaHomeDir());
106: printFile(out, "Catalina base: ", paths.getCatalinaBaseDir());
107: printFile(out, "Catalina server.xml: ", paths
108: .getServerXmlFile());
109: printFile(out, "Catalina conf: ", paths.getCatalinaConfDir());
110: printFile(out, "Catalina lib: ", paths.getCatalinaLibDir());
111: printFile(out, "Catalina bin: ", paths.getCatalinaBinDir());
112: printFile(out, "Catalina catalina.sh: ", paths
113: .getCatalinaShFile());
114: printFile(out, "Catalina catalina.bat: ", paths
115: .getCatalinaBatFile());
116: printFile(out, "OpenEJB lib: ", paths.getOpenEJBLibDir());
117: printFile(out, "OpenEJB loader jar: ", paths
118: .getOpenEJBTomcatLoaderJar());
119: printFile(out, "OpenEJB javaagent jar: ", paths
120: .getOpenEJBJavaagentJar());
121: }
122:
123: private void printFile(ServletOutputStream out, String description,
124: File file) throws IOException {
125: out.println(description + ":");
126: out.println(" " + file);
127: }
128: }
|