private FormData createFormData ( Message message ) { FormData formData = new ObjectFactory ( ) . createFormData ( ) ; formData . setContentType ( getFormContentType ( message ) ) ; formData . setAction ( getFormAction ( message ) ) ; if ( message . getPayload ( ) instanceof MultiValueMap ) { MultiValueMap < String , Object > formValueMap = message . getPayload ( MultiValueMap . class ) ; for ( Map . Entry < String , List < Object > > entry : formValueMap . entrySet ( ) ) { Control control = new ObjectFactory ( ) . createControl ( ) ; control . setName ( entry . getKey ( ) ) ; control . setValue ( StringUtils . arrayToCommaDelimitedString ( entry . getValue ( ) . toArray ( ) ) ) ; formData . addControl ( control ) ; } } else { String rawFormData = message . getPayload ( String . class ) ; if ( StringUtils . hasText ( rawFormData ) ) { StringTokenizer tokenizer = new StringTokenizer ( rawFormData , "&" ) ; while ( tokenizer . hasMoreTokens ( ) ) { Control control = new ObjectFactory ( ) . createControl ( ) ; String [ ] nameValuePair = tokenizer . nextToken ( ) . split ( "=" ) ; if ( autoDecode ) { try { control . setName ( URLDecoder . decode ( nameValuePair [ 0 ] , getEncoding ( ) ) ) ; control . setValue ( URLDecoder . decode ( nameValuePair [ 1 ] , getEncoding ( ) ) ) ; } catch ( UnsupportedEncodingException e ) { throw new CitrusRuntimeException ( String . format ( "Failed to decode form control value '%s=%s'" , nameValuePair [ 0 ] , nameValuePair [ 1 ] ) , e ) ; } } else { control . setName ( nameValuePair [ 0 ] ) ; control . setValue ( nameValuePair [ 1 ] ) ; } formData . addControl ( control ) ; } } } return formData ; }
Create form data model object from url encoded message payload .