public static String sendGet()

in src/main/java/software/aws/chatops_lex_api/resource/Util.java [58:103]


	public static String sendGet(String url, Map<String, String > headers) throws Exception {

        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        //Request header
        con.setRequestProperty("User-Agent", Util.USER_AGENT);
        for(String key: headers.keySet()) {
        	con.setRequestProperty(key, headers.get(key));
        }
        logger.info("\nSending 'GET' request to URL : " + url);
        int responseCode = con.getResponseCode();
        logger.info("Response Code : " + responseCode);

        StringBuffer response = new StringBuffer();
        try {       
	        try( BufferedReader in = new BufferedReader(
	                new InputStreamReader(con.getInputStream())) ){
	        	
		        String inputLine;
		
		        while ((inputLine = in.readLine()) != null) {
					if(response.length()>=MAX_FILE_SIZE){
						throw new RuntimeException("Response is too big");
					}				
					if( inputLine.length() <= MAX_FILE_SIZE)	{
		            	response.append(inputLine);
					}else{
						throw new IllegalArgumentException("Response is too big");
					}
		        }
	        }
	        con.disconnect();
        }catch(Exception e) {
        	logger.info("Exception in getSend: "+e.getMessage());
        }
        String slackResponse	=	response.toString();
        if( slackResponse.contains("invalid_auth")) {
        	
        	logger.info("Response from Slack: "+slackResponse);
        	logger.info("You are using the following token: "+headers);
        	throw new Exception("Slack token is invalid or you are missing grants. Double check the Token, event subscription or OAuth configuration in your slack application");
        	
        }
        return slackResponse;
    }