Revision 26635
tmp/trunk/servidor/WPS_Callejero_Server/DownloadWPSResults/src/es/logex/tigris/addins/DownloaderServlet.java | ||
---|---|---|
1 |
package es.logex.tigris.addins; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.IOException; |
|
6 |
|
|
7 |
import javax.servlet.ServletConfig; |
|
8 |
import javax.servlet.ServletException; |
|
9 |
import javax.servlet.ServletOutputStream; |
|
10 |
import javax.servlet.http.HttpServletRequest; |
|
11 |
import javax.servlet.http.HttpServletResponse; |
|
12 |
|
|
13 |
import org.omg.CORBA_2_3.portable.OutputStream; |
|
14 |
|
|
15 |
/** |
|
16 |
* Servlet implementation class for Servlet: DownloaderServlet |
|
17 |
* |
|
18 |
*/ |
|
19 |
public class DownloaderServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { |
|
20 |
static final long serialVersionUID = 1L; |
|
21 |
private static String absoluteFSPath = null; |
|
22 |
private boolean deleteAfeterDownload = false; |
|
23 |
/* (non-Java-doc) |
|
24 |
* @see javax.servlet.http.HttpServlet#HttpServlet() |
|
25 |
*/ |
|
26 |
public DownloaderServlet() { |
|
27 |
super(); |
|
28 |
} |
|
29 |
|
|
30 |
/* (non-Java-doc) |
|
31 |
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
|
32 |
*/ |
|
33 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
|
34 |
// TODO Auto-generated method stub |
|
35 |
processDownload(request, response); |
|
36 |
|
|
37 |
|
|
38 |
} |
|
39 |
|
|
40 |
private void processDownload(HttpServletRequest request, |
|
41 |
HttpServletResponse response) throws IOException { |
|
42 |
String file = request.getParameter("file"); |
|
43 |
if(file == null) |
|
44 |
{ |
|
45 |
response.sendError(HttpServletResponse.SC_BAD_REQUEST); |
|
46 |
return; |
|
47 |
} |
|
48 |
FileInputStream fin = null; |
|
49 |
File absoluteFile = null; |
|
50 |
try |
|
51 |
{ |
|
52 |
absoluteFile = new File(new File(absoluteFSPath),file); |
|
53 |
fin = new FileInputStream(absoluteFile); |
|
54 |
long fLen = absoluteFile.length(); |
|
55 |
response.setContentType("text/xml;subtype=gml/2.1.2"); |
|
56 |
response.setContentLength((int)fLen); |
|
57 |
ServletOutputStream os = response.getOutputStream(); |
|
58 |
int len=0; |
|
59 |
byte [] data = new byte[10240]; |
|
60 |
try |
|
61 |
{ |
|
62 |
while ( (len=fin.read(data)) > 0) |
|
63 |
{ |
|
64 |
os.write(data,0,len); |
|
65 |
} |
|
66 |
|
|
67 |
os.flush(); |
|
68 |
} |
|
69 |
catch(IOException ex) |
|
70 |
{ |
|
71 |
|
|
72 |
} |
|
73 |
fin.close(); |
|
74 |
|
|
75 |
} |
|
76 |
catch(Exception ex) |
|
77 |
{ |
|
78 |
response.sendError(HttpServletResponse.SC_NOT_FOUND); |
|
79 |
return; |
|
80 |
} |
|
81 |
if(absoluteFile!=null) |
|
82 |
{ |
|
83 |
absoluteFile.delete(); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public void init(ServletConfig config) throws ServletException { |
|
89 |
// TODO Auto-generated method stub |
|
90 |
super.init(config); |
|
91 |
absoluteFSPath = config.getInitParameter("absoluteFSPath"); |
|
92 |
if(absoluteFSPath == null) |
|
93 |
{ |
|
94 |
throw new ServletException("Me falta el parametro requerido 'absoluteFSPath'"); |
|
95 |
} |
|
96 |
|
|
97 |
String strDeleteAfterDownload = config.getInitParameter("deleteAfterDownload"); |
|
98 |
deleteAfeterDownload = Boolean.parseBoolean(strDeleteAfterDownload); |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
} |
tmp/trunk/servidor/WPS_Callejero_Server/DownloadWPSResults/WebContent/META-INF/MANIFEST.MF | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Class-Path: |
|
3 |
|
tmp/trunk/servidor/WPS_Callejero_Server/DownloadWPSResults/WebContent/WEB-INF/web.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> |
|
3 |
<web-app id="WebApp_ID"> |
|
4 |
<display-name>DownloadWPSResults</display-name> |
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
<servlet> |
|
9 |
<servlet-name>DownloaderServlet</servlet-name> |
|
10 |
<servlet-class>es.logex.tigris.addins.DownloaderServlet</servlet-class> |
|
11 |
|
|
12 |
<init-param> |
|
13 |
<param-name>absoluteFSPath</param-name> |
|
14 |
<param-value>/var/www/wps-files</param-value> |
|
15 |
<description>Ruta absoluta del fichero</description> |
|
16 |
</init-param> |
|
17 |
<init-param> |
|
18 |
<param-name>deleteAfterDownload</param-name> |
|
19 |
<param-value>true</param-value> |
|
20 |
<description>Si el parametro es true, borra los ficheros tras servirlos</description> |
|
21 |
</init-param> |
|
22 |
<load-on-startup>1</load-on-startup> |
|
23 |
</servlet> |
|
24 |
|
|
25 |
<servlet-mapping> |
|
26 |
<servlet-name>DownloaderServlet</servlet-name> |
|
27 |
<url-pattern>/getFile/*</url-pattern> |
|
28 |
</servlet-mapping> |
|
29 |
|
|
30 |
|
|
31 |
<welcome-file-list> |
|
32 |
<welcome-file>index.html</welcome-file> |
|
33 |
<welcome-file>index.htm</welcome-file> |
|
34 |
<welcome-file>index.jsp</welcome-file> |
|
35 |
<welcome-file>default.html</welcome-file> |
|
36 |
<welcome-file>default.htm</welcome-file> |
|
37 |
<welcome-file>default.jsp</welcome-file> |
|
38 |
</welcome-file-list> |
|
39 |
</web-app> |
tmp/trunk/servidor/WPS_Callejero_Server/DownloadWPSResults/.classpath | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="src" path="src"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
|
5 |
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5"/> |
|
6 |
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> |
|
7 |
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> |
|
8 |
<classpathentry kind="output" path="WebContent/WEB-INF/classes"/> |
|
9 |
</classpath> |
Also available in: Unified diff