Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eclipse Foundation
IT
Websites
membership.eclipse.org
Commits
5b1e3c99
Commit
5b1e3c99
authored
Jan 13, 2022
by
Martin Lowe
🇨🇦
Browse files
Add routing for FileTooLargeException which was being rethrown as 500
parent
0eb9ef24
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/eclipsefoundation/eclipsedb/tasks/LegacyImageMigration.java
View file @
5b1e3c99
...
...
@@ -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
);
}
}
...
...
src/main/java/org/eclipsefoundation/react/resources/OrganizationResource.java
View file @
5b1e3c99
...
...
@@ -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
);
...
...
src/main/java/org/eclipsefoundation/react/service/ImageStoreService.java
View file @
5b1e3c99
...
...
@@ -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
(
"10
00000
"
)
@WithDefault
(
"10
48576
"
)
long
web
();
@WithDefault
(
"64000"
)
long
webPostCompression
();
@WithDefault
(
"10
00000
0"
)
@WithDefault
(
"10
48576
0"
)
long
print
();
}
...
...
src/main/java/org/eclipsefoundation/react/service/impl/DefaultImageStoreService.java
View file @
5b1e3c99
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment