@Test public void testSomeMethod() throws IOException { mockedContext.setMessage( createBadXdr() ); assertEquals(STOP, filter.handleRead(mockedContext).type()); }
@Override public NextAction handleRead(FilterChainContext ctx) throws IOException { Xdr xdr = ctx.getMessage(); if (xdr == null) { _log.error("Parser returns bad XDR"); return ctx.getStopAction(); } xdr.beginDecoding(); RpcMessage message = new RpcMessage(xdr); RpcTransport transport = new GrizzlyRpcTransport(ctx.getConnection(), (InetSocketAddress)ctx.getAddress(), _replyQueue); switch (message.type()) { case RpcMessageType.CALL: RpcCall call = new RpcCall(message.xid(), xdr, transport); try { call.accept(); ctx.setMessage(call); } catch (RpcException e) { call.reject(e.getStatus(), e.getRpcReply()); _log.info("RPC request rejected: {}", e.getMessage()); return ctx.getStopAction(); } catch (OncRpcException e) { _log.info("failed to process RPC request: {}", e.getMessage()); return ctx.getStopAction(); } return ctx.getInvokeAction(); case RpcMessageType.REPLY: try { RpcReply reply = new RpcReply(message.xid(), xdr, transport); CompletionHandler<RpcReply, RpcTransport> callback = _replyQueue.get(message.xid()); if (callback != null) { if (!reply.isAccepted()) { callback.failed(new OncRpcRejectedException(reply.getRejectStatus()), transport); } else if (reply.getAcceptStatus() != RpcAccepsStatus.SUCCESS) { callback.failed(new OncRpcAcceptedException(reply.getAcceptStatus()), transport); } else { callback.completed(reply, transport); } } } catch (OncRpcException e) { _log.warn("failed to decode reply:", e); } return ctx.getStopAction(); default: return ctx.getStopAction(); } }
RpcProtocolFilter extends BaseFilter { @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { Xdr xdr = ctx.getMessage(); if (xdr == null) { _log.error("Parser returns bad XDR"); return ctx.getStopAction(); } xdr.beginDecoding(); RpcMessage message = new RpcMessage(xdr); RpcTransport transport = new GrizzlyRpcTransport(ctx.getConnection(), (InetSocketAddress)ctx.getAddress(), _replyQueue); switch (message.type()) { case RpcMessageType.CALL: RpcCall call = new RpcCall(message.xid(), xdr, transport); try { call.accept(); ctx.setMessage(call); } catch (RpcException e) { call.reject(e.getStatus(), e.getRpcReply()); _log.info("RPC request rejected: {}", e.getMessage()); return ctx.getStopAction(); } catch (OncRpcException e) { _log.info("failed to process RPC request: {}", e.getMessage()); return ctx.getStopAction(); } return ctx.getInvokeAction(); case RpcMessageType.REPLY: try { RpcReply reply = new RpcReply(message.xid(), xdr, transport); CompletionHandler<RpcReply, RpcTransport> callback = _replyQueue.get(message.xid()); if (callback != null) { if (!reply.isAccepted()) { callback.failed(new OncRpcRejectedException(reply.getRejectStatus()), transport); } else if (reply.getAcceptStatus() != RpcAccepsStatus.SUCCESS) { callback.failed(new OncRpcAcceptedException(reply.getAcceptStatus()), transport); } else { callback.completed(reply, transport); } } } catch (OncRpcException e) { _log.warn("failed to decode reply:", e); } return ctx.getStopAction(); default: return ctx.getStopAction(); } } }
RpcProtocolFilter extends BaseFilter { @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { Xdr xdr = ctx.getMessage(); if (xdr == null) { _log.error("Parser returns bad XDR"); return ctx.getStopAction(); } xdr.beginDecoding(); RpcMessage message = new RpcMessage(xdr); RpcTransport transport = new GrizzlyRpcTransport(ctx.getConnection(), (InetSocketAddress)ctx.getAddress(), _replyQueue); switch (message.type()) { case RpcMessageType.CALL: RpcCall call = new RpcCall(message.xid(), xdr, transport); try { call.accept(); ctx.setMessage(call); } catch (RpcException e) { call.reject(e.getStatus(), e.getRpcReply()); _log.info("RPC request rejected: {}", e.getMessage()); return ctx.getStopAction(); } catch (OncRpcException e) { _log.info("failed to process RPC request: {}", e.getMessage()); return ctx.getStopAction(); } return ctx.getInvokeAction(); case RpcMessageType.REPLY: try { RpcReply reply = new RpcReply(message.xid(), xdr, transport); CompletionHandler<RpcReply, RpcTransport> callback = _replyQueue.get(message.xid()); if (callback != null) { if (!reply.isAccepted()) { callback.failed(new OncRpcRejectedException(reply.getRejectStatus()), transport); } else if (reply.getAcceptStatus() != RpcAccepsStatus.SUCCESS) { callback.failed(new OncRpcAcceptedException(reply.getAcceptStatus()), transport); } else { callback.completed(reply, transport); } } } catch (OncRpcException e) { _log.warn("failed to decode reply:", e); } return ctx.getStopAction(); default: return ctx.getStopAction(); } } RpcProtocolFilter(ReplyQueue replyQueue); }
RpcProtocolFilter extends BaseFilter { @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { Xdr xdr = ctx.getMessage(); if (xdr == null) { _log.error("Parser returns bad XDR"); return ctx.getStopAction(); } xdr.beginDecoding(); RpcMessage message = new RpcMessage(xdr); RpcTransport transport = new GrizzlyRpcTransport(ctx.getConnection(), (InetSocketAddress)ctx.getAddress(), _replyQueue); switch (message.type()) { case RpcMessageType.CALL: RpcCall call = new RpcCall(message.xid(), xdr, transport); try { call.accept(); ctx.setMessage(call); } catch (RpcException e) { call.reject(e.getStatus(), e.getRpcReply()); _log.info("RPC request rejected: {}", e.getMessage()); return ctx.getStopAction(); } catch (OncRpcException e) { _log.info("failed to process RPC request: {}", e.getMessage()); return ctx.getStopAction(); } return ctx.getInvokeAction(); case RpcMessageType.REPLY: try { RpcReply reply = new RpcReply(message.xid(), xdr, transport); CompletionHandler<RpcReply, RpcTransport> callback = _replyQueue.get(message.xid()); if (callback != null) { if (!reply.isAccepted()) { callback.failed(new OncRpcRejectedException(reply.getRejectStatus()), transport); } else if (reply.getAcceptStatus() != RpcAccepsStatus.SUCCESS) { callback.failed(new OncRpcAcceptedException(reply.getAcceptStatus()), transport); } else { callback.completed(reply, transport); } } } catch (OncRpcException e) { _log.warn("failed to decode reply:", e); } return ctx.getStopAction(); default: return ctx.getStopAction(); } } RpcProtocolFilter(ReplyQueue replyQueue); @Override NextAction handleRead(FilterChainContext ctx); }
RpcProtocolFilter extends BaseFilter { @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { Xdr xdr = ctx.getMessage(); if (xdr == null) { _log.error("Parser returns bad XDR"); return ctx.getStopAction(); } xdr.beginDecoding(); RpcMessage message = new RpcMessage(xdr); RpcTransport transport = new GrizzlyRpcTransport(ctx.getConnection(), (InetSocketAddress)ctx.getAddress(), _replyQueue); switch (message.type()) { case RpcMessageType.CALL: RpcCall call = new RpcCall(message.xid(), xdr, transport); try { call.accept(); ctx.setMessage(call); } catch (RpcException e) { call.reject(e.getStatus(), e.getRpcReply()); _log.info("RPC request rejected: {}", e.getMessage()); return ctx.getStopAction(); } catch (OncRpcException e) { _log.info("failed to process RPC request: {}", e.getMessage()); return ctx.getStopAction(); } return ctx.getInvokeAction(); case RpcMessageType.REPLY: try { RpcReply reply = new RpcReply(message.xid(), xdr, transport); CompletionHandler<RpcReply, RpcTransport> callback = _replyQueue.get(message.xid()); if (callback != null) { if (!reply.isAccepted()) { callback.failed(new OncRpcRejectedException(reply.getRejectStatus()), transport); } else if (reply.getAcceptStatus() != RpcAccepsStatus.SUCCESS) { callback.failed(new OncRpcAcceptedException(reply.getAcceptStatus()), transport); } else { callback.completed(reply, transport); } } } catch (OncRpcException e) { _log.warn("failed to decode reply:", e); } return ctx.getStopAction(); default: return ctx.getStopAction(); } } RpcProtocolFilter(ReplyQueue replyQueue); @Override NextAction handleRead(FilterChainContext ctx);  }