/*
 * 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);
    }
    
    public static String getText(String url) throws Exception {
        URL website = new URL(url);
        URLConnection connection = website.openConnection();
        BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                    connection.getInputStream()));

        StringBuilder response = new StringBuilder();
        String inputLine;

        while ((inputLine = in.readLine()) != null) 
            response.append(inputLine);

        in.close();

        return response.toString();
    }
    
    @EventMapping
    public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
        System.out.println("event: " + event);
        //return new TextMessage("TEST: "+event.getMessage().getText());
        
        
        String content = EchoApplication.getText("http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt");
        return new TextMessage(content);
    }

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

@@ -1354,106 +1354,336 @@
     
-%0A    public static String getText(String url) throws Exception %7B%0A        URL website = new URL(url
+    %0A    @EventMapping%0A    public TextMessage handleTextMessageEvent(MessageEvent%3CTextMessageContent%3E event) %7B%0A        System.out.println(%22event: %22 + event);%0A        //return new TextMessage(%22TEST: %22+event.getMessage().getText());%0A%0A        URL website = new URL(%22http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt%22
 );%0A 
@@ -2108,25 +2108,24 @@
 lose();%0A
-%0A
         
 return r
@@ -2120,447 +2120,59 @@
     
-return response.toString();
 %0A    
-%7D%0A
     
-%0A    @EventMapping%0A    public TextMessage handleTextMessageEvent(MessageEvent%3CTextMessageContent%3E event) %7B%0A        System.out.println(%22event: %22 + event);%0A        //return new TextMessage(%22TEST: %22+event.getMessage().getText());%0A        %0A        %0A        String content = EchoApplication.getText(%22http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt%22);%0A        return new TextMessage(content
+return new TextMessage(response.toString()
 );%0A 

Update EchoApplication.java