teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5861: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5861: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.server; raimund@2494: teichmann@5835: import org.dive4elements.artifacts.common.utils.XMLUtils; teichmann@5835: import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; teichmann@5835: import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; teichmann@5835: import org.dive4elements.artifacts.httpclient.http.HttpClient; teichmann@5835: import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; sascha@2497: sascha@2497: import java.io.ByteArrayOutputStream; christian@5008: import java.io.IOException; sascha@2497: import java.io.InputStream; christian@5008: import java.io.PrintWriter; raimund@2494: raimund@2494: import javax.servlet.http.HttpServlet; raimund@2494: import javax.servlet.http.HttpServletRequest; raimund@2494: import javax.servlet.http.HttpServletResponse; raimund@2494: sascha@2497: import org.apache.commons.codec.binary.Base64; sascha@2497: import org.apache.commons.fileupload.FileItemIterator; sascha@2497: import org.apache.commons.fileupload.FileItemStream; sascha@2497: import org.apache.commons.fileupload.servlet.ServletFileUpload; sascha@2497: import org.apache.log4j.Logger; sascha@2497: import org.w3c.dom.Document; sascha@2497: import org.w3c.dom.Element; raimund@2494: raimund@2494: public class FileUploadServiceImpl raimund@2494: extends HttpServlet raimund@2494: { raimund@2494: private static final Logger logger = Logger.getLogger(FileUploadServiceImpl.class); raimund@2494: raimund@2494: @Override raimund@2494: protected void doPost(HttpServletRequest req, HttpServletResponse resp) { raimund@2494: logger.debug("handling post request."); raimund@2494: raimund@2494: String url = getServletContext().getInitParameter("server-url"); raimund@2494: christian@4632: Document request = createFileXML(req); raimund@2494: raimund@2494: if (request == null) { raimund@2494: return; raimund@2494: } raimund@2494: HttpClient client = new HttpClientImpl(url); raimund@2494: raimund@2494: try { raimund@2494: Document result = client.callService(url, "fileupload", request); raimund@2494: christian@5008: PrintWriter respWriter = resp.getWriter(); christian@5008: respWriter.write(""); christian@5008: respWriter.write("