Search in sources :

Example 1 with ProxyFactory

use of com.alibaba.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class HessianProtocolTest method testOverload.

@Test
public void testOverload() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&hessian.overload.method=true&hessian2.request=false");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assert.assertEquals("Hello, haha", result);
    result = client.sayHello("haha", 1);
    Assert.assertEquals("Hello, haha. ", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 2 with ProxyFactory

use of com.alibaba.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class MockClusterInvokerTest method getClusterInvoker.

@SuppressWarnings({ "unchecked", "rawtypes" })
private Invoker<IHelloService> getClusterInvoker(URL url) {
    // As `javassist` have a strict restriction of argument types, request will fail if Invocation do not contains complete parameter type information
    final URL durl = url.addParameter("proxy", "jdk");
    invokers.clear();
    ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("jdk");
    Invoker<IHelloService> invoker1 = proxy.getInvoker(new HelloService(), IHelloService.class, durl);
    invokers.add(invoker1);
    Directory<IHelloService> dic = new StaticDirectory<IHelloService>(durl, invokers, null);
    AbstractClusterInvoker<IHelloService> cluster = new AbstractClusterInvoker(dic) {

        @Override
        protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance) throws RpcException {
            if (durl.getParameter("invoke_return_error", false)) {
                throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "test rpc exception");
            } else {
                return ((Invoker<?>) invokers.get(0)).invoke(invocation);
            }
        }
    };
    return new MockClusterInvoker<IHelloService>(dic, cluster);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invocation(com.alibaba.dubbo.rpc.Invocation) ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) AbstractClusterInvoker(com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker) URL(com.alibaba.dubbo.common.URL) StaticDirectory(com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(com.alibaba.dubbo.rpc.Invoker) AbstractClusterInvoker(com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker) LoadBalance(com.alibaba.dubbo.rpc.cluster.LoadBalance) RpcException(com.alibaba.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ProxyFactory

use of com.alibaba.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class HessianProtocolTest method testHttpClient.

@Test
public void testHttpClient() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&client=httpclient");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 4 with ProxyFactory

use of com.alibaba.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class HessianProtocolTest method testHessianProtocol.

@Test
public void testHessianProtocol() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 5 with ProxyFactory

use of com.alibaba.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class HessianProtocolTest method testCustomException.

@Test
public void testCustomException() {
    HessianServiceImpl server = new HessianServiceImpl();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService client = proxyFactory.getProxy(invoker);
    try {
        client.customException();
        fail();
    } catch (MyException expected) {
    }
    invoker.destroy();
    exporter.unexport();
}
Also used : MyException(com.alibaba.dubbo.rpc.protocol.hessian.HessianServiceImpl.MyException) ProxyFactory(com.alibaba.dubbo.rpc.ProxyFactory) Protocol(com.alibaba.dubbo.rpc.Protocol) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

URL (com.alibaba.dubbo.common.URL)7 ProxyFactory (com.alibaba.dubbo.rpc.ProxyFactory)7 Protocol (com.alibaba.dubbo.rpc.Protocol)6 Test (org.junit.Test)6 RpcException (com.alibaba.dubbo.rpc.RpcException)2 Monitor (com.alibaba.dubbo.monitor.Monitor)1 MonitorFactory (com.alibaba.dubbo.monitor.MonitorFactory)1 MonitorService (com.alibaba.dubbo.monitor.MonitorService)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 Invoker (com.alibaba.dubbo.rpc.Invoker)1 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)1 LoadBalance (com.alibaba.dubbo.rpc.cluster.LoadBalance)1 StaticDirectory (com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory)1 AbstractClusterInvoker (com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker)1 MyException (com.alibaba.dubbo.rpc.protocol.hessian.HessianServiceImpl.MyException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1