commit dd9f33b5b28e8700e15b5169c4652e4d61270780 Author: Karsten Loesing karsten.loesing@gmx.net Date: Tue Apr 3 08:46:58 2012 +0200
Add graph parameters back to filenames.
Fixes #5555. --- .../torproject/ernie/web/GraphImageServlet.java | 10 +++++----- src/org/torproject/ernie/web/RObject.java | 18 ++++++++++++++++++ src/org/torproject/ernie/web/RObjectGenerator.java | 10 ++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/src/org/torproject/ernie/web/GraphImageServlet.java b/src/org/torproject/ernie/web/GraphImageServlet.java index 20d3297..88d5755 100644 --- a/src/org/torproject/ernie/web/GraphImageServlet.java +++ b/src/org/torproject/ernie/web/GraphImageServlet.java @@ -48,11 +48,11 @@ public class GraphImageServlet extends HttpServlet {
/* Request graph from R object generator, which either returns it from * its cache or asks Rserve to generate it. */ - byte[] graphBytes = rObjectGenerator.generateGraph(requestedGraph, + RObject graph = rObjectGenerator.generateGraph(requestedGraph, request.getParameterMap(), true);
/* Make sure that we have a graph to return. */ - if (graphBytes == null) { + if (graph == null || graph.getBytes() == null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } @@ -61,11 +61,11 @@ public class GraphImageServlet extends HttpServlet { BufferedOutputStream output = null; response.setContentType("image/png"); response.setHeader("Content-Length", - String.valueOf(graphBytes.length)); + String.valueOf(graph.getBytes().length)); response.setHeader("Content-Disposition", - "inline; filename="" + requestedGraph + ".png""); + "inline; filename="" + graph.getFileName() + """); output = new BufferedOutputStream(response.getOutputStream(), 1024); - output.write(graphBytes, 0, graphBytes.length); + output.write(graph.getBytes(), 0, graph.getBytes().length); output.flush(); output.close(); } diff --git a/src/org/torproject/ernie/web/RObject.java b/src/org/torproject/ernie/web/RObject.java new file mode 100644 index 0000000..4ee5cdc --- /dev/null +++ b/src/org/torproject/ernie/web/RObject.java @@ -0,0 +1,18 @@ +/* Copyright 2011, 2012 The Tor Project + * See LICENSE for licensing information */ +package org.torproject.ernie.web; + +public class RObject { + private byte[] bytes; + private String fileName; + public RObject(byte[] bytes, String fileName) { + this.bytes = bytes; + this.fileName = fileName; + } + public String getFileName() { + return fileName; + } + public byte[] getBytes() { + return bytes; + } +} diff --git a/src/org/torproject/ernie/web/RObjectGenerator.java b/src/org/torproject/ernie/web/RObjectGenerator.java index 3482dce..005da85 100644 --- a/src/org/torproject/ernie/web/RObjectGenerator.java +++ b/src/org/torproject/ernie/web/RObjectGenerator.java @@ -137,7 +137,7 @@ public class RObjectGenerator implements ServletContextListener { /* Nothing to do. */ }
- public byte[] generateGraph(String requestedGraph, Map parameterMap, + public RObject generateGraph(String requestedGraph, Map parameterMap, boolean checkCache) { Map<String, String[]> checkedParameters = GraphParameterChecker. getInstance().checkParameters(requestedGraph, parameterMap); @@ -172,7 +172,13 @@ public class RObjectGenerator implements ServletContextListener { String imageFilename = imageFilenameBuilder.toString(); rQueryBuilder.append("path = '%s')"); String rQuery = rQueryBuilder.toString(); - return this.generateGraph(rQuery, imageFilename, checkCache); + byte[] graphBytes = this.generateGraph(rQuery, imageFilename, + checkCache); + if (graphBytes != null) { + return new RObject(graphBytes, imageFilename); + } else { + return null; + } }
/* Generate a graph using the given R query that has a placeholder for