use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class DubboProtocol method initClient.
/**
* Create new connection
*
* @param url
*/
private ExchangeClient initClient(URL url) {
// client type setting.
String str = url.getParameter(CLIENT_KEY, url.getParameter(SERVER_KEY, DEFAULT_REMOTING_CLIENT));
url = url.addParameter(CODEC_KEY, DubboCodec.NAME);
// enable heartbeat by default
url = url.addParameterIfAbsent(HEARTBEAT_KEY, String.valueOf(DEFAULT_HEARTBEAT));
// BIO is not allowed since it has severe performance issue.
if (str != null && str.length() > 0 && !ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) {
throw new RpcException("Unsupported client type: " + str + "," + " supported client type is " + StringUtils.join(ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(), " "));
}
ExchangeClient client;
try {
// connection should be lazy
if (url.getParameter(LAZY_CONNECT_KEY, false)) {
client = new LazyConnectExchangeClient(url, requestHandler);
} else {
client = Exchangers.connect(url, requestHandler);
}
} catch (RemotingException e) {
throw new RpcException("Fail to create remoting client for service(" + url + "): " + e.getMessage(), e);
}
return client;
}
use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class DubboProtocol method createServer.
private ProtocolServer createServer(URL url) {
url = URLBuilder.from(url).addParameterIfAbsent(CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()).addParameterIfAbsent(HEARTBEAT_KEY, String.valueOf(DEFAULT_HEARTBEAT)).addParameter(CODEC_KEY, DubboCodec.NAME).build();
String str = url.getParameter(SERVER_KEY, DEFAULT_REMOTING_SERVER);
if (str != null && str.length() > 0 && !ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) {
throw new RpcException("Unsupported server type: " + str + ", url: " + url);
}
ExchangeServer server;
try {
server = Exchangers.bind(url, requestHandler);
} catch (RemotingException e) {
throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e);
}
str = url.getParameter(CLIENT_KEY);
if (str != null && str.length() > 0) {
Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions();
if (!supportedTypes.contains(str)) {
throw new RpcException("Unsupported client type: " + str);
}
}
return new DubboProtocolServer(server);
}
use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class ChannelWrappedInvoker method doInvoke.
@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
RpcInvocation inv = (RpcInvocation) invocation;
// use interface's name as service path to export if it's not found on client side
inv.setAttachment(PATH_KEY, getInterface().getName());
inv.setAttachment(CALLBACK_SERVICE_KEY, serviceKey);
try {
if (RpcUtils.isOneway(getUrl(), inv)) {
// may have concurrency issue
currentClient.send(inv, getUrl().getMethodParameter(invocation.getMethodName(), SENT_KEY, false));
return AsyncRpcResult.newDefaultAsyncResult(invocation);
} else {
final String methodName = RpcUtils.getMethodName(invocation);
final int timeout = (int) RpcUtils.getTimeout(getUrl(), methodName, RpcContext.getContext(), DEFAULT_TIMEOUT);
CompletableFuture<AppResponse> appResponseFuture = currentClient.request(inv, timeout, null).thenApply(obj -> (AppResponse) obj);
return new AsyncRpcResult(appResponseFuture, inv);
}
} catch (RpcException e) {
throw e;
} catch (TimeoutException e) {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, e.getMessage(), e);
} catch (RemotingException e) {
throw new RpcException(RpcException.NETWORK_EXCEPTION, e.getMessage(), e);
} catch (Throwable e) {
// here is non-biz exception, wrap it.
throw new RpcException(e.getMessage(), e);
}
}
use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class ConfigTest method test_RpcContext_getUrls.
// DUBBO-147 find all invoker instances which have been tried from RpcContext
@Test
public void test_RpcContext_getUrls() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-long-waiting.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference-getUrls.xml");
ctx.start();
try {
DemoService demoService = (DemoService) ctx.getBean("demoService");
try {
demoService.sayName("Haha");
fail();
} catch (RpcException expected) {
assertThat(expected.getMessage(), containsString("Tried 3 times"));
}
assertEquals(3, RpcContext.getContext().getUrls().size());
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
use of org.apache.dubbo.rpc.RpcException in project dubbo by alibaba.
the class ConfigTest method test_retrySettingFail.
// BUG: DUBBO-846 in version 2.0.9, config retry="false" on provider's method doesn't work
@Test
public void test_retrySettingFail() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-long-waiting.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference-retry-false.xml");
ctx.start();
try {
DemoService demoService = (DemoService) ctx.getBean("demoService");
try {
demoService.sayName("Haha");
fail();
} catch (RpcException expected) {
assertThat(expected.getMessage(), containsString("Tried 1 times"));
}
assertEquals(1, RpcContext.getContext().getUrls().size());
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
Aggregations