Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/FileUploadServiceImpl.java @ 5086:4f65d833680f dami
Merge Default onto Dami branch.
Dami is now temporarily a public merge branch to fix problems
created by the merge.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 25 Feb 2013 11:50:13 +0100 |
parents | 04ccec566689 |
children |
comparison
equal
deleted
inserted
replaced
5085:4f46679e13d0 | 5086:4f65d833680f |
---|---|
5 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; | 5 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
6 import de.intevation.artifacts.httpclient.http.HttpClient; | 6 import de.intevation.artifacts.httpclient.http.HttpClient; |
7 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | 7 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
8 | 8 |
9 import java.io.ByteArrayOutputStream; | 9 import java.io.ByteArrayOutputStream; |
10 import java.io.IOException; | |
10 import java.io.InputStream; | 11 import java.io.InputStream; |
12 import java.io.PrintWriter; | |
11 | 13 |
12 import javax.servlet.http.HttpServlet; | 14 import javax.servlet.http.HttpServlet; |
13 import javax.servlet.http.HttpServletRequest; | 15 import javax.servlet.http.HttpServletRequest; |
14 import javax.servlet.http.HttpServletResponse; | 16 import javax.servlet.http.HttpServletResponse; |
15 | 17 |
26 { | 28 { |
27 private static final Logger logger = Logger.getLogger(FileUploadServiceImpl.class); | 29 private static final Logger logger = Logger.getLogger(FileUploadServiceImpl.class); |
28 | 30 |
29 @Override | 31 @Override |
30 protected void doPost(HttpServletRequest req, HttpServletResponse resp) { | 32 protected void doPost(HttpServletRequest req, HttpServletResponse resp) { |
31 processPost(req, resp); | |
32 } | |
33 | |
34 | |
35 protected void processPost(HttpServletRequest req, HttpServletResponse resp) { | |
36 logger.debug("handling post request."); | 33 logger.debug("handling post request."); |
37 | 34 |
38 String url = getServletContext().getInitParameter("server-url"); | 35 String url = getServletContext().getInitParameter("server-url"); |
39 | 36 |
40 Document request = createFileXML(req); | 37 Document request = createFileXML(req); |
45 HttpClient client = new HttpClientImpl(url); | 42 HttpClient client = new HttpClientImpl(url); |
46 | 43 |
47 try { | 44 try { |
48 Document result = client.callService(url, "fileupload", request); | 45 Document result = client.callService(url, "fileupload", request); |
49 | 46 |
47 PrintWriter respWriter = resp.getWriter(); | |
48 respWriter.write("<html><link href='FLYS.css' rel='stylesheet' type='text/css'>"); | |
49 respWriter.write("<body><div style='font-face: Arial,Verdana,sans-serif; font-size: 11px'>"); | |
50 | |
50 if (result == null) { | 51 if (result == null) { |
51 logger.warn("FileUpload service returned no result."); | 52 logger.warn("FileUpload service returned no result."); |
53 respWriter.write("FileUpload service returned no result"); | |
52 } | 54 } |
55 else { | |
56 String status = result.getElementsByTagName("status") | |
57 .item(0).getTextContent(); | |
58 respWriter.write(status); | |
59 } | |
60 | |
61 respWriter.write("</div></body></html>"); | |
62 respWriter.flush(); | |
53 | 63 |
54 return; | 64 return; |
55 } | 65 } |
56 catch (ConnectionException ce) { | 66 catch (ConnectionException ce) { |
57 logger.error(ce, ce); | 67 logger.error(ce, ce); |
68 } | |
69 catch (IOException e) { | |
70 logger.error(e, e); | |
58 } | 71 } |
59 } | 72 } |
60 | 73 |
61 | 74 |
62 protected Document createFileXML(HttpServletRequest req) { | 75 protected Document createFileXML(HttpServletRequest req) { |
65 try{ | 78 try{ |
66 FileItemIterator iter = upload.getItemIterator(req); | 79 FileItemIterator iter = upload.getItemIterator(req); |
67 | 80 |
68 while (iter.hasNext()) { | 81 while (iter.hasNext()) { |
69 FileItemStream item = iter.next(); | 82 FileItemStream item = iter.next(); |
70 | |
71 String name = item.getFieldName(); | |
72 InputStream stream = item.openStream(); | 83 InputStream stream = item.openStream(); |
73 | 84 |
74 // Process the input stream | 85 // Process the input stream |
75 ByteArrayOutputStream out = new ByteArrayOutputStream(); | 86 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
76 int len; | 87 int len; |