1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.deployment.web;
35
36 import java.io.IOException;
37
38 import javax.servlet.ServletException;
39 import javax.servlet.http.HttpServlet;
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
42
43 import fr.paris.lutece.plugins.deployment.business.Application;
44 import fr.paris.lutece.plugins.deployment.business.CommandResult;
45 import fr.paris.lutece.plugins.deployment.business.ServerApplicationInstance;
46 import fr.paris.lutece.plugins.deployment.service.DeploymentPlugin;
47 import fr.paris.lutece.plugins.deployment.service.IApplicationService;
48 import fr.paris.lutece.plugins.deployment.service.IFtpService;
49 import fr.paris.lutece.plugins.deployment.service.IServerApplicationService;
50 import fr.paris.lutece.plugins.deployment.util.ConstanteUtils;
51 import fr.paris.lutece.plugins.deployment.util.DeploymentUtils;
52 import fr.paris.lutece.portal.service.plugin.Plugin;
53 import fr.paris.lutece.portal.service.plugin.PluginService;
54 import fr.paris.lutece.portal.service.spring.SpringContextService;
55 import fr.paris.lutece.portal.service.util.AppLogService;
56
57
58
59
60 public class DownloadServlet extends HttpServlet
61 {
62
63
64
65 private static final long serialVersionUID = 8625639667629973645L;
66 private IFtpService _ftpService = SpringContextService.getBean( "deployment.FtpService" );
67 private IServerApplicationService _serverApplicationService = SpringContextService.getBean( "deployment.ServerApplicationService" );
68 private IApplicationService _applicationService = SpringContextService.getBean( "deployment.ApplicationService" );
69
70
71
72
73
74
75
76
77
78
79
80
81
82 @Override
83 protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
84 {
85
86 Plugin plugin = PluginService.getPlugin( DeploymentPlugin.PLUGIN_NAME );
87 String strCodeEnvironment = request.getParameter( ConstanteUtils.PARAM_CODE_ENVIRONMENT );
88 String strCodeServerApplicationInstanceSql = request.getParameter( ConstanteUtils.PARAM_CODE_SERVER_APPLICATION_INSTANCE_SQL );
89 String strCodeDatabase = request.getParameter( ConstanteUtils.PARAM_CODE_DATABASE );
90 String strIdApplication = request.getParameter( ConstanteUtils.PARAM_CODE_APPLICATION );
91 String strServerApplicationType = request.getParameter( ConstanteUtils.PARAM_SERVER_APPLICATION_TYPE );
92
93 Application application = _applicationService.getApplication( DeploymentUtils.getIntegerParameter( strIdApplication ), plugin );
94
95 ServerApplicationInstance serverApplicationInstance = _serverApplicationService.getServerApplicationInstance( application,
96 strCodeServerApplicationInstanceSql, strCodeEnvironment, strServerApplicationType, request.getLocale( ), false, false );
97
98 response.setHeader( "Content-Disposition", "attachment ;filename=\"dump_" + strCodeDatabase + ".sql\";" );
99 response.setHeader( "Pragma", "public" );
100 response.setHeader( "Expires", "0" );
101 response.setHeader( "Cache-Control", "must-revalidate,post-check=0,pre-check=0" );
102 response.setHeader( "Content-Type", "application/octet-stream" );
103
104 CommandResult commandResult = new CommandResult( );
105
106 try
107 {
108 _ftpService.getFile( response.getOutputStream( ), serverApplicationInstance.getFtpInfo( ),
109 DeploymentUtils.getDumpFileDirectory( application.getCode( ), serverApplicationInstance ) + "FROM_Z00-" + strCodeDatabase
110 + "-ALL_TABLES.sql", commandResult );
111 }
112 catch( IOException e )
113 {
114 AppLogService.error( e );
115 }
116
117 }
118
119
120
121
122
123
124 @Override
125 public String getServletInfo( )
126 {
127 return "Servlet serving files content from core_file and core_physical_file tables";
128 }
129 }