mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Save point: [skip ci]
* AbstractHttpRequestTest title in pages
This commit is contained in:
@@ -66,6 +66,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
@@ -228,16 +229,18 @@ public class TransformController
|
|||||||
@GetMapping(ENDPOINT_ROOT)
|
@GetMapping(ENDPOINT_ROOT)
|
||||||
public String test(Model model)
|
public String test(Model model)
|
||||||
{
|
{
|
||||||
return "test";
|
model.addAttribute("title", transformEngine.getTransformEngineName() + " Test Page");
|
||||||
|
return "test"; // display test.html
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test UI error page.
|
* Test UI error page.
|
||||||
*/
|
*/
|
||||||
@GetMapping(ENDPOINT_ERROR)
|
@GetMapping(ENDPOINT_ERROR)
|
||||||
public String error()
|
public String error(Model model)
|
||||||
{
|
{
|
||||||
return "error"; // the name of the template
|
model.addAttribute("title", transformEngine.getTransformEngineName() + " Error Page");
|
||||||
|
return "error"; // display error.html
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -252,7 +255,7 @@ public class TransformController
|
|||||||
{
|
{
|
||||||
model.addAttribute("log", log);
|
model.addAttribute("log", log);
|
||||||
}
|
}
|
||||||
return "log"; // the name of the template
|
return "log"; // display log.html
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -398,8 +401,6 @@ public class TransformController
|
|||||||
* @param timeout Transformation timeout
|
* @param timeout Transformation timeout
|
||||||
* @return A transformation reply
|
* @return A transformation reply
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = ENDPOINT_TRANSFORM, produces = APPLICATION_JSON_VALUE)
|
|
||||||
@ResponseBody
|
|
||||||
public ResponseEntity<TransformReply> transform(@RequestBody TransformRequest request,
|
public ResponseEntity<TransformReply> transform(@RequestBody TransformRequest request,
|
||||||
@RequestParam(value = "timeout", required = false) Long timeout)
|
@RequestParam(value = "timeout", required = false) Long timeout)
|
||||||
{
|
{
|
||||||
@@ -741,12 +742,6 @@ public class TransformController
|
|||||||
return customTransformer;
|
return customTransformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
|
||||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
|
||||||
{
|
|
||||||
//javaExecutor.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(TypeMismatchException.class)
|
@ExceptionHandler(TypeMismatchException.class)
|
||||||
public void handleParamsTypeMismatch(HttpServletResponse response, MissingServletRequestParameterException e) throws IOException
|
public void handleParamsTypeMismatch(HttpServletResponse response, MissingServletRequestParameterException e) throws IOException
|
||||||
{
|
{
|
||||||
@@ -766,18 +761,25 @@ public class TransformController
|
|||||||
|
|
||||||
logger.error(message, e);
|
logger.error(message, e);
|
||||||
LogEntry.setStatusCodeAndMessage(statusCode, message);
|
LogEntry.setStatusCodeAndMessage(statusCode, message);
|
||||||
response.sendError(statusCode, transformEngine.getTransformEngineName() + " - " + message);
|
response.sendError(statusCode, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(TransformException.class)
|
@ExceptionHandler(TransformException.class)
|
||||||
public void transformExceptionWithMessage(HttpServletResponse response, TransformException e) throws IOException
|
public ModelAndView transformExceptionWithMessage(HttpServletResponse response, TransformException e)
|
||||||
|
throws IOException
|
||||||
{
|
{
|
||||||
final String message = e.getMessage();
|
final String message = e.getMessage();
|
||||||
final int statusCode = e.getStatusCode();
|
final int statusCode = e.getStatusCode();
|
||||||
|
|
||||||
logger.error(message, e);
|
logger.error(message);
|
||||||
long time = LogEntry.setStatusCodeAndMessage(statusCode, message);
|
long time = LogEntry.setStatusCodeAndMessage(statusCode, message);
|
||||||
probeTestTransform.recordTransformTime(time);
|
probeTestTransform.recordTransformTime(time);
|
||||||
response.sendError(statusCode, transformEngine.getTransformEngineName() + " - " + message);
|
response.sendError(statusCode, message);
|
||||||
|
|
||||||
|
ModelAndView mav = new ModelAndView();
|
||||||
|
mav.addObject("title", transformEngine.getTransformEngineName() + " Error Page");
|
||||||
|
mav.addObject("message", message);
|
||||||
|
mav.setViewName("error"); // display error.html
|
||||||
|
return mav;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -227,7 +227,7 @@ public class ProbeTestTransform
|
|||||||
File targetFile = getTargetFile(request);
|
File targetFile = getTargetFile(request);
|
||||||
|
|
||||||
String transformName = getTransformerName(sourceFile, sourceMimetype, targetMimetype, transformOptions);
|
String transformName = getTransformerName(sourceFile, sourceMimetype, targetMimetype, transformOptions);
|
||||||
controller.transformImpl(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
// controller.transformImpl(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||||
|
|
||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
String message = "Transform " + time + "ms";
|
String message = "Transform " + time + "ms";
|
||||||
|
@@ -2,13 +2,9 @@
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div th:if="${message} == null">
|
<h2 th:text="${title}"></h2>
|
||||||
<h2>Error Page</h2>
|
|
||||||
</div>
|
|
||||||
<div th:if="${message}">
|
<div th:if="${message}">
|
||||||
<h2 th:text="${message}"></h2>
|
<h3 th:text="${message}"></h3>
|
||||||
<!-- <h2 th:text="${#strings.substring(message,0,#strings.indexOf(message,' - '))} + ' Error Page'"></h2>-->
|
|
||||||
<!-- <h3 th:text="${#strings.substring(message,#strings.indexOf(message,' - ')+3)}"></h3>-->
|
|
||||||
</div>
|
</div>
|
||||||
<p th:text="${status} + ' - ' + ${error}"></p>
|
<p th:text="${status} + ' - ' + ${error}"></p>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<h2>Test Transformations</h2>
|
<h2 th:text="${title}"></h2>
|
||||||
<form method="POST" enctype="multipart/form-data" action="/test">
|
<form method="POST" enctype="multipart/form-data" action="/test">
|
||||||
<table>
|
<table>
|
||||||
<tr><td><div style="text-align:right">file</div></td><td><input type="file" name="file" /></td></tr>
|
<tr><td><div style="text-align:right">file</div></td><td><input type="file" name="file" /></td></tr>
|
||||||
|
@@ -65,7 +65,7 @@ public abstract class AbstractHttpRequestTest
|
|||||||
{
|
{
|
||||||
String result = restTemplate.getForObject("http://localhost:" + port + "/", String.class);
|
String result = restTemplate.getForObject("http://localhost:" + port + "/", String.class);
|
||||||
|
|
||||||
String title = "Test Transformation";
|
String title = getTransformerName() + " Test Page";
|
||||||
assertTrue("\"" + title + "\" should be part of the page title", result.contains(title));
|
assertTrue("\"" + title + "\" should be part of the page title", result.contains(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ public abstract class AbstractHttpRequestTest
|
|||||||
String result = restTemplate.getForObject("http://localhost:" + port + "/log",
|
String result = restTemplate.getForObject("http://localhost:" + port + "/log",
|
||||||
String.class);
|
String.class);
|
||||||
|
|
||||||
String title = getTransformerName() + ' ' + "Log";
|
String title = getTransformerName() + " Log";
|
||||||
assertTrue("\"" + title + "\" should be part of the page title", result.contains(title));
|
assertTrue("\"" + title + "\" should be part of the page title", result.contains(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +85,8 @@ public abstract class AbstractHttpRequestTest
|
|||||||
String result = restTemplate.getForObject("http://localhost:" + port + "/error",
|
String result = restTemplate.getForObject("http://localhost:" + port + "/error",
|
||||||
String.class);
|
String.class);
|
||||||
|
|
||||||
String title = getTransformerName() + ' ' + "Error Page";
|
String title = getTransformerName() + " Error Page";
|
||||||
assertTrue("\"" + title + "\" should be part of the page title", result.contains("Error Page"));
|
assertTrue("\"" + title + "\" should be part of the page title", result.contains(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -95,17 +95,10 @@ public abstract class AbstractHttpRequestTest
|
|||||||
LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
|
LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
|
||||||
parameters.add("targetExtension", ".tmp");
|
parameters.add("targetExtension", ".tmp");
|
||||||
|
|
||||||
assertTransformError(false,
|
assertTransformError(false, "Required request part 'file' is not present",
|
||||||
getTransformerName() + " - Required request part 'file' is not present",
|
|
||||||
parameters);
|
parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertMissingParameter(String name)
|
|
||||||
{
|
|
||||||
assertTransformError(true,
|
|
||||||
getTransformerName() + " - Request parameter '" + name + "' is missing", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertTransformError(boolean addFile,
|
protected void assertTransformError(boolean addFile,
|
||||||
String errorMessage,
|
String errorMessage,
|
||||||
LinkedMultiValueMap<String, Object> additionalParams)
|
LinkedMultiValueMap<String, Object> additionalParams)
|
||||||
@@ -138,10 +131,7 @@ public abstract class AbstractHttpRequestTest
|
|||||||
parameters.add("targetExtension", ".tmp");
|
parameters.add("targetExtension", ".tmp");
|
||||||
parameters.add(DIRECT_ACCESS_URL, directUrl);
|
parameters.add(DIRECT_ACCESS_URL, directUrl);
|
||||||
|
|
||||||
assertTransformError(false,
|
assertTransformError(false, "Direct Access Url not found.", parameters);
|
||||||
getTransformerName() + " - Direct Access Url not found.",
|
|
||||||
parameters);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendTranformationRequest(
|
protected void sendTranformationRequest(
|
||||||
|
Reference in New Issue
Block a user