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

@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());

    
        
         return new TextMessage(getUrlSource("http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt"));
        //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 getUrlSource(String url) throws IOException {
            URL yahoo = new URL(url);
            URLConnection yc = yahoo.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    yc.getInputStream(), "UTF-8"));
            String inputLine;
            StringBuilder a = new StringBuilder();
            while ((inputLine = in.readLine()) != null)
                a.append(inputLine);
            in.close();

            return a.toString();
        }
  
}

@@ -1143,132 +1143,828 @@
 .io.
-*;%0Aimport java.net.*;%0Aimport java.io.IOException;%0A%0A@SpringBootApplication%0A@LineMessageHandler%0Apublic class EchoApplication %7B
+BufferedReader;%0Aimport java.io.InputStreamReader;%0Aimport java.net.URL;%0Aimport java.net.URLConnection;%0A%0A@SpringBootApplication%0A@LineMessageHandler%0Apublic class EchoApplication %7B%0A public static void Connect() throws Exception%7B%0A %0A  //Set URL%0A  URL url = new URL(%22http://website here.com%22);%0A  URLConnection spoof = url.openConnection();%0A %0A  //Spoof the connection so we look like a web browser%0A  spoof.setRequestProperty( %22User-Agent%22, %22Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)%22 );%0A  BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));%0A  String strLine = %22%22;%0A %0A  //Loop through every line in the source%0A  while ((strLine = in.readLine()) != null)%7B%0A %0A   //Prints each line to the console%0A   System.out.println(strLine);%0A  %7D%0A %0A  System.out.println(%22End of page.%22);%0A %7D%0A    
 %0A   
@@ -2311,135 +2311,142 @@
 ));%0A
-%0A    %0A        %0A         return new TextMessage(getUrlSource(%22http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt%22)
+  try%7B%0A   //Calling the Connect method%0A   Connect();%0A  %7Dcatch(Exception e)%7B%0A %0A  %7D%0A    %0A        %0A         return new TextMessage(%22TEST%22
 );%0A 
@@ -2754,536 +2754,8 @@
  %0A  
-private static String getUrlSource(String url) throws IOException %7B%0A            URL yahoo = new URL(url);%0A            URLConnection yc = yahoo.openConnection();%0A            BufferedReader in = new BufferedReader(new InputStreamReader(%0A                    yc.getInputStream(), %22UTF-8%22));%0A            String inputLine;%0A            StringBuilder a = new StringBuilder();%0A            while ((inputLine = in.readLine()) != null)%0A                a.append(inputLine);%0A            in.close();%0A%0A            return a.toString();%0A        %7D
 %0A  %0A

Update EchoApplication.java