Commit 98993d47 authored by Martin Lowe's avatar Martin Lowe 🇨🇦
Browse files

Merge branch 'malowe/dev/eps_compression_skip' into 'dev'

Add routing for FileTooLargeException which was being rethrown as 500

See merge request !470
parents e9f0102d 5b1e3c99
Pipeline #1761 passed with stage
in 0 seconds
......@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
import io.quarkus.runtime.Startup;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import io.undertow.server.handlers.form.MultiPartParserDefinition.FileTooLargeException;
/**
* Imports images from the Eclipse DB OrganizationInformation table into the local imagestore. This will overwrite
......@@ -125,7 +126,7 @@ public class LegacyImageMigration {
void writeImageSafely(Supplier<byte[]> logo, Integer organizationID, String mime, ImageStoreFormats format) {
try {
images.writeImage(logo, Integer.toString(organizationID), mime, Optional.of(format));
} catch (RuntimeException e) {
} catch (FileTooLargeException | RuntimeException e) {
LOGGER.error("Error while writing logo for organization {} with format {}", organizationID, format, e);
}
}
......
......@@ -91,6 +91,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.quarkus.security.Authenticated;
import io.undertow.server.handlers.form.MultiPartParserDefinition.FileTooLargeException;
/**
* Allows for external organizations data to be retrieved and displayed.
......@@ -575,7 +576,7 @@ public class OrganizationResource extends AbstractRESTResource {
@Path("{orgID:\\d+}/logos")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postOrganizationLogoUpdate(@PathParam("orgID") String organizationID,
@MultipartForm OrganizationLogoUpdateRequest request) {
@MultipartForm OrganizationLogoUpdateRequest request) throws FileTooLargeException {
// handle writing and checking image data
ImageStoreFormat format = ImageStoreFormats.getFormat(request.imageFormat);
String extension = ImageFileHelper.convertMimeType(request.imageMIME);
......
......@@ -20,6 +20,7 @@ import org.eclipsefoundation.react.namespace.ImageStoreFormat;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.undertow.server.handlers.form.MultiPartParserDefinition.FileTooLargeException;
/**
* Defines writing, retrieval, and deletion of images using byte arrays.
......@@ -50,7 +51,7 @@ public interface ImageStoreService {
* @return absolute path to access the live image
*/
String writeImage(Supplier<byte[]> imageBytes, String organization, String mimeType,
Optional<ImageStoreFormat> format);
Optional<ImageStoreFormat> format) throws FileTooLargeException;
/**
* Remove images associated with the given organization. This should clear all images that exist for the
......@@ -91,13 +92,13 @@ public interface ImageStoreService {
*
*/
interface MaxSizeInBytes {
@WithDefault("1000000")
@WithDefault("1048576")
long web();
@WithDefault("64000")
long webPostCompression();
@WithDefault("10000000")
@WithDefault("10485760")
long print();
}
......
......@@ -142,7 +142,7 @@ public class DefaultImageStoreService implements ImageStoreService {
@Override
public String writeImage(Supplier<byte[]> imageBytes, String fileName, String mimeType,
Optional<ImageStoreFormat> format) {
Optional<ImageStoreFormat> format) throws FileTooLargeException {
// get file metadata
Path p = imageStoreRoot.resolve(ImageFileHelper.getFileNameWithExtension(fileName, format, mimeType));
BasicFileAttributeView attrView = Files.getFileAttributeView(p, BasicFileAttributeView.class);
......@@ -188,6 +188,9 @@ public class DefaultImageStoreService implements ImageStoreService {
}
} catch (IOException e) {
if (e instanceof FileTooLargeException) {
throw (FileTooLargeException) e;
}
throw new ServerErrorException("Could not write image for organization " + fileName,
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment