/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF 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.alipay.sofa.rpc.samples.h2c;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;

/**
 * @author <a href="mailto:[email protected]">leizhiyuan</a>
 */
@ImportResource({ "classpath:h2c-client-example.xml" })
@SpringBootApplication
public class H2cClientApplication {

    public static void main(String[] args) {

        //change port to run in local machine
        System.setProperty("server.port", "8081");

        SpringApplication springApplication = new SpringApplication(H2cClientApplication.class);
        ApplicationContext applicationContext = springApplication.run(args);

        H2cService directService = (H2cService) applicationContext.getBean("h2cServiceReference");

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        String result = directService.sayH2c("h2c");
        System.out.println("invoke result:" + result);
        if ("h2c".equalsIgnoreCase(result)) {
            System.out.println("h2c invoke success");
        } else {
            System.out.println("h2c invoke fail");
        }
    }
}