public static List < HttpRequestBase > parseJobCallbackProperties ( final Props props , final JobCallbackStatusEnum status , final Map < String , String > contextInfo , final int maxNumCallback , final Logger privateLogger ) { String callbackUrl = null ; if ( ! isThereJobCallbackProperty ( props , status ) ) { // short circuit return Collections . emptyList ( ) ; } final List < HttpRequestBase > result = new ArrayList <> ( ) ; // replace property templates with status final String jobCallBackUrlKey = replaceStatusToken ( JOB_CALLBACK_URL_TEMPLATE , status ) ; final String requestMethod = replaceStatusToken ( JOB_CALLBACK_REQUEST_METHOD_TEMPLATE , status ) ; final String httpBodyKey = replaceStatusToken ( JOB_CALLBACK_BODY_TEMPLATE , status ) ; final String headersKey = replaceStatusToken ( JOB_CALLBACK_REQUEST_HEADERS_TEMPLATE , status ) ; for ( int sequence = 1 ; sequence <= maxNumCallback ; sequence ++ ) { HttpRequestBase httpRequest = null ; final String sequenceStr = Integer . toString ( sequence ) ; // callback url final String callbackUrlKey = jobCallBackUrlKey . replace ( SEQUENCE_TOKEN , sequenceStr ) ; callbackUrl = props . get ( callbackUrlKey ) ; if ( callbackUrl == null || callbackUrl . length ( ) == 0 ) { // no more needs to done break ; } else { final String callbackUrlWithTokenReplaced = replaceTokens ( callbackUrl , contextInfo , true ) ; final String requestMethodKey = requestMethod . replace ( SEQUENCE_TOKEN , sequenceStr ) ; final String method = props . getString ( requestMethodKey , HTTP_GET ) ; if ( HTTP_POST . equals ( method ) ) { final String postBodyKey = httpBodyKey . replace ( SEQUENCE_TOKEN , sequenceStr ) ; final String httpBodyValue = props . get ( postBodyKey ) ; if ( httpBodyValue == null ) { // missing body for POST, not good // update the wiki about skipping callback url if body is missing privateLogger . warn ( "Missing value for key: " + postBodyKey + " skipping job callback '" + callbackUrl + " for job " + contextInfo . get ( CONTEXT_JOB_TOKEN ) ) ; } else { // put together an URL final HttpPost httpPost = new HttpPost ( callbackUrlWithTokenReplaced ) ; final String postActualBody = replaceTokens ( httpBodyValue , contextInfo , false ) ; privateLogger . info ( "postActualBody: " + postActualBody ) ; httpPost . setEntity ( createStringEntity ( postActualBody ) ) ; httpRequest = httpPost ; } } else if ( HTTP_GET . equals ( method ) ) { // GET httpRequest = new HttpGet ( callbackUrlWithTokenReplaced ) ; } else { privateLogger . warn ( "Unsupported request method: " + method + ". Only POST and GET are supported" ) ; } final String headersKeyPerSequence = headersKey . replace ( SEQUENCE_TOKEN , sequenceStr ) ; final String headersValue = props . get ( headersKeyPerSequence ) ; privateLogger . info ( "headers: " + headersValue ) ; final Header [ ] headers = parseHttpHeaders ( headersValue ) ; if ( headers != null ) { httpRequest . setHeaders ( headers ) ; privateLogger . info ( "# of headers found: " + headers . length ) ; } result . add ( httpRequest ) ; } } return result ; }
This method is responsible for parsing job call URL properties and convert them into a list of HttpRequestBase which callers can use to execute .