/*
 * Copyright 2016 LINE Corporation
 *
 * LINE Corporation licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.example.bot.spring.echo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.linecorp.bot.model.event.Event;
import com.linecorp.bot.model.event.MessageEvent;
import com.linecorp.bot.model.event.message.TextMessageContent;
import com.linecorp.bot.model.message.TextMessage;
import com.linecorp.bot.spring.boot.annotation.EventMapping;
import com.linecorp.bot.spring.boot.annotation.LineMessageHandler;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;


@SpringBootApplication
@LineMessageHandler
public class EchoApplication {
    public static void main(String[] args) {
        SpringApplication.run(EchoApplication.class, args);
    }
        
    @EventMapping
    public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event)  {
        System.out.println("event: " + event);
        //return new TextMessage("TEST: "+event.getMessage().getText());

       URL url;

        try {
            // get URL content

            String a="http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt";
            url = new URL(a);
            URLConnection conn = url.openConnection();

            // open the stream and put it into BufferedReader
            BufferedReader br = new BufferedReader(
                               new InputStreamReader(conn.getInputStream()));

            String inputLine;
            while ((inputLine = br.readLine()) != null) {
                    System.out.println(inputLine);
            }
            br.close();

            System.out.println("Done");

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
       return new TextMessage("TEST: "+event.getMessage().getText());
 
        //URL website = new URL("http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt");
        
//        return new TextMessage(response.toString());
    }

    @EventMapping
    public void handleDefaultMessageEvent(Event event) {
        System.out.println("event: " + event);
    }
   

}

@@ -1140,178 +1140,31 @@
 ava.
-io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.net.MalformedURLException;%0Aimport java.net.URL;%0Aimport java.net.URLConnection
+net.*;%0Aimport java.io.*
 ;%0A%0A%0A
@@ -1596,85 +1596,27 @@
     
+ 
 URL url
-;%0A%0A        try %7B%0A            // get URL content%0A%0A            String a=
+ = new URL(
 %22htt
@@ -1681,37 +1681,8 @@
 txt%22
-;%0A            url = new URL(a
 );%0A 
@@ -1688,20 +1688,16 @@
         
-  
-  
 URLConne
@@ -1705,17 +1705,16 @@
 tion con
-n
  = url.o
@@ -1730,28 +1730,24 @@
 tion();%0A
-%0A   
         
  // open
@@ -1742,142 +1742,47 @@
     
- // open the stream and put it into BufferedReader%0A            BufferedReader br = new BufferedReader(%0A                               
+BufferedReader in = new BufferedReader(
 new 
@@ -1802,17 +1802,16 @@
 ader(con
-n
 .getInpu
@@ -1819,29 +1819,24 @@
 Stream()));%0A
-%0A    
         Stri
@@ -1842,23 +1842,11 @@
 ing 
-inputLine;%0A    
+l;%0A
     
@@ -1861,22 +1861,12 @@
 e ((
+l=
 in
-putLine = br
 .rea
@@ -1877,12 +1877,10 @@
 e())
- 
 !=
- 
 null
@@ -1891,32 +1891,24 @@
             
-        
 System.out.p
@@ -1918,241 +1918,9 @@
 tln(
-inputLine);%0A            %7D%0A            br.close();%0A%0A            System.out.println(%22Done%22);%0A%0A        %7D catch (MalformedURLException e) %7B%0A            e.printStackTrace();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace(
+l
 );%0A 

Update EchoApplication.java