use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class ApacheDubboMetaDataSubscriber method onSubscribe.
@Override
public void onSubscribe(final MetaData metaData) {
if (RpcTypeEnum.DUBBO.getName().equals(metaData.getRpcType())) {
MetaData exist = META_DATA.get(metaData.getPath());
if (Objects.isNull(exist) || Objects.isNull(ApacheDubboConfigCache.getInstance().get(metaData.getPath()))) {
// The first initialization
ApacheDubboConfigCache.getInstance().initRef(metaData);
} else {
// because these four properties will affect the call of Dubbo;
if (!Objects.equals(metaData.getServiceName(), exist.getServiceName()) || !Objects.equals(metaData.getRpcExt(), exist.getRpcExt()) || !Objects.equals(metaData.getParameterTypes(), exist.getParameterTypes()) || !Objects.equals(metaData.getMethodName(), exist.getMethodName())) {
ApacheDubboConfigCache.getInstance().build(metaData);
}
}
META_DATA.put(metaData.getPath(), metaData);
}
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class ApacheDubboPluginTest method setUp.
@BeforeEach
public void setUp() {
exchange = MockServerWebExchange.from(MockServerHttpRequest.get("localhost").build());
metaData = new MetaData();
metaData.setId("1332017966661636096");
metaData.setAppName("dubbo");
metaData.setPath("/dubbo/findAll");
metaData.setServiceName("org.apache.shenyu.test.dubbo.api.service.DubboTestService");
metaData.setMethodName("findAll");
metaData.setRpcType(RpcTypeEnum.DUBBO.getName());
ApacheDubboProxyService apacheDubboProxyService = mock(ApacheDubboProxyService.class);
apacheDubboPlugin = new ApacheDubboPlugin(apacheDubboProxyService);
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class ApacheDubboPluginTest method testMethodIsNullExecute.
@Test
public void testMethodIsNullExecute() {
ShenyuContext context = mock(ShenyuContext.class);
exchange.getAttributes().put(Constants.CONTEXT, context);
exchange.getAttributes().put(Constants.PARAM_TRANSFORM, "{key:value}");
MetaData metaData = MetaData.builder().id("1332017966661636096").appName("dubbo").path("/dubbo/findAll").serviceName("org.apache.shenyu.test.dubbo.api.service.DubboTestService").rpcType(RpcTypeEnum.DUBBO.getName()).build();
exchange.getAttributes().put(Constants.META_DATA, metaData);
SelectorData selectorData = mock(SelectorData.class);
RuleData data = mock(RuleData.class);
assertThrows(NullPointerException.class, () -> {
StepVerifier.create(apacheDubboPlugin.doExecute(exchange, chain, selectorData, data)).expectSubscription().verifyComplete();
});
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class ApacheDubboConfigCacheTest method testBuild.
@Test
public void testBuild() {
DubboParam dubboParamExtInfo = new DubboParam();
dubboParamExtInfo.setVersion("2.7.5");
dubboParamExtInfo.setGroup("Group");
dubboParamExtInfo.setLoadbalance("Balance");
dubboParamExtInfo.setUrl("http://192.168.55.113/dubbo");
MetaData metaData = new MetaData();
metaData.setRpcExt(GsonUtils.getInstance().toJson(dubboParamExtInfo));
ApacheDubboConfigCache apacheDubboConfigCacheMock = mock(ApacheDubboConfigCache.class);
when(apacheDubboConfigCacheMock.build(metaData)).thenReturn(new ReferenceConfig<>());
assertNotNull(apacheDubboConfigCacheMock.build(metaData));
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class MotanProxyService method genericInvoker.
/**
* Generic invoker object.
*
* @param body the body
* @param metaData the meta data
* @param exchange the exchange
* @return the object
* @throws ShenyuException the shenyu exception
*/
@SuppressWarnings("all")
public Mono<Object> genericInvoker(final String body, final MetaData metaData, final ServerWebExchange exchange) throws ShenyuException {
Map<String, Map<String, String>> rpcContext = exchange.getAttribute(Constants.GENERAL_CONTEXT);
Optional.ofNullable(rpcContext).map(context -> context.get(PluginEnum.MOTAN.getName())).ifPresent(context -> {
context.forEach((k, v) -> RpcContext.getContext().setRpcAttachment(k, v));
});
RefererConfig<CommonHandler> reference = ApplicationConfigCache.getInstance().get(metaData.getPath());
if (Objects.isNull(reference) || StringUtils.isEmpty(reference.getServiceInterface())) {
ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
reference = ApplicationConfigCache.getInstance().initRef(metaData);
}
CommonHandler commonHandler = reference.getRef();
ApplicationConfigCache.MotanParamInfo motanParamInfo = ApplicationConfigCache.PARAM_MAP.get(metaData.getMethodName());
Object[] params;
if (Objects.isNull(motanParamInfo)) {
params = new Object[0];
} else {
int num = motanParamInfo.getParamTypes().length;
params = new Object[num];
Map<String, Object> bodyMap = GsonUtils.getInstance().convertToMap(body);
for (int i = 0; i < num; i++) {
params[i] = bodyMap.get(motanParamInfo.getParamNames()[i]).toString();
}
}
ResponseFuture responseFuture;
// CHECKSTYLE:OFF IllegalCatch
try {
responseFuture = (ResponseFuture) commonHandler.asyncCall(metaData.getMethodName(), params, Object.class);
} catch (Throwable e) {
LOG.error("Exception caught in MotanProxyService#genericInvoker.", e);
return null;
}
// CHECKSTYLE:ON IllegalCatch
ResponseFuture finalResponseFuture = responseFuture;
CompletableFuture<Object> future = CompletableFuture.supplyAsync(finalResponseFuture::getValue);
return Mono.fromFuture(future.thenApply(ret -> {
if (Objects.isNull(ret)) {
ret = Constants.MOTAN_RPC_RESULT_EMPTY;
}
exchange.getAttributes().put(Constants.RPC_RESULT, ret);
exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE, ResultEnum.SUCCESS.getName());
return ret;
})).onErrorMap(ShenyuException::new);
}
Aggregations