public Map < String , String > getRequestHeaders ( ) { // If we already set the headers when logging request metadata, use them if ( super . getRequestHeaders ( ) != null ) return super . getRequestHeaders ( ) ; try { Map < String , String > headers = null ; String headersVar = getAttributeValueSmart ( HEADERS_VARIABLE ) ; if ( headersVar != null ) { Process processVO = getProcessDefinition ( ) ; Variable variableVO = processVO . getVariable ( headersVar ) ; if ( variableVO == null ) throw new ActivityException ( "Headers variable '" + headersVar + "' is not defined for process " + processVO . getLabel ( ) ) ; if ( ! variableVO . getType ( ) . startsWith ( "java.util.Map" ) ) throw new ActivityException ( "Headers variable '" + headersVar + "' must be of type java.util.Map" ) ; Object headersObj = getVariableValue ( headersVar ) ; if ( headersObj != null ) { headers = new HashMap <> ( ) ; for ( Object key : ( ( Map < ? , ? > ) headersObj ) . keySet ( ) ) { headers . put ( key . toString ( ) , ( ( Map < ? , ? > ) headersObj ) . get ( key ) . toString ( ) ) ; } } } Object authProvider = getAuthProvider ( ) ; if ( authProvider instanceof AuthTokenProvider ) { if ( headers == null ) headers = new HashMap <> ( ) ; URL endpoint = new URL ( getEndpointUri ( ) ) ; String user = getAttribute ( AUTH_USER ) ; String password = getAttribute ( AUTH_PASSWORD ) ; String appId = getAttribute ( AUTH_APP_ID ) ; if ( appId != null && appId . length ( ) > 0 ) { Map < String , String > options = new HashMap <> ( ) ; options . put ( "appId" , appId ) ; ( ( AuthTokenProvider ) authProvider ) . setOptions ( options ) ; } String token = new String ( ( ( AuthTokenProvider ) authProvider ) . getToken ( endpoint , user , password ) ) ; headers . put ( "Authorization" , "Bearer " + token ) ; } // Set the headers so that we don't try and set them next time this method gets called super . setRequestHeaders ( headers ) ; return headers ; } catch ( Exception ex ) { logger . severeException ( ex . getMessage ( ) , ex ) ; return null ; } }
Override to specify HTTP request headers .