ingo@78: package de.intevation.flys.client.server; ingo@78: ingo@78: import java.io.OutputStream; ingo@78: import java.io.IOException; ingo@549: import java.util.HashMap; ingo@549: import java.util.Map; ingo@78: ingo@78: import org.w3c.dom.Document; ingo@78: ingo@78: import javax.servlet.http.HttpServlet; ingo@78: import javax.servlet.http.HttpServletRequest; ingo@78: import javax.servlet.http.HttpServletResponse; ingo@78: ingo@213: import de.intevation.artifacts.common.utils.ClientProtocolUtils; ingo@213: ingo@78: import de.intevation.artifacts.httpclient.http.HttpClient; ingo@78: import de.intevation.artifacts.httpclient.http.HttpClientImpl; ingo@78: ingo@78: ingo@78: /** ingo@78: * This service is used to request a chart from the artifact server. The ingo@78: * response is directed directly to the output stream, so the image that is ingo@78: * retrieved is displayed in the UI afterwards. ingo@78: * ingo@78: * @author Ingo Weinzierl ingo@78: */ ingo@78: public class ChartOutputServiceImpl ingo@78: extends HttpServlet ingo@78: { ingo@78: public void doGet(HttpServletRequest req, HttpServletResponse resp) { ingo@78: System.out.println("ChartOutputServiceImpl.doGet"); ingo@78: ingo@78: try { ingo@78: OutputStream out = resp.getOutputStream(); ingo@78: ingo@78: String serverUrl = req.getParameter("server"); ingo@78: String uuid = req.getParameter("uuid"); ingo@213: String type = req.getParameter("type"); ingo@254: String locale = req.getParameter("locale"); ingo@78: ingo@213: Document request = ClientProtocolUtils.newOutCollectionDocument( ingo@549: uuid, type, type, ingo@549: ChartServiceHelper.getChartAttributes(prepareChartAttributes(req))); ingo@78: ingo@254: HttpClient client = new HttpClientImpl(serverUrl, locale); ingo@213: client.collectionOut(request, uuid, "chart", out); ingo@78: ingo@78: out.close(); ingo@78: out.flush(); ingo@78: } ingo@78: catch (IOException ioe) { ingo@549: ioe.printStackTrace(); ingo@78: System.err.println(ioe.getMessage()); ingo@78: } ingo@280: catch (Exception e) { ingo@549: e.printStackTrace(); ingo@280: System.err.println(e.getMessage()); ingo@280: } ingo@280: } ingo@280: ingo@280: ingo@549: protected Map prepareChartAttributes(HttpServletRequest req) { ingo@549: Map attr = new HashMap(); ingo@280: ingo@549: Map params = req.getParameterMap(); ingo@542: ingo@549: attr.put("width", req.getParameter("width")); ingo@549: attr.put("height", req.getParameter("height")); ingo@549: attr.put("minx", req.getParameter("minx")); ingo@549: attr.put("maxx", req.getParameter("maxx")); ingo@549: attr.put("miny", req.getParameter("miny")); ingo@549: attr.put("maxy", req.getParameter("maxy")); ingo@542: ingo@549: return attr; ingo@78: } ingo@78: } ingo@280: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :