QED Administrator Console

com/quadcap/app/qed/XmlDumpServlet.java

Go to the documentation of this file.
00001 package com.quadcap.app.qed; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.IOException; 00042 import java.io.OutputStream; 00043 import java.io.OutputStreamWriter; 00044 00045 import java.util.zip.GZIPOutputStream; 00046 00047 import java.sql.Connection; 00048 00049 import javax.servlet.ServletConfig; 00050 import javax.servlet.ServletException; 00051 00052 import javax.servlet.http.HttpServlet; 00053 import javax.servlet.http.HttpServletRequest; 00054 import javax.servlet.http.HttpServletResponse; 00055 import javax.servlet.http.HttpSession; 00056 00057 import com.quadcap.sql.tools.XmlDump; 00058 00059 import com.quadcap.util.Debug; 00060 00061 /** 00062 * 00063 * @author Stan Bailes 00064 */ 00065 00066 public class XmlDumpServlet extends HttpServlet { 00067 /** 00068 * Initialize this servlet 00069 * 00070 * @param config the servlet configuration object, containing my 00071 * initialization parameters 00072 * @exception ServletException if I can't initialize for some reason. 00073 */ 00074 public void init(ServletConfig config) throws ServletException { 00075 super.init(config); 00076 } 00077 00078 /** 00079 * Handle an incoming request. 00080 * 00081 * @param req HttpServletRequest that encapsulates the request to 00082 * the servlet 00083 * @param res HttpServletResponse that encapsulates the response 00084 * from the servlet 00085 * 00086 * @exception IOException if detected when handling the request 00087 * @exception ServletException if the request could not be handled 00088 */ 00089 protected void service(HttpServletRequest req, HttpServletResponse res) 00090 throws ServletException, IOException 00091 { 00092 try { 00093 HttpSession session = req.getSession(true); 00094 if (session == null) throw new ServletException("No session"); 00095 AdminSession admin = 00096 (AdminSession)session.getValue("admin"); 00097 if (admin == null) 00098 throw new ServletException("no admin session"); 00099 res.setHeader("Content-Disposition", 00100 "attachment; filename=\"dumpdb.xml.gz\""); 00101 String dbName = req.getParameter("dbName"); 00102 if (dbName == null) { 00103 throw new ServletException("no dbName"); 00104 } 00105 OutputStream w = res.getOutputStream(); 00106 GZIPOutputStream gz = new GZIPOutputStream(w); 00107 OutputStreamWriter ow = new OutputStreamWriter(gz); 00108 Connection conn = admin.getConnection(dbName); 00109 XmlDump dump = new XmlDump(conn); 00110 dump.dumpTables(ow); 00111 gz.finish(); 00112 ow.flush(); 00113 } catch (Exception e) { 00114 Debug.print(e); 00115 res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 00116 e.toString()); 00117 } 00118 } 00119 }