/*
 * 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.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;

@SpringBootApplication
@LineMessageHandler
public class EchoApplication {
    public static void main(String[] args) {
        SpringApplication.run(EchoApplication.class, args);
    }

    	public static String callURL(String myURL) {
		System.out.println("Requeted URL:" + myURL);
		StringBuilder sb = new StringBuilder();
		URLConnection urlConn = null;
		InputStreamReader in = null;
		try {
			URL url = new URL(myURL);
			urlConn = url.openConnection();
			if (urlConn != null)
				urlConn.setReadTimeout(60 * 1000);
			if (urlConn != null && urlConn.getInputStream() != null) {
				in = new InputStreamReader(urlConn.getInputStream(),
						Charset.defaultCharset());
				BufferedReader bufferedReader = new BufferedReader(in);
				if (bufferedReader != null) {
					int cp;
					while ((cp = bufferedReader.read()) != -1) {
						sb.append((char) cp);
					}
					bufferedReader.close();
				}
			}
		in.close();
		} catch (Exception e) {
			throw new RuntimeException("Exception while calling URL:"+ myURL, e);
		} 
 
		return sb.toString();
	}
    
    @EventMapping
    public TextMessage handleTextMessageEvent(MessageEvent<TextMessageContent> event) {
        System.out.println("event: " + event);
        //return new TextMessage("TEST: "+event.getMessage().getText());
        return new TextMessage(callURL("http://cdn.crunchify.com/wp-content/uploads/code/json.sample.txt"));
    }

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

@@ -1127,159 +1127,8 @@
 r;%0A%0A
-import java.io.BufferedReader;%0Aimport java.io.InputStreamReader;%0Aimport java.net.URL;%0Aimport java.net.URLConnection;%0Aimport java.nio.charset.Charset;%0A%0A
 @Spr
@@ -1311,877 +1311,8 @@
    %7D
-%0A%0A    %09public static String callURL(String myURL) %7B%0A%09%09System.out.println(%22Requeted URL:%22 + myURL);%0A%09%09StringBuilder sb = new StringBuilder();%0A%09%09URLConnection urlConn = null;%0A%09%09InputStreamReader in = null;%0A%09%09try %7B%0A%09%09%09URL url = new URL(myURL);%0A%09%09%09urlConn = url.openConnection();%0A%09%09%09if (urlConn != null)%0A%09%09%09%09urlConn.setReadTimeout(60 * 1000);%0A%09%09%09if (urlConn != null && urlConn.getInputStream() != null) %7B%0A%09%09%09%09in = new InputStreamReader(urlConn.getInputStream(),%0A%09%09%09%09%09%09Charset.defaultCharset());%0A%09%09%09%09BufferedReader bufferedReader = new BufferedReader(in);%0A%09%09%09%09if (bufferedReader != null) %7B%0A%09%09%09%09%09int cp;%0A%09%09%09%09%09while ((cp = bufferedReader.read()) != -1) %7B%0A%09%09%09%09%09%09sb.append((char) cp);%0A%09%09%09%09%09%7D%0A%09%09%09%09%09bufferedReader.close();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09in.close();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09throw new RuntimeException(%22Exception while calling URL:%22+ myURL, e);%0A%09%09%7D %0A %0A%09%09return sb.toString();%0A%09%7D
 %0A   

Update EchoApplication.java