view flys-client/src/main/java/de/intevation/flys/client/server/ExportServiceImpl.java @ 274:71a7533555d0

Added a service to export data from the artifact server. flys-client/trunk@1900 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 11 May 2011 14:23:08 +0000
parents
children 8ea213bd8fba
line wrap: on
line source
package de.intevation.flys.client.server;

import java.io.OutputStream;
import java.io.IOException;

import org.w3c.dom.Document;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.intevation.artifacts.common.utils.ClientProtocolUtils;

import de.intevation.artifacts.httpclient.http.HttpClient;
import de.intevation.artifacts.httpclient.http.HttpClientImpl;


/**
 * This service is used to request a data export from the artifact server. The
 * response is directed directly to the output stream, so that a file dialog is
 * opened.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class ExportServiceImpl
extends      HttpServlet
{
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("ExportServiceImpl.doGet");

        try {
            OutputStream out = resp.getOutputStream();

            String serverUrl = req.getParameter("server");
            String uuid      = req.getParameter("uuid");
            String mode      = req.getParameter("mode");
            String type      = req.getParameter("type");
            String locale    = req.getParameter("locale");
            String fn        = mode + "." + type;

            resp.setHeader("Content-Disposition", "attachment;filename=" + fn);

            Document request = ClientProtocolUtils.newOutCollectionDocument(
                uuid, mode);

            HttpClient client = new HttpClientImpl(serverUrl, locale);
            client.collectionOut(request, uuid, mode, out);

            out.close();
            out.flush();
        }
        catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org