Skip to content

Commit

Permalink
Rename exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerjmchugh committed Jan 6, 2025
1 parent 3800bd7 commit 9a2798f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Custom exception to be thrown when the size of a remote file to be uploaded to the store exceeds the maximum upload size.
*/
public class RemoteFileTooLargeException extends IOException {
public class InputStreamLimitExceededException extends IOException {
private final long maxUploadSize;
private final long remoteFileSize;

Expand All @@ -14,7 +14,7 @@ public class RemoteFileTooLargeException extends IOException {
*
* @param maxUploadSize the maximum upload size allowed
*/
public RemoteFileTooLargeException(long maxUploadSize) {
public InputStreamLimitExceededException(long maxUploadSize) {
this(maxUploadSize, -1L);
}

Expand All @@ -24,7 +24,7 @@ public RemoteFileTooLargeException(long maxUploadSize) {
* @param maxUploadSize the maximum upload size allowed
* @param remoteFileSize the size of the remote file
*/
public RemoteFileTooLargeException(long maxUploadSize, long remoteFileSize) {
public InputStreamLimitExceededException(long maxUploadSize, long remoteFileSize) {
super("Remote file size " + (remoteFileSize >= 0L ? "of " + remoteFileSize + " bytes " : "") + "exceeds the maximum upload size" + (maxUploadSize >= 0L ? " of " + maxUploadSize + " bytes" : ""));
this.maxUploadSize = maxUploadSize;
this.remoteFileSize = remoteFileSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.commons.io.FilenameUtils;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.api.exception.NotAllowedException;
import org.fao.geonet.api.exception.RemoteFileTooLargeException;
import org.fao.geonet.api.exception.InputStreamLimitExceededException;
import org.fao.geonet.api.exception.ResourceNotFoundException;
import org.fao.geonet.domain.AbstractMetadata;
import org.fao.geonet.domain.MetadataResource;
Expand Down Expand Up @@ -236,7 +236,7 @@ public final MetadataResource putResource(ServiceContext context, String metadat
// Check if the content length is within the allowed limit
long contentLength = connection.getContentLengthLong();
if (contentLength > maxUploadSize) {
throw new RemoteFileTooLargeException(maxUploadSize, contentLength);
throw new InputStreamLimitExceededException(maxUploadSize, contentLength);
}

// Put the resource but limit the input stream to the max upload size plus one byte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package org.fao.geonet.api.records.attachments;

import jeeves.server.context.ServiceContext;
import org.fao.geonet.api.exception.RemoteFileTooLargeException;
import org.fao.geonet.api.exception.InputStreamLimitExceededException;
import org.fao.geonet.api.exception.ResourceAlreadyExistException;
import org.fao.geonet.api.exception.ResourceNotFoundException;
import org.fao.geonet.constants.Geonet;
Expand Down Expand Up @@ -205,7 +205,7 @@ public MetadataResource putResource(final ServiceContext context, final String m
Path filePath = getPath(context, metadataId, visibility, filename, approved);
try {
Files.copy(is, filePath, StandardCopyOption.REPLACE_EXISTING);
} catch (RemoteFileTooLargeException e) {
} catch (InputStreamLimitExceededException e) {
Files.deleteIfExists(filePath);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.fao.geonet.util;

import org.fao.geonet.api.exception.RemoteFileTooLargeException;
import org.fao.geonet.api.exception.InputStreamLimitExceededException;

import java.io.IOException;
import java.io.InputStream;

/**
* Implementation of {@link org.apache.commons.fileupload.util.LimitedInputStream} that throws a
* {@link RemoteFileTooLargeException} when the configured limit is exceeded.
* {@link InputStreamLimitExceededException} when the configured limit is exceeded.
*/
public class LimitedInputStream extends org.apache.commons.fileupload.util.LimitedInputStream {

Expand All @@ -25,6 +25,6 @@ public LimitedInputStream(InputStream inputStream, long pSizeMax) {

@Override
protected void raiseError(long pSizeMax, long pCount) throws IOException {
throw new RemoteFileTooLargeException(pSizeMax);
throw new InputStreamLimitExceededException(pSizeMax);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Object securityHandler(final HttpServletRequest request, final Exception
@ApiResponse(content = {@Content(mediaType = APPLICATION_JSON_VALUE)})
@ExceptionHandler({
MaxUploadSizeExceededException.class,
RemoteFileTooLargeException.class
InputStreamLimitExceededException.class
})
public ApiError maxFileExceededHandler(final Exception exception, final HttpServletRequest request) {
Exception ex;
Expand All @@ -166,9 +166,9 @@ public ApiError maxFileExceededHandler(final Exception exception, final HttpServ
.withDescriptionKey("exception.maxUploadSizeExceeded.description",
new String[]{FileUtil.humanizeFileSize(contentLength),
FileUtil.humanizeFileSize(((MaxUploadSizeExceededException) exception).getMaxUploadSize())});
} else if (exception instanceof RemoteFileTooLargeException) {
long maxUploadSize = ((RemoteFileTooLargeException) exception).getMaxUploadSize();
long remoteFileSize = ((RemoteFileTooLargeException) exception).getRemoteFileSize();
} else if (exception instanceof InputStreamLimitExceededException) {
long maxUploadSize = ((InputStreamLimitExceededException) exception).getMaxUploadSize();
long remoteFileSize = ((InputStreamLimitExceededException) exception).getRemoteFileSize();
if (remoteFileSize == -1) {
ex = new GeonetMaxUploadSizeExceededException("uploadedResourceSizeExceededException", exception)
.withMessageKey("exception.maxUploadSizeExceeded",
Expand Down

0 comments on commit 9a2798f

Please sign in to comment.