Source:
private void createSimpleProxy(final boolean proxyRequestBlockwise, final boolean proxyResponseBlockwiseEnabled) { final Coap2CoapTranslator coapTranslator = new Coap2CoapTranslator(); final CoapUriTranslator uriTranslator = new CoapUriTranslator(); CoapEndpoint.Builder builder = new CoapEndpoint.Builder(); builder.setCoapStackFactory(CoapEndpoint.STANDARD_COAP_STACK_FACTORY); builder.setInetSocketAddress(TestTools.LOCALHOST_EPHEMERAL); if (proxyResponseBlockwiseEnabled) { builder.setNetworkConfig(blockwiseConfig); } CoapEndpoint proxyServerEndpoint = builder.build(); CoapServer proxy = new CoapServer(); cleanup.add(proxy); proxy.addEndpoint(proxyServerEndpoint); proxy.setMessageDeliverer(new MessageDeliverer() { @Override public void deliverRequest(Exchange exchange) { Response outgoingResponse = null; try { Request incomingRequest = exchange.getRequest(); URI finalDestinationUri = uriTranslator.getDestinationURI(incomingRequest, uriTranslator.getExposedInterface(incomingRequest)); Request outgoingRequest = coapTranslator.getRequest(finalDestinationUri, incomingRequest); CoapClient proxyClient = new CoapClient(); CoapEndpoint.Builder builder = new CoapEndpoint.Builder(); builder.setCoapStackFactory(CoapEndpoint.STANDARD_COAP_STACK_FACTORY); if (proxyRequestBlockwise) { builder.setNetworkConfig(blockwiseConfig); } CoapEndpoint proxyClientEndpoint = builder.build(); proxyClient.setEndpoint(proxyClientEndpoint); cleanup.add(proxyClientEndpoint); CoapResponse incomingResponse = proxyClient.advanced(outgoingRequest); outgoingResponse = coapTranslator.getResponse(incomingResponse.advanced()); } catch (org.eclipse.californium.proxy2.TranslationException | ConnectorException | IOException e) { System.err.println("Processing on proxy failed."); e.printStackTrace(); fail(); } exchange.sendResponse(outgoingResponse); } @Override public void deliverResponse(Exchange exchange, Response response) { System.out.println("Proxy: Deliver response called."); } }); proxy.start(); proxyUri = TestTools.getUri(proxyServerEndpoint, "/"); }

Target:
private void createSimpleProxy(final boolean proxyRequestBlockwise, final boolean proxyResponseBlockwiseEnabled) { final Coap2CoapTranslator coapTranslator = new Coap2CoapTranslator(); CoapEndpoint.Builder builder = new CoapEndpoint.Builder(); builder.setCoapStackFactory(CoapEndpoint.STANDARD_COAP_STACK_FACTORY); builder.setInetSocketAddress(TestTools.LOCALHOST_EPHEMERAL); if (proxyResponseBlockwiseEnabled) { builder.setNetworkConfig(blockwiseConfig); } CoapEndpoint proxyServerEndpoint = builder.build(); CoapServer proxy = new CoapServer(); cleanup.add(proxy); proxy.addEndpoint(proxyServerEndpoint); proxy.setMessageDeliverer(new MessageDeliverer() { @Override public void deliverRequest(Exchange exchange) { Response outgoingResponse = null; try { Request incomingRequest = exchange.getRequest(); URI finalDestinationUri = coapTranslator.getDestinationURI(incomingRequest, coapTranslator.getExposedInterface(incomingRequest)); Request outgoingRequest = coapTranslator.getRequest(finalDestinationUri, incomingRequest); CoapClient proxyClient = new CoapClient(); CoapEndpoint.Builder builder = new CoapEndpoint.Builder(); builder.setCoapStackFactory(CoapEndpoint.STANDARD_COAP_STACK_FACTORY); if (proxyRequestBlockwise) { builder.setNetworkConfig(blockwiseConfig); } CoapEndpoint proxyClientEndpoint = builder.build(); proxyClient.setEndpoint(proxyClientEndpoint); cleanup.add(proxyClientEndpoint); CoapResponse incomingResponse = proxyClient.advanced(outgoingRequest); outgoingResponse = coapTranslator.getResponse(incomingResponse.advanced()); } catch (org.eclipse.californium.proxy2.TranslationException | ConnectorException | IOException e) { System.err.println("Processing on proxy failed."); e.printStackTrace(); fail(); } exchange.sendResponse(outgoingResponse); } @Override public void deliverResponse(Exchange exchange, Response response) { System.out.println("Proxy: Deliver response called."); } }); proxy.start(); proxyUri = TestTools.getUri(proxyServerEndpoint, "/"); }