use of io.github.tesla.filter.domain.FilterRpcDO in project tesla by linking12.
the class FilterRouteServiceImpl method save.
@Override
public int save(FilterRouteDto routeDto) {
FilterRouteDO routeDo = routeDto.buildRoute();
FilterRpcDO rpcDo = routeDto.buildRpc();
int success2 = routeDao.save(routeDo);
Long routeId = routeDo.getId();
rpcDo.setRouteId(routeId);
if (routeDo.getRpc()) {
int success1 = rpcDao.save(rpcDo);
if (success1 > 0 && success2 > 0) {
return CommonResponse.SUCCESS;
} else {
return CommonResponse.ERROR;
}
}
return success2;
}
use of io.github.tesla.filter.domain.FilterRpcDO in project tesla by linking12.
the class DynamicsRouteCacheComponent method doCache.
@Override
protected void doCache() {
try {
readWriteLock.writeLock().lock();
// clear data
ROUTE_CACHE.clear();
RPC_CACHE.clear();
// cache all data
List<FilterRouteDO> routes = routeDao.list(Maps.newHashMap());
for (FilterRouteDO route : routes) {
FilterRouteDO routeCopy = route.copy();
String path = routeCopy.getFromPath();
ROUTE_CACHE.put(path, routeCopy);
}
List<FilterRpcDO> rpcs = rpcDao.list(Maps.newHashMap());
for (FilterRpcDO rpc : rpcs) {
FilterRpcDO rpcCopy = rpc.copy();
RPC_CACHE.put(rpcCopy.getRouteId(), rpcCopy);
}
} finally {
readWriteLock.writeLock().unlock();
}
}
use of io.github.tesla.filter.domain.FilterRpcDO in project tesla by linking12.
the class DubboTransformHttpRequestFilter method doFilter.
@Override
public HttpResponse doFilter(HttpRequest originalRequest, HttpObject httpObject, ChannelHandlerContext channelHandlerContext) {
if (originalRequest instanceof FullHttpRequest && dubboClient != null) {
FullHttpRequest request = (FullHttpRequest) originalRequest;
String urlPath = request.uri();
FilterRpcDO rpc = routeRuleCache.getRpc(urlPath);
if (rpc != null) {
ByteBuf jsonBuf = request.content();
String jsonInput = jsonBuf.toString(CharsetUtil.UTF_8);
String jsonOutput = dubboClient.doRemoteCall(rpc, jsonInput);
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(jsonOutput.getBytes(CharsetUtil.UTF_8)));
} else {
// 如果从缓存没有查到dubbo的映射信息,说明不是泛化调用,返回空,继续走下一个filter或者去走rest服务发现等
return null;
}
}
return null;
}
use of io.github.tesla.filter.domain.FilterRpcDO in project tesla by linking12.
the class GrpcTransformHttpRequestFilter method doFilter.
@Override
public HttpResponse doFilter(HttpRequest originalRequest, HttpObject httpObject, ChannelHandlerContext channelHandlerContext) {
if (originalRequest instanceof FullHttpRequest && grpcClient != null) {
FullHttpRequest request = (FullHttpRequest) originalRequest;
String urlPath = request.uri();
FilterRpcDO rpc = routeRuleCache.getRpc(urlPath);
if (rpc != null) {
ByteBuf jsonBuf = request.content();
String jsonInput = jsonBuf.toString(CharsetUtil.UTF_8);
String jsonOutput = grpcClient.doRemoteCall(rpc, jsonInput);
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(jsonOutput.getBytes(CharsetUtil.UTF_8)));
} else {
// 如果从缓存没有查到grpc的映射信息,说明不是泛化调用,返回空,继续走下一个filter或者去走rest服务发现等
return null;
}
}
return null;
}
Aggregations