use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class SofaPlugin method doExecute.
@Override
protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
String param = exchange.getAttribute(Constants.PARAM_TRANSFORM);
ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
assert shenyuContext != null;
MetaData metaData = exchange.getAttribute(Constants.META_DATA);
if (!checkMetaData(metaData)) {
assert metaData != null;
LOG.error(" path is :{}, meta data have error.... {}", shenyuContext.getPath(), metaData);
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
Object error = ShenyuResultWrap.error(exchange, ShenyuResultEnum.META_DATA_ERROR, null);
return WebFluxResultUtils.result(exchange, error);
}
if (StringUtils.isNoneBlank(metaData.getParameterTypes()) && StringUtils.isBlank(param)) {
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
Object error = ShenyuResultWrap.error(exchange, ShenyuResultEnum.SOFA_HAVE_BODY_PARAM, null);
return WebFluxResultUtils.result(exchange, error);
}
Map<String, Map<String, String>> rpcContext = exchange.getAttribute(Constants.GENERAL_CONTEXT);
Optional.ofNullable(rpcContext).map(context -> context.get(PluginEnum.SOFA.getName())).ifPresent(context -> RpcInvokeContext.getContext().putAllRequestBaggage(context));
final Mono<Object> result = sofaProxyService.genericInvoker(param, metaData, exchange);
return result.then(chain.execute(exchange));
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class ApplicationConfigCacheTest method testInitPrx.
@Test
public void testInitPrx() {
final MetaData metaData = new MetaData("id", "127.0.0.1:8080", "contextPath", "path6", RpcTypeEnum.TARS.getName(), "serviceName6", "method1", "parameterTypes", "{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":[{\"left\":\"int\",\"right\":\"param1\"}," + "{\"left\":\"java.lang.Integer\",\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}", false);
assertThrows(NullPointerException.class, () -> {
applicationConfigCacheUnderTest.initPrx(metaData);
final TarsInvokePrxList result = applicationConfigCacheUnderTest.get("path6");
assertEquals("promise_method1", result.getMethod().getName());
});
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class PrxInfoUtilTest method testGetPrxName.
@Test
public void testGetPrxName() {
final MetaData metaData = new MetaData("id", "appName", "contextPath", "/path", "rpcType", "serviceName", "methodName", "parameterTypes", "rpcExt", false);
final String result = PrxInfoUtil.getPrxName(metaData);
assertEquals("pathmethodNamePrx", result);
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class ZookeeperSyncDataServiceTest method setUp.
@BeforeEach
public void setUp() {
zkClient = mock(ZkClient.class);
// mock plugin data & method
PluginData pluginData = PluginData.builder().name(MOCK_PLUGIN_NAME).enabled(Boolean.FALSE).build();
when(zkClient.exists(anyString())).thenReturn(Boolean.FALSE);
when(zkClient.readData(MOCK_PLUGIN_PATH)).thenReturn(GsonUtils.getInstance().toJson(pluginData));
when(zkClient.getChildren(MOCK_PLUGIN_PARENT_PATH)).thenReturn(Lists.newArrayList(MOCK_PLUGIN_NAME));
// mock selector data & method
SelectorData selectorData = SelectorData.builder().name(MOCK_SELECTOR_NAME).enabled(Boolean.FALSE).build();
when(zkClient.readData(MOCK_SELECTOR_PATH)).thenReturn(GsonUtils.getInstance().toJson(selectorData));
when(zkClient.getChildren(MOCK_SELECTOR_PARENT_PATH)).thenReturn(Lists.newArrayList(MOCK_SELECTOR_NAME));
// mock rule data & method
RuleData ruleData = RuleData.builder().name(MOCK_RULE_NAME).enabled(Boolean.FALSE).build();
when(zkClient.readData(MOCK_RULE_PATH)).thenReturn(GsonUtils.getInstance().toJson(ruleData));
when(zkClient.getChildren(MOCK_RULE_PARENT_PATH)).thenReturn(Lists.newArrayList(MOCK_RULE_NAME));
// mock auth data & method
AppAuthData appAuthData = AppAuthData.builder().appKey(MOCK_APP_AUTH_KEY).enabled(Boolean.FALSE).build();
when(zkClient.readData(MOCK_APP_AUTH_PATH)).thenReturn(GsonUtils.getInstance().toJson(appAuthData));
when(zkClient.getChildren(MOCK_APP_AUTH_PARENT_PATH)).thenReturn(Lists.newArrayList(MOCK_APP_AUTH_KEY));
// mock meta data & method
MetaData metaData = MetaData.builder().id(MOCK_META_DATA_ID).enabled(Boolean.FALSE).build();
when(zkClient.readData(MOCK_META_DATA_PATH)).thenReturn(GsonUtils.getInstance().toJson(metaData));
when(zkClient.getChildren(MOCK_META_DATA_PARENT_PATH)).thenReturn(Lists.newArrayList(MOCK_META_DATA_ID));
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class ZookeeperSyncDataServiceTest method testWatchMetaDataWhenDataDeleted.
@Test
public void testWatchMetaDataWhenDataDeleted() throws Exception {
final List<MetaData> unSubscribeList = new ArrayList<>(1);
MetaDataSubscriber metaDataSubscriber = new MetaDataSubscriber() {
@Override
public void onSubscribe(final MetaData metaData) {
}
@Override
public void unSubscribe(final MetaData metaData) {
unSubscribeList.add(metaData);
}
};
syncDataService = new ZookeeperSyncDataService(zkClient, null, Lists.newArrayList(metaDataSubscriber), Collections.emptyList());
ArgumentCaptor<IZkDataListener> captor = ArgumentCaptor.forClass(IZkDataListener.class);
verify(zkClient).subscribeDataChanges(eq(MOCK_META_DATA_PATH), captor.capture());
captor.getValue().handleDataDeleted(MOCK_META_DATA_PATH);
assertThat(unSubscribeList.size(), is(1));
assertThat(unSubscribeList.get(0).getPath(), is(MOCK_META_DATA_ID));
}
Aggregations