package hello;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

@Controller
@RequestMapping("/webhook")
public class HelloWorldController {

    @RequestMapping(method = RequestMethod.POST)
    public @ResponseBody String webhook(@RequestBody String obj){
       String text = null;
       String source = null;
       String name=null;
       String respostring=null;
       String text1=null;
       String rescode_str=null;
try{
	    	JSONObject objS = new JSONObject(obj);
//          System.out.println(objS.get("id"));
          JSONObject result = objS.getJSONObject("result");
	        text = result.getString("resolvedQuery");
	  JSONObject originalRequest = objS.getJSONObject("originalRequest");
	        source = originalRequest.getString("source");
	JSONObject data = originalRequest.getJSONObject("data");
	JSONObject user = data.getJSONObject("user");
	        name=user.getString("name");

	        text1="I love India";
	      //  int rescode=authorize();
	    //    rescode_str=String.valueOf(rescode);//Now it will return "10"  
	HelloWorldController hwc=new HelloWorldController();
	String res=hwc.authorize(obj);
           
            
	    
          
}catch(Exception e){
	text = "last ctach"+e.getMessage();
}

	       return  "{speech: "+text+",displayText: "+text+", source: biz-webhook-sample}";
	       //return  "{speech: "+text+" source "+source+",displayText: "+text+", source: biz-webhook-sample}";
	    }
	
	public String authorize(String obj){
  
		
                 return obj;
	}
	  
	
}

@@ -2002,43 +2002,1309 @@
 j)%7B%0A
-  %0A%09%09%0A                 return obj;%0A
+%09%09%09 StringBuilder result=null;%0A                 int statusCode = 0;%0A%09%09 try %7B%0A            int BUFFER_SIZE = 4096;%0A            URL url = new URL(%22http://34.196.246.23:8101/MessagingToolController?webhookrespo=hi%22);%0A//             HttpURLConnection http = (HttpURLConnection) url.openConnection();%0A%0A//             http.setRequestMethod(%22POST%22);%0A//             http.setRequestProperty(%22Content-Type%22, %22ext/html%22);%0A//             http.setUseCaches(false);%0A        %0A//             http.setDoOutput(true);%0A   %0A//             statusCode = http.getResponseCode();%0A//             System.out.println(%22code=======%22 + statusCode);%0A//             String newLine = System.getProperty(%22line.separator%22);%0A//             BufferedReader reader = new BufferedReader(new InputStreamReader(http.getInputStream()));%0A//             result = new StringBuilder();%0A//             String line;%0A//             boolean flag = false;%0A//             while ((line = reader.readLine()) != null) %7B%0A//                 result.append(flag ? newLine : %22%22).append(line);%0A//                 flag = true;%0A//             %7D%0A//             System.out.println(result);%0A        %7D catch (Exception e) %7B%0A            System.out.println(%22error  %22 + e.getMessage());%0A        %7D%0A               //  return result;%0A                 return result;%0A  %0A       
 %09%7D%0A%09

Update HelloWorldController.java