Search in sources :

Example 16 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class GenericServiceTest method testGenericFindComplexObject4FullServiceMetadata.

@Test
public void testGenericFindComplexObject4FullServiceMetadata() {
    DemoService server = new DemoServiceImpl();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000");
    Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url));
    String var1 = "v1";
    int var2 = 234;
    long l = 555;
    String[] var3 = { "var31", "var32" };
    List<Integer> var4 = Arrays.asList(2, 4, 8);
    ComplexObject.TestEnum testEnum = ComplexObject.TestEnum.VALUE2;
    // ComplexObject complexObject = createComplexObject(var1, var2, l, var3, var4, testEnum);
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    Object result = client.$invoke("findComplexObject", new String[] { "java.lang.String", "int", "long", "java.lang.String[]", "java.util.List", "org.apache.dubbo.service.ComplexObject$TestEnum" }, new Object[] { var1, var2, l, var3, var4, testEnum });
    Assertions.assertNotNull(result);
    ComplexObject r = map2bean((Map) result);
    Assertions.assertEquals(r, createComplexObject(var1, var2, l, var3, var4, testEnum));
    invoker.destroy();
    exporter.unexport();
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) DemoService(org.apache.dubbo.service.DemoService) URL(org.apache.dubbo.common.URL) ComplexObject(org.apache.dubbo.service.ComplexObject) ComplexObject(org.apache.dubbo.service.ComplexObject) Protocol(org.apache.dubbo.rpc.Protocol) DemoServiceImpl(org.apache.dubbo.service.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 17 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class XmlRpcProtocolTest method testXmlRpcProtocolForServerJetty9.

@Test
public void testXmlRpcProtocolForServerJetty9() {
    XmlRpcServiceImpl server = new XmlRpcServiceImpl();
    Assertions.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("xmlrpc://127.0.0.1:" + port + "/" + XmlRpcService.class.getName() + "?version=1.0.0&server=jetty9");
    Exporter<XmlRpcService> exporter = protocol.export(proxyFactory.getInvoker(server, XmlRpcService.class, url));
    Invoker<XmlRpcService> invoker = protocol.refer(XmlRpcService.class, url);
    XmlRpcService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assertions.assertTrue(server.isCalled());
    Assertions.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 18 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class XmlRpcProtocolTest method testCustomException.

@Test
@Disabled
public void testCustomException() {
    XmlRpcServiceImpl server = new XmlRpcServiceImpl();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("xmlrpc://127.0.0.1:" + port + "/" + XmlRpcService.class.getName() + "?version=1.0.0&server=jetty9");
    Exporter<XmlRpcService> exporter = protocol.export(proxyFactory.getInvoker(server, XmlRpcService.class, url));
    Invoker<XmlRpcService> invoker = protocol.refer(XmlRpcService.class, url);
    XmlRpcService client = proxyFactory.getProxy(invoker);
    try {
        client.customException();
        Assertions.fail();
    } catch (XmlRpcServiceImpl.MyException expected) {
    }
    invoker.destroy();
    exporter.unexport();
}
Also used : ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 19 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class MockClusterInvokerTest method getClusterInvokerMock.

private Invoker<IHelloService> getClusterInvokerMock(URL url, Invoker<IHelloService> mockInvoker) {
    // 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);
    if (mockInvoker != null) {
        invokers.add(mockInvoker);
    }
    StaticDirectory<IHelloService> dic = new StaticDirectory<IHelloService>(durl, invokers, null);
    dic.buildRouterChain();
    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 : Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) URL(org.apache.dubbo.common.URL) StaticDirectory(org.apache.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(org.apache.dubbo.rpc.Invoker) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with ProxyFactory

use of org.apache.dubbo.rpc.ProxyFactory in project dubbo by alibaba.

the class MockProviderRpcExceptionTest method getClusterInvokerMock.

private Invoker<IHelloRpcService> getClusterInvokerMock(URL url, Invoker<IHelloRpcService> mockInvoker) {
    // 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<IHelloRpcService> invoker1 = proxy.getInvoker(new HelloRpcService(), IHelloRpcService.class, durl);
    invokers.add(invoker1);
    if (mockInvoker != null) {
        invokers.add(mockInvoker);
    }
    StaticDirectory<IHelloRpcService> dic = new StaticDirectory<IHelloRpcService>(durl, invokers, null);
    dic.buildRouterChain();
    AbstractClusterInvoker<IHelloRpcService> 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<IHelloRpcService>(dic, cluster);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) URL(org.apache.dubbo.common.URL) StaticDirectory(org.apache.dubbo.rpc.cluster.directory.StaticDirectory) Invoker(org.apache.dubbo.rpc.Invoker) AbstractClusterInvoker(org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker) LoadBalance(org.apache.dubbo.rpc.cluster.LoadBalance) RpcException(org.apache.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

URL (org.apache.dubbo.common.URL)27 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)27 Protocol (org.apache.dubbo.rpc.Protocol)25 Test (org.junit.jupiter.api.Test)25 GenericService (org.apache.dubbo.rpc.service.GenericService)10 DemoService (org.apache.dubbo.service.DemoService)6 DemoServiceImpl (org.apache.dubbo.service.DemoServiceImpl)6 ComplexObject (org.apache.dubbo.service.ComplexObject)5 Invoker (org.apache.dubbo.rpc.Invoker)3 RpcException (org.apache.dubbo.rpc.RpcException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Invocation (org.apache.dubbo.rpc.Invocation)2 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)2 LoadBalance (org.apache.dubbo.rpc.cluster.LoadBalance)2 StaticDirectory (org.apache.dubbo.rpc.cluster.directory.StaticDirectory)2 AbstractClusterInvoker (org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker)2 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1