private static AmazonWebServiceRequest generateRequest ( ActionContext context , Class < ? > type , RequestModel model , AmazonWebServiceRequest request , Object token ) throws InstantiationException , IllegalAccessException { if ( request == null ) { request = ( AmazonWebServiceRequest ) type . newInstance ( ) ; } request . getRequestClientOptions ( ) . appendUserAgent ( USER_AGENT ) ; for ( PathTargetMapping mapping : model . getIdentifierMappings ( ) ) { Object value = context . getIdentifier ( mapping . getSource ( ) ) ; if ( value == null ) { throw new IllegalStateException ( "Action has a mapping for identifier " + mapping . getSource ( ) + ", but the target has no " + "identifier of that name!" ) ; } ReflectionUtils . setByPath ( request , value , mapping . getTarget ( ) ) ; } for ( PathTargetMapping mapping : model . getAttributeMappings ( ) ) { Object value = context . getAttribute ( mapping . getSource ( ) ) ; if ( value == null ) { // TODO: Is this ever valid? throw new IllegalStateException ( "Action has a mapping for attribute " + mapping . getSource ( ) + ", but the target has no " + "attribute of that name!" ) ; } ReflectionUtils . setByPath ( request , value , mapping . getTarget ( ) ) ; } for ( PathTargetMapping mapping : model . getConstantMappings ( ) ) { // TODO: This only works for strings; can we do better? ReflectionUtils . setByPath ( request , mapping . getSource ( ) , mapping . getTarget ( ) ) ; } if ( token != null ) { List < String > tokenPath = model . getTokenPath ( ) ; if ( tokenPath == null ) { throw new IllegalArgumentException ( "Cannot pass a token with a null token path" ) ; } ReflectionUtils . setByPath ( request , token , tokenPath ) ; } return request ; }
Generates a client - level request by extracting the user parameters ( if