ServerMessageDeliverer implements MessageDeliverer { @Override public final void deliverResponse(final Exchange exchange, final Response response) { if (response == null) { throw new NullPointerException("Response must not be null"); } else if (exchange == null) { throw new NullPointerException("Exchange must not be null"); } else if (exchange.getRequest() == null) { throw new IllegalArgumentException("Exchange does not contain request"); } else { boolean processed = preDeliverResponse(exchange, response); if (!processed) { exchange.getRequest().setResponse(response); } } } ServerMessageDeliverer(final Resource root); @Override final void deliverRequest(final Exchange exchange); @Override final void deliverResponse(final Exchange exchange, final Response response);  }
@Test public void testDeliverResponseYieldsToSubclass() { ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) { @Override protected boolean preDeliverResponse(Exchange exchange, Response response) { return true; } }; deliverer.deliverResponse(outboundRequest, incomingResponse); assertNull(outboundRequest.getRequest().getResponse()); }
@Test public void testDeliverResponseProcessesResponseAfterPreDeliverResponse() { ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) { @Override protected boolean preDeliverResponse(Exchange exchange, Response response) { response.getOptions().addOption(new Option(200)); return false; } }; deliverer.deliverResponse(outboundRequest, incomingResponse); assertNotNull(outboundRequest.getRequest().getResponse()); assertTrue(outboundRequest.getRequest().getResponse().getOptions().hasOption(200)); }