1 23 package com.sun.enterprise.tools.admingui.servlet; 24 25 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 26 import com.sun.enterprise.admin.common.JMXFileTransfer; 27 28 import java.io.File ; 29 import java.io.FileInputStream ; 30 import java.io.InputStream ; 31 32 import javax.servlet.ServletRequest ; 33 34 35 38 public class ClientStubsContentSource implements DownloadServlet.ContentSource { 39 40 47 public String getId() { 48 return "clientStubs"; } 50 51 58 public InputStream getInputStream(DownloadServlet.Context ctx) { 59 ctx.setAttribute(DownloadServlet.EXTENSION, "jar"); 62 ServletRequest request = ctx.getServletRequest(); 64 String appName = request.getParameter("appName"); if ((appName == null) || (appName.trim().length() == 0)) { 66 appName = request.getParameter("appClientName"); } 68 69 String tmpFilePath = null; 71 InputStream tmpFile = null; 72 try { 73 tmpFilePath = new JMXFileTransfer(MBeanUtil.getMBeanServer()) 74 .downloadClientStubs( 75 appName, 76 System.getProperty("java.io.tmpdir")); tmpFile = new FileInputStream (tmpFilePath); 78 } catch (Exception ex) { 79 throw new RuntimeException (ex); 80 } 81 82 ctx.setAttribute("tmpFilePath", tmpFilePath); ctx.setAttribute("tmpFile", tmpFile); 86 return tmpFile; 88 } 89 90 95 public void cleanUp(DownloadServlet.Context ctx) { 96 String tmpFilePath = 98 (String ) ctx.getAttribute("tmpFilePath"); InputStream tmpFile = 100 (InputStream ) ctx.getAttribute("tmpFile"); 102 if (tmpFile != null) { 104 try { 105 tmpFile.close(); 106 } catch (Exception ex) { 107 } 109 } 110 111 if (tmpFilePath != null) { 113 File file = new File (tmpFilePath); 114 try { 115 file.delete(); 116 } catch (Exception ex) { 117 } 119 } 120 121 ctx.removeAttribute("tmpFilePath"); ctx.removeAttribute("tmpFile"); } 125 126 133 public long getLastModified(DownloadServlet.Context context) { 134 return -1; 135 } 136 } 137 | Popular Tags |