/*
 * 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.net.*;
import java.io.*;


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

        URL oracle = new URL("http://www.oracle.com/");
        BufferedReader in = new BufferedReader(
        new InputStreamReader(oracle.openStream()));

        String inputLine;
        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);
        in.close();
        
        return new TextMessage("TEST: "+text);
        //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);
    }
       private static String readUrl(String urlString) throws Exception {
        BufferedReader reader = null;
        try {
            URL url = new URL(urlString);
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer buffer = new StringBuffer();
            int read;
            char[] chars = new char[1024];
            while ((read = reader.read(chars)) != -1)
                buffer.append(chars, 0, read); 

            return buffer.toString();
        } finally {
            if (reader != null)
                reader.close();
        }

    }

    static class Page {
        String title;
        String link;
        String description;
        String language;
        List<Item> items;
    }

    static class Item {
        String title;
        String link;
        String description;
    }
}

@@ -1140,33 +1140,81 @@
 ava.
-net.*;%0Aimport java.io.*;%0A
+io.BufferedReader;%0Aimport java.io.InputStreamReader;%0Aimport java.net.URL;
 %0A%0A@S
@@ -1658,21 +1658,15 @@
     
-   
 URL 
-oracle
+url
  = n
@@ -1684,35 +1684,74 @@
 p://
-www.oracle.com/
+cdn.crunchify.com/wp-content/uploads/code/json.sample.txt
 %22);%0A
-  
+%0A
     
-  
 Buff
@@ -1785,25 +1785,16 @@
 dReader(
-%0A        
 new Inpu
@@ -1811,14 +1811,11 @@
 der(
-oracle
+url
 .ope
@@ -1827,21 +1827,16 @@
 am()));%0A
-%0A
-    
     Stri
@@ -1842,35 +1842,25 @@
 ing 
-inputLine;%0A  
+str;%0A
     
-  
 while ((
 inpu
@@ -1855,25 +1855,19 @@
 while ((
-inputLine
+str
  = in.re
@@ -1884,29 +1884,25 @@
 != null)
-%0A   
+ %7B%0A
       
-   
 System.o
@@ -1916,24 +1916,21 @@
 tln(
-inputLine
+str
 );
+ 
 %0A    
+%7D%0A
     
@@ -2304,869 +2304,7 @@
 %0A   
-    private static String readUrl(String urlString) throws Exception %7B%0A        BufferedReader reader = null;%0A        try %7B%0A            URL url = new URL(urlString);%0A            reader = new BufferedReader(new InputStreamReader(url.openStream()));%0A            StringBuffer buffer = new StringBuffer();%0A            int read;%0A            char%5B%5D chars = new char%5B1024%5D;%0A            while ((read = reader.read(chars)) != -1)%0A                buffer.append(chars, 0, read); %0A%0A            return buffer.toString();%0A        %7D finally %7B%0A            if (reader != null)%0A                reader.close();%0A        %7D%0A%0A    %7D%0A%0A    static class Page %7B%0A        String title;%0A        String link;%0A        String description;%0A        String language;%0A        List%3CItem%3E items;%0A    %7D%0A%0A    static class Item %7B%0A        String title;%0A        String link;%0A        String description;%0A    %7D
 %0A%7D%0A

Update EchoApplication.java