view flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java @ 78:9ca5160cf080

Added a service that builds up requests to retrieve chart images. Use this service to display charts in the ChartOutputTab. flys-client/trunk@1584 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 28 Mar 2011 10:45:45 +0000
parents
children 7ea004d0ffbc
line wrap: on
line source
package de.intevation.flys.client.server;

import java.io.OutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Document;

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

import de.intevation.artifacts.httpclient.http.HttpClient;
import de.intevation.artifacts.httpclient.http.HttpClientImpl;
import de.intevation.artifacts.httpclient.objects.Artifact;
import de.intevation.artifacts.httpclient.utils.ArtifactProtocolUtils;


/**
 * This service is used to request a chart from the artifact server. The
 * response is directed directly to the output stream, so the image that is
 * retrieved is displayed in the UI afterwards.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class ChartOutputServiceImpl
extends      HttpServlet
{
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("ChartOutputServiceImpl.doGet");

        try {
            OutputStream out = resp.getOutputStream();

            String serverUrl = req.getParameter("server");
            String uuid      = req.getParameter("uuid");
            String hash      = req.getParameter("hash");
            String width     = req.getParameter("width");
            String height    = req.getParameter("height");
            String target    = req.getParameter("target");
            String mimeType  = "image/png";

            Map opts = new HashMap();
            opts.put("width", width);
            opts.put("height", height);
            opts.put("mimeType", mimeType);
            opts.put("points", "false");

            Document chart = ArtifactProtocolUtils.createChartDocument(
                new Artifact(hash, uuid), opts);

            HttpClient client = new HttpClientImpl(serverUrl);
            client.out(new Artifact(uuid, hash), chart, target, out);

            out.close();
            out.flush();
        }
        catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }
    }
}

http://dive4elements.wald.intevation.org