use of com.weibo.api.motan.rpc.Provider in project motan by weibocom.
the class YarMessageRouterTest method testHandle.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testHandle() {
response = new DefaultResponse();
response.setValue("test");
response.setProcessTime(1);
Provider provider = new DefaultProvider(null, null, AnnoService.class);
router.addProvider(provider);
YarRequest yarRequest = new YarRequest(1, "JSON", "hello", new Object[] { "params" });
yarRequest.setRequestPath(requestPath);
YarResponse yarResponse = (YarResponse) router.handle(null, yarRequest);
assertEquals(YarProtocolUtil.convert(response, "JSON"), yarResponse);
}
use of com.weibo.api.motan.rpc.Provider in project motan by weibocom.
the class YarRpcProtocolTest method testInitRequestRouter.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testInitRequestRouter() {
YarRpcProtocol protocol = new YarRpcProtocol();
URL url = new URL("motan", "localhost", 8002, "urlpath");
Provider provider = new DefaultProvider(null, url, MessageHandler.class);
ProviderMessageRouter router = protocol.initRequestRouter(url, provider);
assertNotNull(router);
URL url2 = new URL("motan", "localhost", 8003, "urlpath2");
Provider provider2 = new DefaultProvider(null, url2, MessageHandler.class);
ProviderMessageRouter router2 = protocol.initRequestRouter(url2, provider2);
assertNotNull(router2);
assertFalse(router2.equals(router));
URL url3 = new URL("motan", "localhost", 8002, "urlpath3");
Provider provider3 = new DefaultProvider(null, url3, MessageHandler.class);
ProviderMessageRouter router3 = protocol.initRequestRouter(url3, provider3);
assertNotNull(router3);
assertTrue(router3.equals(router));
try {
protocol.initRequestRouter(url, provider);
assertTrue(false);
} catch (Exception e) {
assertTrue(e.getMessage().contains("duplicate yar provider"));
}
}
use of com.weibo.api.motan.rpc.Provider in project motan by weibocom.
the class YarMessageRouterTest method testAddProvider.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testAddProvider() {
Provider provider = new DefaultProvider(null, null, AnnoService.class);
router.addProvider(provider);
assertTrue(router.checkProvider(requestPath));
router.removeProvider(provider);
assertFalse(router.checkProvider(requestPath));
URL url = new URL("motan", "localhost", 8002, "urlpath");
provider = new DefaultProvider(null, url, normalService.class);
router.addProvider(provider);
assertTrue(router.checkProvider(YarProtocolUtil.getYarPath(normalService.class, url)));
router.removeProvider(provider);
assertFalse(router.checkProvider(YarProtocolUtil.getYarPath(normalService.class, url)));
}
use of com.weibo.api.motan.rpc.Provider in project motan by weibocom.
the class GrpcServer method addExporter.
@SuppressWarnings("rawtypes")
public void addExporter(Exporter<?> exporter) throws Exception {
Provider provider = exporter.getProvider();
ServerServiceDefinition serviceDefine = GrpcUtil.getServiceDefByAnnotation(provider.getInterface());
boolean urlShareChannel = exporter.getUrl().getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
synchronized (serviceDefinetions) {
if (!(shareChannel && urlShareChannel) && !serviceDefinetions.isEmpty()) {
URL url = serviceDefinetions.keySet().iterator().next();
throw new MotanFrameworkException("url:" + exporter.getUrl() + " cannot share channel with url:" + url);
}
registry.addService(serviceDefine, provider);
if (httpHandler != null) {
httpHandler.addProvider(provider);
}
serviceDefinetions.put(exporter.getUrl(), serviceDefine);
}
}
use of com.weibo.api.motan.rpc.Provider in project motan by weibocom.
the class NettyHttpRequestHandler method processHttpRequest.
@SuppressWarnings("rawtypes")
protected void processHttpRequest(ChannelHandlerContext ctx, FullHttpRequest httpRequest) {
FullHttpResponse httpResponse = null;
try {
DefaultRequest rpcRequest = buildRpcRequest(httpRequest);
String ip = NetUtils.getHostName(ctx.channel().remoteAddress());
if (ip != null) {
rpcRequest.setAttachment(URLParamType.host.getName(), ip);
}
Provider provider = providerMap.get(rpcRequest.getInterfaceName());
if (provider == null) {
httpResponse = buildErrorResponse("request service not exist. service:" + rpcRequest.getInterfaceName());
} else {
Response response = provider.call(rpcRequest);
httpResponse = buildHttpResponse(response, HttpUtil.isKeepAlive(httpRequest));
}
} catch (Exception e) {
LoggerUtil.error("NettyHttpHandler process http request fail.", e);
httpResponse = buildErrorResponse(e.getMessage());
} finally {
httpRequest.content().release();
}
sendResponse(ctx, httpResponse);
}
Aggregations