本文整理汇总了Java中com.alibaba.dubbo.rpc.ProxyFactory类的典型用法代码示例。如果您正苦于以下问题:Java ProxyFactory类的具体用法?Java ProxyFactory怎么用?Java ProxyFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProxyFactory类属于com.alibaba.dubbo.rpc包,在下文中一共展示了ProxyFactory类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHessianProtocol
import com.alibaba.dubbo.rpc.ProxyFactory; //导入依赖的package包/类
@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();
}
示例2: testHttpClient
import com.alibaba.dubbo.rpc.ProxyFactory; //导入依赖的package包/类
@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();
}
示例3: testTimeOut
import com.alibaba.dubbo.rpc.ProxyFactory; //导入依赖的package包/类
@Test
public void testTimeOut() {
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&timeout=10");
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.timeOut(6000);
fail();
} catch (RpcException expected) {
Assert.assertEquals(true, expected.isTimeout());
}finally{
invoker.destroy();
exporter.unexport();
}
}
示例4: testCustomException
import com.alibaba.dubbo.rpc.ProxyFactory; //导入依赖的package包/类
@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();
}
示例5: testRestProtocol
import com.alibaba.dubbo.rpc.ProxyFactory; //导入依赖的package包/类
@Test
public void testRestProtocol() throws InterruptedException {
RestService server = new RestServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
URL url = URL.valueOf("resteasy://127.0.0.1:5342/" + RestService.class.getName() + "?version=1.0.0&logger=slf4j");
ServiceClassHolder.getInstance().pushServiceClass(RestService.class);
Exporter<RestService> exporter = protocol.export(proxyFactory.getInvoker(server, RestService.class, url));
Invoker<RestService> invoker = protocol.refer(RestService.class, url);
RestService client = proxyFactory.getProxy(invoker);
RequestDto requestDto = new RequestDto();
requestDto.setAge(88);
requestDto.setName("doctor who");
ModelResult<String> modelResult = client.test(requestDto);
String expected = "test " + ToStringBuilder.reflectionToString(requestDto, ToStringStyle.SHORT_PREFIX_STYLE);
System.out.println(expected);
Assert.assertEquals(expected, modelResult.getData());
invoker.destroy();
// TimeUnit.MINUTES.sleep(1);
exporter.unexport();
}