public void doPost ( HttpServletRequest req , HttpServletResponse res ) throws ServletException , IOException { log . info ( "doPost(): " + UsageLog . setupRequestContext ( req ) ) ; // Check that we have a file upload request boolean isMultipart = ServletFileUpload . isMultipartContent ( req ) ; if ( ! isMultipart ) { log . info ( "doPost(): " + UsageLog . closingMessageForRequestContext ( HttpServletResponse . SC_BAD_REQUEST , 0 ) ) ; res . sendError ( HttpServletResponse . SC_BAD_REQUEST ) ; return ; } //Create a new file upload handler ServletFileUpload upload = new ServletFileUpload ( this . cdmValidatorContext . getFileuploadFileItemFactory ( ) ) ; upload . setSizeMax ( this . cdmValidatorContext . getMaxFileUploadSize ( ) ) ; // maximum bytes before a FileUploadException will be thrown List < FileItem > fileItems ; try { fileItems = ( List < FileItem > ) upload . parseRequest ( req ) ; } catch ( FileUploadException e ) { log . info ( "doPost(): Validator FileUploadException" , e ) ; log . info ( "doPost(): " + UsageLog . closingMessageForRequestContext ( HttpServletResponse . SC_BAD_REQUEST , 0 ) ) ; if ( ! res . isCommitted ( ) ) res . sendError ( HttpServletResponse . SC_BAD_REQUEST ) ; return ; } //Process the uploaded items String username = null ; boolean wantXml = false ; for ( FileItem item : fileItems ) { if ( item . isFormField ( ) ) { if ( "username" . equals ( item . getFieldName ( ) ) ) username = item . getString ( ) ; if ( "xml" . equals ( item . getFieldName ( ) ) ) wantXml = item . getString ( ) . equals ( "true" ) ; } } for ( FileItem item : fileItems ) { if ( ! item . isFormField ( ) ) { try { processUploadedFile ( req , res , ( DiskFileItem ) item , username , wantXml ) ; return ; } catch ( Exception e ) { log . info ( "doPost(): Validator processUploadedFile" , e ) ; log . info ( "doPost(): " + UsageLog . closingMessageForRequestContext ( HttpServletResponse . SC_BAD_REQUEST , 0 ) ) ; res . sendError ( HttpServletResponse . SC_BAD_REQUEST , e . getMessage ( ) ) ; } } } }
POST handles uploaded files