Search in sources :

Example 1 with ServletRequestContext

use of com.helger.web.fileupload.servlet.ServletRequestContext in project ph-web by phax.

the class StreamingFuncTest method _parseUploadToList.

@Nonnull
@ReturnsMutableCopy
private ICommonsList<IFileItem> _parseUploadToList(final InputStream pStream, final int pLength) throws FileUploadException {
    final String contentType = "multipart/form-data; boundary=---1234";
    final AbstractFileUploadBase upload = new ServletFileUpload(new DiskFileItemFactory(10240));
    final MockHttpServletRequest request = new MockHttpServletRequest() {

        @Override
        public int getContentLength() {
            return pLength;
        }

        @Override
        public ServletInputStream getInputStream() {
            return new AbstractServletInputStream() {

                @Override
                public int read() throws IOException {
                    return pStream.read();
                }
            };
        }
    };
    request.setContentType(contentType);
    return upload.parseRequest(new ServletRequestContext(request));
}
Also used : ServletFileUpload(com.helger.web.fileupload.servlet.ServletFileUpload) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ServletRequestContext(com.helger.web.fileupload.servlet.ServletRequestContext) AbstractServletInputStream(com.helger.servlet.io.AbstractServletInputStream) DiskFileItemFactory(com.helger.web.fileupload.parse.DiskFileItemFactory) AbstractFileUploadBase(com.helger.web.fileupload.parse.AbstractFileUploadBase) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 2 with ServletRequestContext

use of com.helger.web.fileupload.servlet.ServletRequestContext in project ph-web by phax.

the class StreamingFuncTest method _parseUploadToIterator.

private IFileItemIterator _parseUploadToIterator(final byte[] aContent) throws FileUploadException, IOException {
    final String contentType = "multipart/form-data; boundary=---1234";
    final AbstractFileUploadBase upload = new ServletFileUpload(new DiskFileItemFactory(10240));
    final HttpServletRequest request = new MockHttpServletRequest().setContent(aContent).setContentType(contentType);
    return upload.getItemIterator(new ServletRequestContext(request));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ServletFileUpload(com.helger.web.fileupload.servlet.ServletFileUpload) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ServletRequestContext(com.helger.web.fileupload.servlet.ServletRequestContext) DiskFileItemFactory(com.helger.web.fileupload.parse.DiskFileItemFactory) AbstractFileUploadBase(com.helger.web.fileupload.parse.AbstractFileUploadBase)

Aggregations

MockHttpServletRequest (com.helger.servlet.mock.MockHttpServletRequest)2 AbstractFileUploadBase (com.helger.web.fileupload.parse.AbstractFileUploadBase)2 DiskFileItemFactory (com.helger.web.fileupload.parse.DiskFileItemFactory)2 ServletFileUpload (com.helger.web.fileupload.servlet.ServletFileUpload)2 ServletRequestContext (com.helger.web.fileupload.servlet.ServletRequestContext)2 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)1 AbstractServletInputStream (com.helger.servlet.io.AbstractServletInputStream)1 Nonnull (javax.annotation.Nonnull)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1