Search in sources :

Example 1 with RestServerFilter

use of rpc.turbo.filter.RestServerFilter in project turbo-rpc by hank-whu.

the class RestHttResponseEncoder method doResponseFilter.

private void doResponseFilter(ChannelHandlerContext ctx, FullHttpRequest request, FullHttpResponse response, Invoker<CompletableFuture<?>> invoker, Throwable throwable) {
    final int filterLength = filters.size();
    if (filterLength == 0) {
        return;
    }
    if (clientAddress == null) {
        InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress();
        clientAddress = new HostPort(insocket.getAddress().getHostAddress(), 0);
    }
    if (serverAddress == null) {
        InetSocketAddress insocket = (InetSocketAddress) ctx.channel().localAddress();
        serverAddress = new HostPort(insocket.getAddress().getHostAddress(), insocket.getPort());
    }
    RemoteContext.setServerAddress(serverAddress);
    RemoteContext.setClientAddress(clientAddress);
    if (invoker != null) {
        RemoteContext.setRemoteMethod(invoker.getMethod());
        RemoteContext.setServiceMethodName(invokerFactory.getServiceMethodName(invoker.getServiceId()));
    } else {
        RemoteContext.setRemoteMethod(null);
        RemoteContext.setServiceMethodName(null);
    }
    if (response.status() == HttpResponseStatus.OK) {
        for (int i = 0; i < filterLength; i++) {
            RestServerFilter filter = filters.get(i);
            filter.onSend(request, response);
        }
    } else {
        for (int i = 0; i < filterLength; i++) {
            RestServerFilter filter = filters.get(i);
            filter.onError(request, response, throwable);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HostPort(rpc.turbo.config.HostPort) RestServerFilter(rpc.turbo.filter.RestServerFilter)

Example 2 with RestServerFilter

use of rpc.turbo.filter.RestServerFilter in project turbo-rpc by hank-whu.

the class NettyRestHandler method doRequestFilter.

private boolean doRequestFilter(FullHttpRequest request, Invoker<CompletableFuture<?>> invoker) {
    final int filterLength = filters.size();
    if (filterLength == 0) {
        return true;
    }
    RemoteContext.setServerAddress(serverAddress);
    RemoteContext.setClientAddress(clientAddress);
    if (invoker != null) {
        RemoteContext.setRemoteMethod(invoker.getMethod());
        RemoteContext.setServiceMethodName(invokerFactory.getServiceMethodName(invoker.getServiceId()));
    } else {
        RemoteContext.setRemoteMethod(null);
        RemoteContext.setServiceMethodName(null);
    }
    for (int i = 0; i < filterLength; i++) {
        RestServerFilter filter = filters.get(i);
        if (!filter.onRecive(request)) {
            return false;
        }
    }
    return true;
}
Also used : RestServerFilter(rpc.turbo.filter.RestServerFilter)

Aggregations

RestServerFilter (rpc.turbo.filter.RestServerFilter)2 InetSocketAddress (java.net.InetSocketAddress)1 HostPort (rpc.turbo.config.HostPort)1