mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-07-31 17:38:33 +00:00
REPO-3422 Startup check for LibreOffice
Also included the transformer name on the log and error pages.
This commit is contained in:
@@ -66,6 +66,12 @@ public class AlfrescoPdfRendererController extends AbstractTransformerController
|
|||||||
setCheckCommand(createCheckCommand());
|
setCheckCommand(createCheckCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTransformerName()
|
||||||
|
{
|
||||||
|
return "Alfresco PDF Renderer";
|
||||||
|
}
|
||||||
|
|
||||||
private static RuntimeExec createTransformCommand()
|
private static RuntimeExec createTransformCommand()
|
||||||
{
|
{
|
||||||
RuntimeExec runtimeExec = new RuntimeExec();
|
RuntimeExec runtimeExec = new RuntimeExec();
|
||||||
|
@@ -1,10 +1,6 @@
|
|||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div th:if="${message}">
|
|
||||||
<h2 th:text="${message}"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h2>Alfresco PDF Renderer Test Transformation</h2>
|
<h2>Alfresco PDF Renderer Test Transformation</h2>
|
||||||
<form method="POST" enctype="multipart/form-data" action="/transform">
|
<form method="POST" enctype="multipart/form-data" action="/transform">
|
||||||
|
@@ -71,6 +71,12 @@ public class ImageMagickController extends AbstractTransformerController
|
|||||||
setCheckCommand(createCheckCommand());
|
setCheckCommand(createCheckCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTransformerName()
|
||||||
|
{
|
||||||
|
return "ImageMagick";
|
||||||
|
}
|
||||||
|
|
||||||
private static RuntimeExec createTransformCommand()
|
private static RuntimeExec createTransformCommand()
|
||||||
{
|
{
|
||||||
RuntimeExec runtimeExec = new RuntimeExec();
|
RuntimeExec runtimeExec = new RuntimeExec();
|
||||||
|
@@ -1,10 +1,6 @@
|
|||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div th:if="${message}">
|
|
||||||
<h2 th:text="${message}"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h2>ImageMagick Test Transformation</h2>
|
<h2>ImageMagick Test Transformation</h2>
|
||||||
<form method="POST" enctype="multipart/form-data" action="/transform">
|
<form method="POST" enctype="multipart/form-data" action="/transform">
|
||||||
|
@@ -96,6 +96,24 @@ public class LibreOfficeController extends AbstractTransformerController
|
|||||||
this.jodconverter = jodconverter;
|
this.jodconverter = jodconverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTransformerName()
|
||||||
|
{
|
||||||
|
return "LibreOffice";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String version()
|
||||||
|
{
|
||||||
|
// This method is simply used to check the availability in the case of LibreOffice.
|
||||||
|
if (!jodconverter.isAvailable())
|
||||||
|
{
|
||||||
|
throw new TransformException(500, "LibreOffice is not yet available");
|
||||||
|
}
|
||||||
|
|
||||||
|
return "LibreOffice available";
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/transform")
|
@PostMapping("/transform")
|
||||||
public ResponseEntity<Resource> transform(HttpServletRequest request,
|
public ResponseEntity<Resource> transform(HttpServletRequest request,
|
||||||
@RequestParam("file") MultipartFile sourceMultipartFile,
|
@RequestParam("file") MultipartFile sourceMultipartFile,
|
||||||
|
@@ -1,10 +1,6 @@
|
|||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div th:if="${message}">
|
|
||||||
<h2 th:text="${message}"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h2>LibreOffice Test Transformation</h2>
|
<h2>LibreOffice Test Transformation</h2>
|
||||||
<form method="POST" enctype="multipart/form-data" action="/transform">
|
<form method="POST" enctype="multipart/form-data" action="/transform">
|
||||||
|
@@ -108,9 +108,11 @@ public abstract class AbstractTransformerController
|
|||||||
logger.info("");
|
logger.info("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract String getTransformerName();
|
||||||
|
|
||||||
@RequestMapping("/version")
|
@RequestMapping("/version")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
String version()
|
protected String version()
|
||||||
{
|
{
|
||||||
String version = "Version not checked";
|
String version = "Version not checked";
|
||||||
if (checkCommand != null)
|
if (checkCommand != null)
|
||||||
@@ -140,6 +142,7 @@ public abstract class AbstractTransformerController
|
|||||||
@GetMapping("/log")
|
@GetMapping("/log")
|
||||||
public String log(Model model)
|
public String log(Model model)
|
||||||
{
|
{
|
||||||
|
model.addAttribute("title", getTransformerName() + " Log Entries");
|
||||||
Collection<LogEntry> log = LogEntry.getLog();
|
Collection<LogEntry> log = LogEntry.getLog();
|
||||||
if (!log.isEmpty())
|
if (!log.isEmpty())
|
||||||
{
|
{
|
||||||
@@ -148,9 +151,16 @@ public abstract class AbstractTransformerController
|
|||||||
return "log"; // the name of the template
|
return "log"; // the name of the template
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/error")
|
||||||
|
public String error()
|
||||||
|
{
|
||||||
|
return "error"; // the name of the template
|
||||||
|
}
|
||||||
|
|
||||||
@ExceptionHandler(TypeMismatchException.class)
|
@ExceptionHandler(TypeMismatchException.class)
|
||||||
public void handleParamsTypeMismatch(HttpServletResponse response, MissingServletRequestParameterException e) throws IOException
|
public void handleParamsTypeMismatch(HttpServletResponse response, MissingServletRequestParameterException e) throws IOException
|
||||||
{
|
{
|
||||||
|
String transformerName = getTransformerName();
|
||||||
String name = e.getParameterName();
|
String name = e.getParameterName();
|
||||||
String message = "Request parameter " + name + " is of the wrong type";
|
String message = "Request parameter " + name + " is of the wrong type";
|
||||||
int statusCode = 400;
|
int statusCode = 400;
|
||||||
@@ -162,12 +172,13 @@ public abstract class AbstractTransformerController
|
|||||||
|
|
||||||
LogEntry.setStatusCodeAndMessage(statusCode, message);
|
LogEntry.setStatusCodeAndMessage(statusCode, message);
|
||||||
|
|
||||||
response.sendError(statusCode, message);
|
response.sendError(statusCode, transformerName+" - "+message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(MissingServletRequestParameterException.class)
|
@ExceptionHandler(MissingServletRequestParameterException.class)
|
||||||
public void handleMissingParams(HttpServletResponse response, MissingServletRequestParameterException e) throws IOException
|
public void handleMissingParams(HttpServletResponse response, MissingServletRequestParameterException e) throws IOException
|
||||||
{
|
{
|
||||||
|
String transformerName = getTransformerName();
|
||||||
String name = e.getParameterName();
|
String name = e.getParameterName();
|
||||||
String message = "Request parameter " + name + " is missing";
|
String message = "Request parameter " + name + " is missing";
|
||||||
int statusCode = 400;
|
int statusCode = 400;
|
||||||
@@ -179,12 +190,13 @@ public abstract class AbstractTransformerController
|
|||||||
|
|
||||||
LogEntry.setStatusCodeAndMessage(statusCode, message);
|
LogEntry.setStatusCodeAndMessage(statusCode, message);
|
||||||
|
|
||||||
response.sendError(statusCode, message);
|
response.sendError(statusCode, transformerName+" - "+message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(TransformException.class)
|
@ExceptionHandler(TransformException.class)
|
||||||
public void transformExceptionWithMessage(HttpServletResponse response, TransformException e) throws IOException
|
public void transformExceptionWithMessage(HttpServletResponse response, TransformException e) throws IOException
|
||||||
{
|
{
|
||||||
|
String transformerName = getTransformerName();
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
int statusCode = e.getStatusCode();
|
int statusCode = e.getStatusCode();
|
||||||
|
|
||||||
@@ -195,9 +207,32 @@ public abstract class AbstractTransformerController
|
|||||||
|
|
||||||
LogEntry.setStatusCodeAndMessage(statusCode, message);
|
LogEntry.setStatusCodeAndMessage(statusCode, message);
|
||||||
|
|
||||||
response.sendError(statusCode, message);
|
// Forced to include the transformer name in the message (see commented out version of this method)
|
||||||
|
response.sendError(statusCode, transformerName+" - "+message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Results in HTML rather than json but there is an error in the log about "template might not exist or might
|
||||||
|
// not be accessible by any of the configured Template Resolvers" for the transformer.html (which is correct
|
||||||
|
// because that failed). Looks like Spring only supports returning json or XML when returning an Object or even
|
||||||
|
// a ResponseEntity without this logged exception, which is a shame as it would have been nicer to have just
|
||||||
|
// added the transformerName to the Object.
|
||||||
|
// @ExceptionHandler(TransformException.class)
|
||||||
|
// public final Map<String, Object> transformExceptionWithMessage(HttpServletResponse response, TransformException e, WebRequest request)
|
||||||
|
// {
|
||||||
|
// String transformerName = getTransformerName();
|
||||||
|
// String message = e.getMessage();
|
||||||
|
// int statusCode = e.getStatusCode();
|
||||||
|
//
|
||||||
|
// LogEntry.setStatusCodeAndMessage(statusCode, message);
|
||||||
|
//
|
||||||
|
// Map<String, Object> errorAttributes = new HashMap<>();
|
||||||
|
// errorAttributes.put("title", transformerName);
|
||||||
|
// errorAttributes.put("message", message);
|
||||||
|
// errorAttributes.put("status", Integer.toString(statusCode));
|
||||||
|
// errorAttributes.put("error", HttpStatus.valueOf(statusCode).getReasonPhrase());
|
||||||
|
// return errorAttributes;
|
||||||
|
// }
|
||||||
|
|
||||||
protected String createTargetFileName(MultipartFile sourceMultipartFile, String targetExtension)
|
protected String createTargetFileName(MultipartFile sourceMultipartFile, String targetExtension)
|
||||||
{
|
{
|
||||||
String targetFilename = null;
|
String targetFilename = null;
|
||||||
|
@@ -25,7 +25,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.transformer.base;
|
package org.alfresco.transformer.base;
|
||||||
|
|
||||||
import java.util.*;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Deque;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@@ -40,6 +43,7 @@ public class LogEntry
|
|||||||
private static final AtomicInteger count = new AtomicInteger(0);
|
private static final AtomicInteger count = new AtomicInteger(0);
|
||||||
private static final Deque<LogEntry> log = new ConcurrentLinkedDeque<>();
|
private static final Deque<LogEntry> log = new ConcurrentLinkedDeque<>();
|
||||||
private static final int MAX_LOG_SIZE = 10;
|
private static final int MAX_LOG_SIZE = 10;
|
||||||
|
private static final SimpleDateFormat HH_MM_SS = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
|
||||||
private static ThreadLocal<LogEntry> currentLogEntry = new ThreadLocal<LogEntry>()
|
private static ThreadLocal<LogEntry> currentLogEntry = new ThreadLocal<LogEntry>()
|
||||||
{
|
{
|
||||||
@@ -71,6 +75,32 @@ public class LogEntry
|
|||||||
private String options;
|
private String options;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(getId());
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(HH_MM_SS.format(getDate()));
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(getStatusCode());
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(getDuration());
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(getSource());
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(getSourceSize());
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(getTarget());
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(getTargetSize());
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(getOptions());
|
||||||
|
sb.append(' ');
|
||||||
|
sb.append(getMessage());
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static Collection<LogEntry> getLog()
|
public static Collection<LogEntry> getLog()
|
||||||
{
|
{
|
||||||
return log;
|
return log;
|
||||||
@@ -127,6 +157,11 @@ public class LogEntry
|
|||||||
LogEntry logEntry = currentLogEntry.get();
|
LogEntry logEntry = currentLogEntry.get();
|
||||||
logEntry.durationStreamOut = System.currentTimeMillis() - logEntry.start - logEntry.durationStreamIn - logEntry.durationTransform;
|
logEntry.durationStreamOut = System.currentTimeMillis() - logEntry.start - logEntry.durationStreamIn - logEntry.durationTransform;
|
||||||
currentLogEntry.remove();
|
currentLogEntry.remove();
|
||||||
|
|
||||||
|
if (AbstractTransformerController.logger != null && AbstractTransformerController.logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
AbstractTransformerController.logger.debug(logEntry.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId()
|
public int getId()
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h2 th:text="${#strings.substring(message,0,#strings.indexOf(message,' - '))} + ' Error Page'"></h2>
|
||||||
|
<h3 th:text="${#strings.substring(message,#strings.indexOf(message,' - ')+3)}"></h3>
|
||||||
|
<p th:text="${status} + ' - ' + ${error}"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<br/>
|
||||||
|
<a href="/">Test Transformation</a>
|
||||||
|
<a href="/log">Log entries</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -1,11 +1,8 @@
|
|||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div th:if="${message}">
|
<div>
|
||||||
<h2 th:text="${message}"/>
|
<h2 th:text="${title}"></h2>
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2>Log entries</h2>
|
|
||||||
<div th:if="${log}">
|
<div th:if="${log}">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -34,7 +31,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<br/>
|
<br/>
|
||||||
|
Reference in New Issue
Block a user