Skip to content

Commit

Permalink
Jakarta - 3 - API changes in code
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobazzi committed Nov 29, 2023
1 parent 43e8690 commit a547eb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload2.core.FileUploadException;
import org.eclipse.scout.rt.platform.BEANS;
import org.eclipse.scout.rt.platform.BeanMetaData;
import org.eclipse.scout.rt.platform.IBean;
Expand All @@ -42,6 +37,11 @@
import org.junit.Test;
import org.mockito.Mockito;

import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeBodyPart;
import jakarta.mail.internet.MimeMultipart;
import jakarta.servlet.http.HttpServletRequest;

public class UploadRequestHandlerTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload2.core.FileItemInput;
import org.apache.commons.fileupload2.core.FileItemInputIterator;
import org.apache.commons.fileupload2.core.FileUploadException;
import org.apache.commons.fileupload2.jakarta.JakartaServletFileUpload;
import org.eclipse.scout.rt.platform.BEANS;
import org.eclipse.scout.rt.platform.Order;
import org.eclipse.scout.rt.platform.config.CONFIG;
Expand Down Expand Up @@ -65,6 +61,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
* This handler contributes to the {@link UiServlet} as the POST handler for /upload
*/
Expand Down Expand Up @@ -99,7 +99,7 @@ public boolean handlePost(final HttpServletRequest req, final HttpServletRespons
final String targetAdapterId = matcher.group(2);

// Check if is really a file upload
if (!ServletFileUpload.isMultipartContent(req)) {
if (!JakartaServletFileUpload.isMultipartContent(req)) {
return false;
}

Expand Down Expand Up @@ -216,18 +216,18 @@ protected Long getAckSequenceNo(HttpServletRequest req) {
*/
protected void readUploadData(HttpServletRequest httpReq, IUploadable uploadable, Map<String, String> uploadProperties, List<BinaryResource> uploadResources) throws FileUploadException, IOException {
Set<String> validFileExtensions = getValidFileExtensionsFor(uploadable, uploadProperties);
ServletFileUpload upload = new ServletFileUpload();
upload.setHeaderEncoding(StandardCharsets.UTF_8.name());
JakartaServletFileUpload upload = new JakartaServletFileUpload();
upload.setHeaderCharset(StandardCharsets.UTF_8);
upload.setSizeMax(uploadable.getMaximumUploadSize());
upload.setFileCountMax(CONFIG.getPropertyValue(UiHtmlConfigProperties.MaxUploadFileCountProperty.class));
int fileCount = 0;
for (FileItemIterator it = upload.getItemIterator(httpReq); it.hasNext();) {
for (FileItemInputIterator it = upload.getItemIterator(httpReq); it.hasNext(); ) {
fileCount++;
//the first entry in an upload multipart is typically a "rowId" entry. be tolerant with one more file.
if (upload.getFileCountMax() > 0 && (fileCount - 1) > upload.getFileCountMax()) {
throw new RejectedResourceException("Too many files ({}).", fileCount);
}
FileItemStream item = it.next();
FileItemInput item = it.next();
String filename = item.getName();
if (StringUtility.hasText(filename)) {
String[] parts = StringUtility.split(filename, "[/\\\\]");
Expand All @@ -244,7 +244,7 @@ protected void readUploadData(HttpServletRequest httpReq, IUploadable uploadable
verifyFileName(validFileExtensions, filename, ext);
}
byte[] content;
try (InputStream in = item.openStream()) {
try (InputStream in = item.getInputStream()) {
content = IOUtility.readBytes(in);
}
BinaryResource res = BinaryResources.create()
Expand Down Expand Up @@ -280,7 +280,7 @@ protected void readUploadData(HttpServletRequest httpReq, IUploadable uploadable
* <p>
* The content is passed as well to allow for a custom content type detection logic.
*/
protected String detectContentType(String filename, FileItemStream item, byte[] content) {
protected String detectContentType(String filename, FileItemInput item, byte[] content) {
if (filename != null) {
return null;
}
Expand Down

0 comments on commit a547eb9

Please sign in to comment.