use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class DefaultShenyuContextBuilder method build.
@Override
public ShenyuContext build(final ServerWebExchange exchange) {
ServerHttpRequest request = exchange.getRequest();
String path = request.getURI().getPath();
MetaData metaData = MetaDataCache.getInstance().obtain(path);
HttpHeaders headers = request.getHeaders();
String upgrade = headers.getFirst(UPGRADE);
String rpcType;
if (Objects.nonNull(metaData) && Boolean.TRUE.equals(metaData.getEnabled())) {
exchange.getAttributes().put(Constants.META_DATA, metaData);
rpcType = metaData.getRpcType();
} else if (StringUtils.isNotEmpty(upgrade) && RpcTypeEnum.WEB_SOCKET.getName().equals(upgrade)) {
rpcType = RpcTypeEnum.WEB_SOCKET.getName();
} else {
String rpcTypeParam = request.getHeaders().getFirst(RPC_TYPE);
rpcType = StringUtils.isEmpty(rpcTypeParam) ? RpcTypeEnum.HTTP.getName() : rpcTypeParam;
}
return decoratorMap.get(rpcType).decorator(buildDefaultContext(request), metaData);
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class ApacheDubboMetaDataSubscriberTest method setUp.
@BeforeEach
public void setUp() {
apacheDubboMetaDataSubscriber = new ApacheDubboMetaDataSubscriber();
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());
metaData.setRpcExt("{\"group\":\"Group\",\"version\":\"2.7.5\",\"loadbalance\":\"Balance\",\"url\":\"http://192.168.55.113/dubbo\"}");
metaData.setParameterTypes("parameterTypes");
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class AbstractDubboPlugin method doExecute.
/**
* this is Template Method child has Implement your own logic.
*
* @param exchange exchange the current server exchange {@linkplain ServerWebExchange}
* @param chain chain the current chain {@linkplain ServerWebExchange}
* @param selector selector {@linkplain SelectorData}
* @param rule rule {@linkplain RuleData}
* @return {@code Mono<Void>} to indicate when request handling is complete
*/
@Override
public 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)) {
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 (Objects.nonNull(metaData) && StringUtils.isNoneBlank(metaData.getParameterTypes()) && StringUtils.isBlank(param)) {
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
Object error = ShenyuResultWrap.error(exchange, ShenyuResultEnum.DUBBO_HAVE_BODY_PARAM, null);
return WebFluxResultUtils.result(exchange, error);
}
this.rpcContext(exchange);
return this.doDubboInvoker(exchange, chain, selector, rule, metaData, param);
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class GrpcShenyuContextDecoratorTest method testDecorator.
@Test
public void testDecorator() {
MetaData metaData = new MetaData();
metaData.setAppName("grpc");
metaData.setServiceName("echo");
metaData.setRpcType(PluginEnum.GRPC.getName());
metaData.setContextPath("/grpc");
final ShenyuContext shenyuContext = grpcShenyuContextDecorator.decorator(new ShenyuContext(), metaData);
assertNotNull(shenyuContext);
assertNotNull(shenyuContext.getContextPath());
assertNotNull(shenyuContext.getMethod());
assertNotNull(shenyuContext.getModule());
}
use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.
the class AlibabaDubboMetaDataSubscriberTest method setUp.
@BeforeEach
public void setUp() {
alibabaDubboMetaDataSubscriber = new AlibabaDubboMetaDataSubscriber();
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());
metaData.setRpcExt("{\"group\":\"Group\",\"version\":\"2.6.5\",\"url\":\"http://192.168.55.113/dubbo\"}");
metaData.setParameterTypes("parameterTypes");
}
Aggregations