view flys-client/src/main/java/de/intevation/flys/client/server/ExportServiceImpl.java @ 4421:0b0f415203f0

Add new Filter class to change caching Add new Filter class to avoid caching of GWT nocache files in browsers and http proxies. The new Filter class NoCacheFilter sets http headers to stop the proxies and browesers from storing the nocache files.
author Björn Ricks <bjoern.ricks@intevation.de>
date Tue, 06 Nov 2012 13:32:06 +0100
parents def13f23bb27
children 94b95e002fb9
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 org.w3c.dom.Element;

import org.apache.log4j.Logger;

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.common.utils.XMLUtils;

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
{
    private static final Logger logger =
        Logger.getLogger(ExportServiceImpl.class);


    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        logger.info("ExportServiceImpl.doGet");

        try {
            OutputStream out = resp.getOutputStream();

            String url    = getServletContext().getInitParameter("server-url");
            String uuid   = req.getParameter("uuid");
            String mode   = req.getParameter("mode");
            String type   = req.getParameter("type");
            String locale = req.getParameter("locale");
            String km     = req.getParameter("km");
            String fn     = mode + "." + type;

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

            if (logger.isDebugEnabled()) {
                logger.debug("Request " + type + " export.");
            }

            Document attr = null;
            if (km != null && km.length() > 0) {
                attr = XMLUtils.newDocument();
                XMLUtils.ElementCreator ec =
                        new XMLUtils.ElementCreator(attr, null, null);
                Element e = ec.create("km");
                e.setTextContent(km);
                attr.appendChild(e);
            }
            Document request = ClientProtocolUtils.newOutCollectionDocument(
                uuid, mode, type, attr);
            HttpClient client = new HttpClientImpl(url, locale);
            client.collectionOut(request, uuid, mode, out);

            out.close();
            out.flush();
        }
        catch (IOException ioe) {
            logger.error(ioe, ioe);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org