@Test public void testDeliverRequestProcessesRequestAfterPreDeliverRequest() { final Option customOption = new Option(200); ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) { @Override protected boolean preDeliverRequest(Exchange exchange) { exchange.getRequest().getOptions().addOption(customOption); return false; } }; deliverer.deliverRequest(incomingRequest); ArgumentCaptor<Exchange> exchangeCaptor = ArgumentCaptor.forClass(Exchange.class); verify(rootResource).handleRequest(exchangeCaptor.capture()); assertTrue(exchangeCaptor.getValue().getRequest().getOptions().hasOption(200)); }
@Override public final void deliverRequest(final Exchange exchange) { if (exchange == null) { throw new NullPointerException("exchange must not be null"); } boolean processed = preDeliverRequest(exchange); if (!processed) { final Resource resource = findResource(exchange); if (resource != null) { checkForObserveOption(exchange, resource); Executor executor = resource.getExecutor(); if (executor != null) { executor.execute(new Runnable() { public void run() { resource.handleRequest(exchange); } }); } else { resource.handleRequest(exchange); } } else { if (LOGGER.isInfoEnabled()) { Request request = exchange.getRequest(); LOGGER.info("did not find resource /{} requested by {}", request.getOptions().getUriPathString(), request.getSourceContext().getPeerAddress()); } exchange.sendResponse(new Response(ResponseCode.NOT_FOUND)); } } }
ServerMessageDeliverer implements MessageDeliverer { @Override public final void deliverRequest(final Exchange exchange) { if (exchange == null) { throw new NullPointerException("exchange must not be null"); } boolean processed = preDeliverRequest(exchange); if (!processed) { final Resource resource = findResource(exchange); if (resource != null) { checkForObserveOption(exchange, resource); Executor executor = resource.getExecutor(); if (executor != null) { executor.execute(new Runnable() { public void run() { resource.handleRequest(exchange); } }); } else { resource.handleRequest(exchange); } } else { if (LOGGER.isInfoEnabled()) { Request request = exchange.getRequest(); LOGGER.info("did not find resource /{} requested by {}", request.getOptions().getUriPathString(), request.getSourceContext().getPeerAddress()); } exchange.sendResponse(new Response(ResponseCode.NOT_FOUND)); } } } }
ServerMessageDeliverer implements MessageDeliverer { @Override public final void deliverRequest(final Exchange exchange) { if (exchange == null) { throw new NullPointerException("exchange must not be null"); } boolean processed = preDeliverRequest(exchange); if (!processed) { final Resource resource = findResource(exchange); if (resource != null) { checkForObserveOption(exchange, resource); Executor executor = resource.getExecutor(); if (executor != null) { executor.execute(new Runnable() { public void run() { resource.handleRequest(exchange); } }); } else { resource.handleRequest(exchange); } } else { if (LOGGER.isInfoEnabled()) { Request request = exchange.getRequest(); LOGGER.info("did not find resource /{} requested by {}", request.getOptions().getUriPathString(), request.getSourceContext().getPeerAddress()); } exchange.sendResponse(new Response(ResponseCode.NOT_FOUND)); } } } ServerMessageDeliverer(final Resource root); }
ServerMessageDeliverer implements MessageDeliverer { @Override public final void deliverRequest(final Exchange exchange) { if (exchange == null) { throw new NullPointerException("exchange must not be null"); } boolean processed = preDeliverRequest(exchange); if (!processed) { final Resource resource = findResource(exchange); if (resource != null) { checkForObserveOption(exchange, resource); Executor executor = resource.getExecutor(); if (executor != null) { executor.execute(new Runnable() { public void run() { resource.handleRequest(exchange); } }); } else { resource.handleRequest(exchange); } } else { if (LOGGER.isInfoEnabled()) { Request request = exchange.getRequest(); LOGGER.info("did not find resource /{} requested by {}", request.getOptions().getUriPathString(), request.getSourceContext().getPeerAddress()); } exchange.sendResponse(new Response(ResponseCode.NOT_FOUND)); } } } ServerMessageDeliverer(final Resource root); @Override final void deliverRequest(final Exchange exchange); @Override final void deliverResponse(final Exchange exchange, final Response response); }
ServerMessageDeliverer implements MessageDeliverer { @Override public final void deliverRequest(final Exchange exchange) { if (exchange == null) { throw new NullPointerException("exchange must not be null"); } boolean processed = preDeliverRequest(exchange); if (!processed) { final Resource resource = findResource(exchange); if (resource != null) { checkForObserveOption(exchange, resource); Executor executor = resource.getExecutor(); if (executor != null) { executor.execute(new Runnable() { public void run() { resource.handleRequest(exchange); } }); } else { resource.handleRequest(exchange); } } else { if (LOGGER.isInfoEnabled()) { Request request = exchange.getRequest(); LOGGER.info("did not find resource /{} requested by {}", request.getOptions().getUriPathString(), request.getSourceContext().getPeerAddress()); } exchange.sendResponse(new Response(ResponseCode.NOT_FOUND)); } } } ServerMessageDeliverer(final Resource root); @Override final void deliverRequest(final Exchange exchange); @Override final void deliverResponse(final Exchange exchange, final Response response);  }