Search in sources :

Example 1 with ExampleObj

use of com.alipay.sofa.rpc.rest.ExampleObj in project sofa-rpc by sofastack.

the class HttpApacheClientMain method main.

public static void main(String[] args) {
    /*
            注意:windows下服务端若未指定绑定到所有网卡0.0.0.0,则本机客户端是不能直接使用127.0.0.1访问的。
            请查看服务端启动日志,看具体绑定的网卡和端口是哪个:Server have success bind to 10.23.11.22:11090
            例如 http://10.23.11.22:11090
         */
    String url = "http://127.0.0.1:8888/rest/post/1234567890";
    Object[] params = new Object[] { "xxhttpxxx" };
    String result = sendByPost(url, params);
    LOGGER.info("result : {}", result);
    url = "http://127.0.0.1:8888/rest/object";
    ExampleObj example = new ExampleObj();
    example.setId(100);
    example.setName("namename");
    params = new Object[] { example };
    result = sendByPost(url, params);
    ExampleObj objresult = JSON.parseObject(result, ExampleObj.class);
    LOGGER.info("obj result : {}", objresult);
}
Also used : ExampleObj(com.alipay.sofa.rpc.rest.ExampleObj)

Example 2 with ExampleObj

use of com.alipay.sofa.rpc.rest.ExampleObj in project sofa-rpc by sofastack.

the class RestClientMain method main.

public static void main(String[] args) throws InterruptedException {
    ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
    ConsumerConfig<RestService> consumerConfig = new ConsumerConfig<RestService>().setApplication(application).setInterfaceId(RestService.class.getName()).setProtocol("rest").setBootstrap("rest").setDirectUrl("rest://127.0.0.1:8888").setTimeout(3000);
    RestService helloService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    while (true) {
        try {
            String s = helloService.add(22, "xxx");
            LOGGER.warn("add {}", s);
            s = helloService.query(22);
            LOGGER.warn("get {}", s);
            List<ExampleObj> es = new ArrayList<ExampleObj>();
            es.add(new ExampleObj().setName("xxx").setId(1));
            es.add(new ExampleObj().setName("yyy").setId(2));
            List<ExampleObj> rs = helloService.objects(es);
            LOGGER.warn("rs {}", rs.size());
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
        }
    }
}
Also used : ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ExampleObj(com.alipay.sofa.rpc.rest.ExampleObj) ArrayList(java.util.ArrayList) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) RestService(com.alipay.sofa.rpc.rest.RestService)

Aggregations

ExampleObj (com.alipay.sofa.rpc.rest.ExampleObj)2 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 RestService (com.alipay.sofa.rpc.rest.RestService)1 ArrayList (java.util.ArrayList)1