Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<!-- commons-httpclient deprecated, use httpclient5 instead. To be removed in the future -->
<!-- Not upgrading to httpClient 4, because for new projects we should use httpclient5, and for old projects -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
Expand All @@ -82,6 +84,29 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.1</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down Expand Up @@ -140,7 +165,7 @@
<version>2.14.1</version>
</dependency>
<!-- he Log4j 1.2 Bridge allows applications coded to use Log4j 1.2 API to use Log4j 2 instead
see requirements https://logging.apache.org/log4j/2.x/log4j-1.2-api -->
see requirements https://logging.apache.org/log4j/2.x/log4j-1.2-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.hc.client5.http.entity.mime.HttpMultipartMode;
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
Expand Down Expand Up @@ -104,7 +103,6 @@ public void testDoPost_Files_NoHandler( ) throws Exception
ObjectMapper objectMapper = new ObjectMapper( );
JsonNode objectNodeRef = objectMapper.readTree( strRefJson );
JsonNode objectNodeJson = objectMapper.readTree( strResponseJson );

assertEquals( objectNodeRef, objectNodeJson );
}

Expand Down Expand Up @@ -233,17 +231,17 @@ private MockHttpServletRequest getMultipartRequest( ) throws Exception
byte [ ] fileContent = new byte [ ] {
1, 2, 3
};
Part [ ] parts = new Part [ ] {
new FilePart( "file1", new ByteArrayPartSource( "file1", fileContent ) )
};
MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity( parts, new PostMethod( ).getParams( ) );

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("upfile", fileContent, ContentType.DEFAULT_BINARY, "file1");
HttpEntity entity = builder.build();
// Serialize request body
ByteArrayOutputStream requestContent = new ByteArrayOutputStream( );
multipartRequestEntity.writeRequest( requestContent );
entity.writeTo(requestContent);
// Set request body to HTTP servlet request
request.setContent( requestContent.toByteArray( ) );
// Set content type to HTTP servlet request (important, includes Mime boundary string)
request.setContentType( multipartRequestEntity.getContentType( ) );
request.setContentType( entity.getContentType( ) );
request.setMethod( "POST" );
return request;
}
Expand Down