String fetchToken ( String tokenType ) throws IOException , MediaWikiApiErrorException { Map < String , String > params = new HashMap <> ( ) ; params . put ( ApiConnection . PARAM_ACTION , "query" ) ; params . put ( "meta" , "tokens" ) ; params . put ( "type" , tokenType ) ; try { JsonNode root = this . sendJsonRequest ( "POST" , params ) ; return root . path ( "query" ) . path ( "tokens" ) . path ( tokenType + "token" ) . textValue ( ) ; } catch ( IOException | MediaWikiApiErrorException e ) { logger . error ( "Error when trying to fetch token: " + e . toString ( ) ) ; } return null ; }
Executes a API query action to get a new token . The method only executes the action without doing any checks first . If errors occur they are logged and null is returned .