Skip to content

Commit

Permalink
NPE fix on run templates (in log.info message ;-)
Browse files Browse the repository at this point in the history
  • Loading branch information
kreinhard committed Oct 26, 2018
1 parent 58d133d commit 97d1a24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import de.reinhard.merlin.utils.Converter;
import de.reinhard.merlin.word.WordDocument;
import de.reinhard.merlin.word.templating.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.glassfish.jersey.media.multipart.ContentDisposition;
Expand Down Expand Up @@ -90,7 +89,7 @@ public Response uploadFile(FormDataMultiPart form) {
// Needed to get the Content-Disposition by client:
builder.header("Access-Control-Expose-Headers", "Content-Disposition");
Response response = builder.build();
log.info("Downloading file '" + zipFilename + "', length: " + FileUtils.byteCountToDisplaySize(zipByteArray.length));
log.info("Downloading file '" + zipFilename + "', length: " + RestUtils.getByteCountToDisplaySize(zipByteArray.length));
return response;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.reinhard.merlin.app.rest;

import de.reinhard.merlin.app.javafx.RunningMode;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -40,4 +41,15 @@ static String getISODate() {
return ISO_DATEFORMAT.format(new Date());
}
}

static String getByteCountToDisplaySize(Long length) {
if (length == null) {
return "0KB";
}
return FileUtils.byteCountToDisplaySize(length);
}

static String getByteCountToDisplaySize(int length) {
return FileUtils.byteCountToDisplaySize(length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import de.reinhard.merlin.word.templating.Template;
import de.reinhard.merlin.word.templating.TemplateDefinition;
import de.reinhard.merlin.word.templating.WordTemplateRunner;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -65,12 +64,13 @@ public Response runTemplate(String json) {
WordTemplateRunner runner = new WordTemplateRunner(templateDefinition, doc);
WordDocument result = runner.run(data.getVariables());
String filename = runner.createFilename(path.getFileName().toString(), data.getVariables());
Response.ResponseBuilder builder = Response.ok(result.getAsByteArrayOutputStream().toByteArray());
byte[] byteArray = result.getAsByteArrayOutputStream().toByteArray();
Response.ResponseBuilder builder = Response.ok(byteArray);
builder.header("Content-Disposition", "attachment; filename=" + filename);
// Needed to get the Content-Disposition by client:
builder.header("Access-Control-Expose-Headers", "Content-Disposition");
response = builder.build();
log.info("Downloading file '" + filename + "', length: " + FileUtils.byteCountToDisplaySize(doc.getLength()));
log.info("Downloading file '" + filename + "', length: " + RestUtils.getByteCountToDisplaySize(byteArray.length));
return response;
} catch (Exception ex) {
String errorMsg = "Error while try to run template '" + data.getTemplatePrimaryKey() + "'.";
Expand Down

0 comments on commit 97d1a24

Please sign in to comment.