Search in sources :

Example 16 with GenericObject

use of com.alipay.hessian.generic.model.GenericObject in project sofa-rpc by sofastack.

the class GenericClientMain method main.

public static void main(String[] args) {
    ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("generic-client");
    ConsumerConfig<GenericService> consumerConfig = new ConsumerConfig<GenericService>().setApplication(applicationConfig).setInterfaceId(TestGenericService.class.getName()).setGeneric(true).setTimeout(50000).setDirectUrl("bolt://127.0.0.1:22222?appName=generic-server");
    GenericService testService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    while (true) {
        try {
            String s1 = (String) testService.$invoke("echoStr", new String[] { "java.lang.String" }, new Object[] { "1111" });
            LOGGER.warn("generic return :{}", s1);
            GenericObject genericObject = new GenericObject("com.alipay.sofa.rpc.invoke.generic.TestObj");
            genericObject.putField("str", "xxxx");
            genericObject.putField("num", 222);
            GenericObject o2 = (GenericObject) testService.$genericInvoke("echoObj", new String[] { "com.alipay.sofa.rpc.invoke.generic.TestObj" }, new Object[] { genericObject });
            LOGGER.warn("generic return :{}", o2);
            TestObj o3 = testService.$genericInvoke("echoObj", new String[] { "com.alipay.sofa.rpc.invoke.generic.TestObj" }, new Object[] { genericObject }, TestObj.class);
            LOGGER.warn("generic return :{}", o3);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        try {
            Thread.sleep(2000);
        } catch (Exception ignore) {
        }
    }
}
Also used : GenericService(com.alipay.sofa.rpc.api.GenericService) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) GenericObject(com.alipay.hessian.generic.model.GenericObject) GenericObject(com.alipay.hessian.generic.model.GenericObject)

Aggregations

GenericObject (com.alipay.hessian.generic.model.GenericObject)16 Test (org.junit.Test)4 GenericService (com.alipay.sofa.rpc.api.GenericService)3 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)3 UnsafeByteArrayInputStream (com.alipay.sofa.rpc.common.struct.UnsafeByteArrayInputStream)2 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)2 ComplexBean (com.alipay.sofa.rpc.test.generic.bean.ComplexBean)2 People (com.alipay.sofa.rpc.test.generic.bean.People)2 Hessian2Input (com.caucho.hessian.io.Hessian2Input)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 GenericCollection (com.alipay.hessian.generic.model.GenericCollection)1 GenericMap (com.alipay.hessian.generic.model.GenericMap)1 GenericContext (com.alipay.sofa.rpc.api.GenericContext)1 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1 RequestBase (com.alipay.sofa.rpc.core.request.RequestBase)1