Merge branch 'master' into 'feature/REPO-3378_release_docker_images'

Sync Master with feature/REPO-3378_release_docker_images

See merge request Repository/alfresco-docker-transformers!1
This commit is contained in:
Alexandru Epure
2018-04-10 09:09:11 +01:00
24 changed files with 213 additions and 796 deletions

View File

@@ -98,9 +98,21 @@ public abstract class AbstractTransformerController
checkCommand = runtimeExec;
}
protected void logEnterpriseLicenseMessage()
{
logger.info("This image is only intended to be used with the Alfresco Enterprise Content Repository which is covered by ");
logger.info("https://www.alfresco.com/legal/agreements and https://www.alfresco.com/terms-use");
logger.info("");
logger.info("License rights for this program may be obtained from Alfresco Software, Ltd. pursuant to a written agreement");
logger.info("and any use of this program without such an agreement is prohibited.");
logger.info("");
}
protected abstract String getTransformerName();
@RequestMapping("/version")
@ResponseBody
String version()
protected String version()
{
String version = "Version not checked";
if (checkCommand != null)
@@ -130,6 +142,7 @@ public abstract class AbstractTransformerController
@GetMapping("/log")
public String log(Model model)
{
model.addAttribute("title", getTransformerName() + " Log Entries");
Collection<LogEntry> log = LogEntry.getLog();
if (!log.isEmpty())
{
@@ -138,9 +151,16 @@ public abstract class AbstractTransformerController
return "log"; // the name of the template
}
@GetMapping("/error")
public String error()
{
return "error"; // the name of the template
}
@ExceptionHandler(TypeMismatchException.class)
public void handleParamsTypeMismatch(HttpServletResponse response, MissingServletRequestParameterException e) throws IOException
{
String transformerName = getTransformerName();
String name = e.getParameterName();
String message = "Request parameter " + name + " is of the wrong type";
int statusCode = 400;
@@ -152,12 +172,13 @@ public abstract class AbstractTransformerController
LogEntry.setStatusCodeAndMessage(statusCode, message);
response.sendError(statusCode, message);
response.sendError(statusCode, transformerName+" - "+message);
}
@ExceptionHandler(MissingServletRequestParameterException.class)
public void handleMissingParams(HttpServletResponse response, MissingServletRequestParameterException e) throws IOException
{
String transformerName = getTransformerName();
String name = e.getParameterName();
String message = "Request parameter " + name + " is missing";
int statusCode = 400;
@@ -169,12 +190,13 @@ public abstract class AbstractTransformerController
LogEntry.setStatusCodeAndMessage(statusCode, message);
response.sendError(statusCode, message);
response.sendError(statusCode, transformerName+" - "+message);
}
@ExceptionHandler(TransformException.class)
public void transformExceptionWithMessage(HttpServletResponse response, TransformException e) throws IOException
{
String transformerName = getTransformerName();
String message = e.getMessage();
int statusCode = e.getStatusCode();
@@ -185,9 +207,32 @@ public abstract class AbstractTransformerController
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)
{
String targetFilename = null;

View File

@@ -25,7 +25,10 @@
*/
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.atomic.AtomicInteger;
@@ -40,6 +43,7 @@ public class LogEntry
private static final AtomicInteger count = new AtomicInteger(0);
private static final Deque<LogEntry> log = new ConcurrentLinkedDeque<>();
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>()
{
@@ -71,6 +75,32 @@ public class LogEntry
private String options;
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()
{
return log;
@@ -127,6 +157,11 @@ public class LogEntry
LogEntry logEntry = currentLogEntry.get();
logEntry.durationStreamOut = System.currentTimeMillis() - logEntry.start - logEntry.durationStreamIn - logEntry.durationTransform;
currentLogEntry.remove();
if (AbstractTransformerController.logger != null && AbstractTransformerController.logger.isDebugEnabled())
{
AbstractTransformerController.logger.debug(logEntry.toString());
}
}
public int getId()

View File

@@ -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>

View File

@@ -1,41 +1,38 @@
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div th:if="${message}">
<h2 th:text="${message}"/>
<div>
<h2 th:text="${title}"></h2>
<div th:if="${log}">
<table>
<tr>
<th>Id</th>
<th>Time</th>
<th>Status Code</th>
<th>Duration (ms)</th>
<th>Source</th>
<th></th>
<th>Target</th>
<th></th>
<th>Options</th>
<th>Message</th>
</tr>
<tr th:each="entry : ${log}">
<td th:text="${entry.id}"></td>
<td th:text="${#dates.format(entry.date, 'HH:mm:ss')}"></td>
<td th:text="${entry.statusCode}"></td>
<td th:text="${entry.duration}"></td>
<td th:text="${entry.source}"></td>
<td th:text="${entry.sourceSize}"></td>
<td th:text="${entry.target}"></td>
<td th:text="${entry.targetSize}"></td>
<td th:text="${entry.options}"></td>
<td th:text="${entry.message}"></td>
</tr>
</table>
</div>
</div>
<h2>Log entries</h2>
<div th:if="${log}">
<table>
<tr>
<th>Id</th>
<th>Time</th>
<th>Status Code</th>
<th>Duration (ms)</th>
<th>Source</th>
<th></th>
<th>Target</th>
<th></th>
<th>Options</th>
<th>Message</th>
</tr>
<tr th:each="entry : ${log}">
<td th:text="${entry.id}"></td>
<td th:text="${#dates.format(entry.date, 'HH:mm:ss')}"></td>
<td th:text="${entry.statusCode}"></td>
<td th:text="${entry.duration}"></td>
<td th:text="${entry.source}"></td>
<td th:text="${entry.sourceSize}"></td>
<td th:text="${entry.target}"></td>
<td th:text="${entry.targetSize}"></td>
<td th:text="${entry.options}"></td>
<td th:text="${entry.message}"></td>
</tr>
</table>
</div>
<div>
<br/>
<a href="/">Test Transformation</a>