private void parseMultipartParameters ( Map < String , List < FileItem > > fileItemListMap , RequestAdapter requestAdapter ) { String encoding = requestAdapter . getEncoding ( ) ; MultiValueMap < String , String > parameterMap = new LinkedMultiValueMap <> ( ) ; MultiValueMap < String , FileParameter > fileParameterMap = new LinkedMultiValueMap <> ( ) ; for ( Map . Entry < String , List < FileItem > > entry : fileItemListMap . entrySet ( ) ) { String fieldName = entry . getKey ( ) ; List < FileItem > fileItemList = entry . getValue ( ) ; if ( fileItemList != null && ! fileItemList . isEmpty ( ) ) { for ( FileItem fileItem : fileItemList ) { if ( fileItem . isFormField ( ) ) { String value = getString ( fileItem , encoding ) ; parameterMap . add ( fieldName , value ) ; } else { String fileName = fileItem . getName ( ) ; // Skip file uploads that don't have a file name - meaning that // no file was selected. if ( StringUtils . isEmpty ( fileName ) ) { continue ; } boolean valid = FilenameUtils . isValidFileExtension ( fileName , allowedFileExtensions , deniedFileExtensions ) ; if ( ! valid ) { continue ; } MemoryMultipartFileParameter fileParameter = new MemoryMultipartFileParameter ( fileItem ) ; fileParameterMap . add ( fieldName , fileParameter ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Found multipart file [" + fileParameter . getFileName ( ) + "] of size " + fileParameter . getFileSize ( ) + " bytes, stored " + fileParameter . getStorageDescription ( ) ) ; } } } } } if ( ! parameterMap . isEmpty ( ) ) { for ( Map . Entry < String , List < String > > entry : parameterMap . entrySet ( ) ) { String name = entry . getKey ( ) ; List < String > list = entry . getValue ( ) ; String [ ] values = list . toArray ( new String [ 0 ] ) ; requestAdapter . setParameter ( name , values ) ; } } if ( ! fileParameterMap . isEmpty ( ) ) { for ( Map . Entry < String , List < FileParameter > > entry : fileParameterMap . entrySet ( ) ) { String name = entry . getKey ( ) ; List < FileParameter > list = entry . getValue ( ) ; FileParameter [ ] values = list . toArray ( new FileParameter [ 0 ] ) ; requestAdapter . setFileParameter ( name , values ) ; } } }
Parse form fields and file items .