mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Save point: [skip ci]
* HttpStatus
This commit is contained in:
@@ -188,7 +188,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
{
|
||||
if (sourceMultipartFile == null)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(), "Required request part 'file' is not present");
|
||||
throw new TransformException(BAD_REQUEST, "Required request part 'file' is not present");
|
||||
}
|
||||
sourceFile = createSourceFile(request, sourceMultipartFile);
|
||||
sourceFilename = sourceMultipartFile.getOriginalFilename();
|
||||
@@ -236,11 +236,11 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(), "Direct Access Url is invalid.", e);
|
||||
throw new TransformException(BAD_REQUEST, "Direct Access Url is invalid.", e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(), "Direct Access Url not found.", e);
|
||||
throw new TransformException(BAD_REQUEST, "Direct Access Url not found.", e);
|
||||
}
|
||||
|
||||
return sourceFile;
|
||||
@@ -312,7 +312,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
}
|
||||
catch (TransformException e)
|
||||
{
|
||||
reply.setStatus(e.getStatusCode());
|
||||
reply.setStatus(e.getStatusCode().value());
|
||||
reply.setErrorDetails(messageWithCause("Failed at reading the source file", e));
|
||||
|
||||
transformerDebug.logFailure(reply);
|
||||
@@ -356,7 +356,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
}
|
||||
catch (TransformException e)
|
||||
{
|
||||
reply.setStatus(e.getStatusCode());
|
||||
reply.setStatus(e.getStatusCode().value());
|
||||
reply.setErrorDetails(messageWithCause("Failed at processing transformation", e));
|
||||
|
||||
transformerDebug.logFailure(reply);
|
||||
@@ -381,7 +381,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
}
|
||||
catch (TransformException e)
|
||||
{
|
||||
reply.setStatus(e.getStatusCode());
|
||||
reply.setStatus(e.getStatusCode().value());
|
||||
reply.setErrorDetails(messageWithCause("Failed at writing the transformed file", e));
|
||||
|
||||
transformerDebug.logFailure(reply);
|
||||
@@ -481,7 +481,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
String message = "Source file with reference: " + sourceReference + " is null or empty. "
|
||||
+ "Transformation will fail and stop now as there is no content to be transformed.";
|
||||
logger.warn(message);
|
||||
throw new TransformException(BAD_REQUEST.value(), message);
|
||||
throw new TransformException(BAD_REQUEST, message);
|
||||
}
|
||||
final File file = createTempFile("source_", "." + extension);
|
||||
|
||||
@@ -542,8 +542,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
sourceSizeInBytes, targetMimetype, transformOptions, null);
|
||||
if (transformerName == null)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(),
|
||||
"No transforms were able to handle the request");
|
||||
throw new TransformException(BAD_REQUEST, "No transforms were able to handle the request");
|
||||
}
|
||||
return transformerName;
|
||||
}
|
||||
|
@@ -116,7 +116,7 @@ public class QueueTransformService
|
||||
catch (TransformException e)
|
||||
{
|
||||
logger.error(e.getMessage(), e);
|
||||
replyWithError(replyToDestinationQueue, HttpStatus.valueOf(e.getStatusCode()),
|
||||
replyWithError(replyToDestinationQueue, HttpStatus.valueOf(e.getStatusCode().value()),
|
||||
e.getMessage(), correlationId);
|
||||
return;
|
||||
}
|
||||
@@ -155,23 +155,21 @@ public class QueueTransformService
|
||||
String message =
|
||||
"MessageConversionException during T-Request deserialization of message with correlationID "
|
||||
+ correlationId + ": ";
|
||||
throw new TransformException(BAD_REQUEST.value(), message + e.getMessage());
|
||||
throw new TransformException(BAD_REQUEST, message + e.getMessage());
|
||||
}
|
||||
catch (JMSException e)
|
||||
{
|
||||
String message =
|
||||
"JMSException during T-Request deserialization of message with correlationID "
|
||||
+ correlationId + ": ";
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
message + e.getMessage());
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR, message + e.getMessage());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String message =
|
||||
"Exception during T-Request deserialization of message with correlationID "
|
||||
+ correlationId + ": ";
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
message + e.getMessage());
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR, message + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -210,7 +210,7 @@ public interface TransformController
|
||||
TransformException e) throws IOException
|
||||
{
|
||||
final String message = e.getMessage();
|
||||
final int statusCode = e.getStatusCode();
|
||||
final int statusCode = e.getStatusCode().value();
|
||||
|
||||
logger.error(message, e);
|
||||
|
||||
|
@@ -92,8 +92,7 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
"Could not read " + locationFromProperty, e);
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR, "Could not read " + locationFromProperty, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -70,7 +70,7 @@ public class AlfrescoSharedFileStoreClient
|
||||
}
|
||||
catch (HttpClientErrorException e)
|
||||
{
|
||||
throw new TransformException(e.getStatusCode().value(), e.getMessage(), e);
|
||||
throw new TransformException(e.getStatusCode(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class AlfrescoSharedFileStoreClient
|
||||
}
|
||||
catch (HttpClientErrorException e)
|
||||
{
|
||||
throw new TransformException(e.getStatusCode().value(), e.getMessage(), e);
|
||||
throw new TransformException(e.getStatusCode(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -55,14 +55,12 @@ public abstract class AbstractCommandExecutor implements CommandExecutor
|
||||
|
||||
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(),
|
||||
"Transformer exit code was not 0: \n" + result.getStdErr());
|
||||
throw new TransformException(BAD_REQUEST, "Transformer exit code was not 0: \n" + result.getStdErr());
|
||||
}
|
||||
|
||||
if (!targetFile.exists() || targetFile.length() == 0)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
"Transformer failed to create an output file");
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR, Transformer failed to create an output file");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,14 +72,14 @@ public abstract class AbstractCommandExecutor implements CommandExecutor
|
||||
final ExecutionResult result = checkCommand.execute();
|
||||
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
"Transformer version check exit code was not 0: \n" + result);
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
"Transformer version check exit code was not 0: \n" + result);
|
||||
}
|
||||
|
||||
final String version = result.getStdOut().trim();
|
||||
if (version.isEmpty())
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
"Transformer version check failed to create any output");
|
||||
}
|
||||
return version;
|
||||
|
@@ -82,20 +82,20 @@ public interface Transformer
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(), getMessage(e), e);
|
||||
throw new TransformException(BAD_REQUEST, getMessage(e), e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(), getMessage(e), e);
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR, getMessage(e), e);
|
||||
}
|
||||
if (!targetFile.exists())
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
"Transformer failed to create an output file. Target file does not exist.");
|
||||
}
|
||||
if (sourceFile.length() > 0 && targetFile.length() == 0)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
"Transformer failed to create an output file. Target file is empty but source file was not empty.");
|
||||
}
|
||||
}
|
||||
|
@@ -47,6 +47,7 @@ import org.alfresco.transformer.logging.LogEntry;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
@@ -104,9 +105,8 @@ public class FileManager
|
||||
if (filename == null || filename.isEmpty())
|
||||
{
|
||||
String sourceOrTarget = source ? "source" : "target";
|
||||
int statusCode = source ? BAD_REQUEST.value() : INTERNAL_SERVER_ERROR.value();
|
||||
throw new TransformException(statusCode,
|
||||
"The " + sourceOrTarget + " filename was not supplied");
|
||||
HttpStatus statusCode = source ? BAD_REQUEST : INTERNAL_SERVER_ERROR;
|
||||
throw new TransformException(statusCode, "The " + sourceOrTarget + " filename was not supplied");
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
@@ -120,8 +120,7 @@ public class FileManager
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new TransformException(INSUFFICIENT_STORAGE.value(),
|
||||
"Failed to store the source file", e);
|
||||
throw new TransformException(INSUFFICIENT_STORAGE, "Failed to store the source file", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,8 +132,7 @@ public class FileManager
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new TransformException(INSUFFICIENT_STORAGE.value(),
|
||||
"Failed to store the source file", e);
|
||||
throw new TransformException(INSUFFICIENT_STORAGE, "Failed to store the source file", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,13 +147,13 @@ public class FileManager
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
"Could not read the target file: " + file.getPath());
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
"The target filename was malformed: " + file.getPath(), e);
|
||||
}
|
||||
}
|
||||
@@ -238,7 +236,7 @@ public class FileManager
|
||||
Resource targetResource = load(targetFile);
|
||||
targetFilename = UriUtils.encodePath(getFilename(targetFilename), "UTF-8");
|
||||
return ResponseEntity.ok().header(CONTENT_DISPOSITION,
|
||||
"attachment; filename*= UTF-8''" + targetFilename).body(targetResource);
|
||||
"attachment; filename*=UTF-8''" + targetFilename).body(targetResource);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -229,7 +229,7 @@ public abstract class ProbeTestTransform
|
||||
|
||||
if (time > maxTime)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
getMessagePrefix(isLiveProbe) +
|
||||
message + " which is more than " + livenessPercent +
|
||||
"% slower than the normal value of " + normalTime + "ms");
|
||||
@@ -247,14 +247,14 @@ public abstract class ProbeTestTransform
|
||||
{
|
||||
if (die.get())
|
||||
{
|
||||
throw new TransformException(TOO_MANY_REQUESTS.value(),
|
||||
throw new TransformException(TOO_MANY_REQUESTS,
|
||||
getMessagePrefix(isLiveProbe) + "Transformer requested to die. A transform took " +
|
||||
"longer than " + (maxTransformTime * 1000) + " seconds");
|
||||
}
|
||||
|
||||
if (maxTransformCount > 0 && transformCount.get() > maxTransformCount)
|
||||
{
|
||||
throw new TransformException(TOO_MANY_REQUESTS.value(),
|
||||
throw new TransformException(TOO_MANY_REQUESTS,
|
||||
getMessagePrefix(isLiveProbe) + "Transformer requested to die. It has performed " +
|
||||
"more than " + maxTransformCount + " transformations");
|
||||
}
|
||||
@@ -271,8 +271,8 @@ public abstract class ProbeTestTransform
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new TransformException(INSUFFICIENT_STORAGE.value(),
|
||||
getMessagePrefix(isLiveProbe) + "Failed to store the source file", e);
|
||||
throw new TransformException(INSUFFICIENT_STORAGE,
|
||||
getMessagePrefix(isLiveProbe) + "Failed to store the source file", e);
|
||||
}
|
||||
long length = sourceFile.length();
|
||||
LogEntry.setSource(sourceFilename, length);
|
||||
@@ -329,13 +329,13 @@ public abstract class ProbeTestTransform
|
||||
String probeMessage = getProbeMessage(isLiveProbe);
|
||||
if (!targetFile.exists() || !targetFile.isFile())
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
probeMessage + "Target File \"" + targetFile.getAbsolutePath() + "\" did not exist");
|
||||
}
|
||||
long length = targetFile.length();
|
||||
if (length < minExpectedLength || length > maxExpectedLength)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR,
|
||||
probeMessage + "Target File \"" + targetFile.getAbsolutePath() +
|
||||
"\" was the wrong size (" + length + "). Needed to be between " +
|
||||
minExpectedLength + " and " + maxExpectedLength);
|
||||
|
@@ -26,41 +26,10 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
import static org.alfresco.transform.common.RequestParamMap.DIRECT_ACCESS_URL;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG_LATEST;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.http.HttpHeaders.ACCEPT;
|
||||
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
@@ -70,8 +39,8 @@ import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.config.TransformOptionValue;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.alfresco.transformer.model.FileRefEntity;
|
||||
import org.alfresco.transformer.model.FileRefResponse;
|
||||
@@ -90,10 +59,40 @@ import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
import static org.alfresco.transform.common.RequestParamMap.DIRECT_ACCESS_URL;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG_LATEST;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.http.HttpHeaders.ACCEPT;
|
||||
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Super class for testing controllers without a server. Includes tests for the AbstractTransformerController itself.
|
||||
|
Reference in New Issue
Block a user