1 package com.quadcap.app.qed; 2 3 40 41 import java.io.IOException ; 42 import java.io.OutputStream ; 43 import java.io.OutputStreamWriter ; 44 45 import java.util.zip.GZIPOutputStream ; 46 47 import java.sql.Connection ; 48 49 import javax.servlet.ServletConfig ; 50 import javax.servlet.ServletException ; 51 52 import javax.servlet.http.HttpServlet ; 53 import javax.servlet.http.HttpServletRequest ; 54 import javax.servlet.http.HttpServletResponse ; 55 import javax.servlet.http.HttpSession ; 56 57 import com.quadcap.sql.tools.XmlDump; 58 59 import com.quadcap.util.Debug; 60 61 65 66 public class XmlDumpServlet extends HttpServlet { 67 74 public void init(ServletConfig config) throws ServletException { 75 super.init(config); 76 } 77 78 89 protected void service(HttpServletRequest req, HttpServletResponse res) 90 throws ServletException , IOException 91 { 92 try { 93 HttpSession session = req.getSession(true); 94 if (session == null) throw new ServletException ("No session"); 95 AdminSession admin = 96 (AdminSession)session.getValue("admin"); 97 if (admin == null) 98 throw new ServletException ("no admin session"); 99 res.setHeader("Content-Disposition", 100 "attachment; filename=\"dumpdb.xml.gz\""); 101 String dbName = req.getParameter("dbName"); 102 if (dbName == null) { 103 throw new ServletException ("no dbName"); 104 } 105 OutputStream w = res.getOutputStream(); 106 GZIPOutputStream gz = new GZIPOutputStream (w); 107 OutputStreamWriter ow = new OutputStreamWriter (gz); 108 Connection conn = admin.getConnection(dbName); 109 XmlDump dump = new XmlDump(conn); 110 dump.dumpTables(ow); 111 gz.finish(); 112 ow.flush(); 113 } catch (Exception e) { 114 Debug.print(e); 115 res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 116 e.toString()); 117 } 118 } 119 } 120 | Popular Tags |