NIFI-317:

- Code clean up. Earlier versions of this used a GET request which required the img be url encoded. Converted to using POST due to URL length limitations but left the encoding code in place.
This commit is contained in:
Matt Gilman 2015-02-04 10:02:51 -05:00
parent 3a0cb2d634
commit ed53b46b7a
3 changed files with 7 additions and 13 deletions

View File

@ -18,7 +18,6 @@ package org.apache.nifi.web.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@ -44,10 +43,10 @@ public class DownloadSvg extends HttpServlet {
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final String rawSvg = request.getParameter("svg");
final String svg = request.getParameter("svg");
// ensure the image markup has been included
if (rawSvg == null) {
if (svg == null) {
// set the response status
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
@ -59,9 +58,6 @@ public class DownloadSvg extends HttpServlet {
}
try {
// get the svg and decode it, +'s need to be converted
final String svg = URLDecoder.decode(rawSvg.replace("+", "%2B"), "UTF-8");
if (logger.isDebugEnabled()) {
logger.debug(svg);
}

View File

@ -406,21 +406,19 @@ nf.Common = {
}()),
/**
* Creates a form inline in order to submit the specified params to the specified URL
* using the specified method.
* Creates a form inline in order to post the specified params to the specified URL.
*
* @param {string} method The method to use
* @param {string} url The URL
* @param {object} params An object with the params to include in the submission
*/
submit: function (method, url, params) {
post: function (url, params) {
// temporarily override beforeunload
var previousBeforeUnload = window.onbeforeunload;
window.onbeforeunload = null;
// create a form for submission
var form = $('<form></form>').attr({
'method': method,
'method': 'POST',
'action': url,
'style': 'display: none;'
});

View File

@ -1287,9 +1287,9 @@ nf.ProvenanceLineage = (function () {
svg = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' + svg;
// send to server to initiate download... client side only support is too browser specific at this point
nf.Common.submit('POST', './download-svg', {
nf.Common.post('./download-svg', {
'filename': 'provenance',
'svg': encodeURIComponent(svg)
'svg': svg
});
});