public void sendRequest(Request request) { Exchange exchange = new Exchange(request, Origin.LOCAL); sendRequest(exchange, request); // layer method }
public void sendRequest(final Request request) { Exchange exchange = new Exchange(request, Origin.LOCAL); sendRequest(exchange, request); // layer method }
private Exchange newOutboundRequest() { Request request = Request.newGet(); request.setURI("coap://127.0.0.1:12000/test"); Exchange exchange = new Exchange(request, Origin.LOCAL); return exchange; } }
Exchange exchange = new Exchange(request, Exchange.Origin.REMOTE); exchange.setObserver(exchangeObserver); return exchange; Exchange exchange = new Exchange(request, Exchange.Origin.REMOTE); LOGGER.log(Level.FINER, "New ongoing request, storing {0} for {1}", new Object[] { idByUri, request }); exchange.setObserver(exchangeObserver);
private static Exchange sendObserveRequest(final UdpMatcher matcher) { Request request = Request.newGet(); request.setDestination(dest.getAddress()); request.setDestinationPort(dest.getPort()); request.setObserve(); Exchange exchange = new Exchange(request, Origin.LOCAL); matcher.sendRequest(exchange, request); return exchange; }
/** * Sets up the fixture. */ @Before public void setUp() { rootResource = mock(Resource.class); when(rootResource.getChild(anyString())).thenReturn(rootResource); when(rootResource.getExecutor()).thenReturn(null); incomingRequest = new Exchange(new Request(Code.POST), Exchange.Origin.REMOTE); incomingRequest.setRequest(incomingRequest.getCurrentRequest()); incomingResponse = new Response(ResponseCode.CONTENT); outboundRequest = new Exchange(new Request(Code.GET), Origin.LOCAL); outboundRequest.setRequest(outboundRequest.getCurrentRequest()); }
private static Exchange sendRequest(final UdpMatcher matcher, final CorrelationContext ctx) { Request request = Request.newGet(); request.setDestination(dest.getAddress()); request.setDestinationPort(dest.getPort()); Exchange exchange = new Exchange(request, Origin.LOCAL); exchange.setRequest(request); matcher.sendRequest(exchange, request); exchange.setCorrelationContext(ctx); return exchange; }
private Exchange sendRequest(final TcpMatcher matcher, final CorrelationContext ctx) { Request request = Request.newGet(); request.setDestination(dest.getAddress()); request.setDestinationPort(dest.getPort()); Exchange exchange = new Exchange(request, Origin.LOCAL); exchange.setRequest(request); matcher.sendRequest(exchange, request); exchange.setCorrelationContext(ctx); return exchange; }
@Test public void sendResponseExpectSent() { Request request = new Request(CoAP.Code.GET); Exchange exchange = new Exchange(request, Exchange.Origin.REMOTE); Response response = new Response(CoAP.ResponseCode.CONTENT); stack.sendResponse(exchange, response); verify(outbox).sendResponse(exchange, response); } }
@Test public void sendResponseExpectSent() { Request request = new Request(CoAP.Code.GET); Exchange exchange = new Exchange(request, Exchange.Origin.REMOTE); Response response = new Response(CoAP.ResponseCode.CONTENT); stack.sendResponse(exchange, response); verify(outbox).sendResponse(exchange, response); } }
/** * Verifies that an inbound blockwise request is rejected with a 4.13 error response. */ @Test public void testReceiveRequestRejectsExcessiveRequestBody() { NetworkConfig config = NetworkConfig.createStandardWithoutFile() .setInt(Keys.MAX_MESSAGE_SIZE, 128) .setInt(Keys.MAX_RESOURCE_BODY_SIZE, 200); Layer outbox = mock(Layer.class); ArgumentCaptor<Response> errorResponse = ArgumentCaptor.forClass(Response.class); BlockwiseLayer blockwiseLayer = new BlockwiseLayer(config); blockwiseLayer.setLowerLayer(outbox); Request request = newBlockwiseRequest(256, 64); Exchange exchange = new Exchange(request, Origin.REMOTE); blockwiseLayer.receiveRequest(exchange, request); verify(outbox).sendResponse(Mockito.any(Exchange.class), errorResponse.capture()); assertThat(errorResponse.getValue().getCode(), is(ResponseCode.REQUEST_ENTITY_TOO_LARGE)); }
/** * Verifies that an inbound blockwise request is forwarded to application layer * if overall transparent blockwise handling is disabled. */ @Test public void testReceiveRequestDelegatesToApplicationLayer() { NetworkConfig config = NetworkConfig.createStandardWithoutFile() .setInt(Keys.MAX_MESSAGE_SIZE, 128) .setInt(Keys.MAX_RESOURCE_BODY_SIZE, 0); Layer appLayer = mock(Layer.class); BlockwiseLayer blockwiseLayer = new BlockwiseLayer(config); blockwiseLayer.setUpperLayer(appLayer); Request request = newBlockwiseRequest(256, 64); Exchange exchange = new Exchange(request, Origin.REMOTE); blockwiseLayer.receiveRequest(exchange, request); verify(appLayer).receiveRequest(exchange, request); }
/** * Verifies that canceling a message that has no MID set does not throw an exception. * */ @Test public void testExchangeObserverToleratesUnsentMessages() { // GIVEN a request that has no MID and has not been sent yet UdpMatcher matcher = newMatcher(false); Request request = Request.newGet(); request.setDestination(dest.getAddress()); request.setDestinationPort(dest.getPort()); Exchange exchange = new Exchange(request, Origin.LOCAL); exchange.setRequest(request); assertFalse(request.hasMID()); matcher.observe(exchange); // WHEN the request is canceled and thus the message exchange completes exchange.setComplete(); // THEN the matcher's exchange observer does not throw an exception }
@Test public void testDiscoveryMultiFiltering() { Request request = Request.newGet(); request.setURI("coap://localhost/.well-known/core?rt=light-lux&rt=temprature-cel"); Exchange exchange = new Exchange(request, Origin.REMOTE); exchange.setRequest(request); exchange.setEndpoint(new DummyEndpoint()); DiscoveryResource discovery = new DiscoveryResource(root); discovery.handleRequest(exchange); System.out.println(exchange.getResponse().getPayloadString()); Assert.assertEquals(ResponseCode.BAD_OPTION, exchange.getResponse().getCode()); }
/** * Verifies that a request for a resource with a body exceeding the max buffer size is * cancelled when the first response block is received. */ @Test public void testReceiveResponseCancelsRequestForExcessiveResponseBody() { NetworkConfig config = NetworkConfig.createStandardWithoutFile() .setInt(Keys.MAX_MESSAGE_SIZE, 128) .setInt(Keys.MAX_RESOURCE_BODY_SIZE, 200); MessageObserver requestObserver = mock(MessageObserver.class); BlockwiseLayer blockwiseLayer = new BlockwiseLayer(config); Request req = Request.newGet(); req.setURI("coap://127.0.0.1/bigResource"); req.addMessageObserver(requestObserver); Response response = Response.createResponse(req, ResponseCode.CONTENT); response.getOptions().setSize2(256).setBlock2(BlockOption.size2Szx(64), true, 0); Exchange exchange = new Exchange(null, Origin.LOCAL); exchange.setRequest(req); blockwiseLayer.receiveResponse(exchange, response); verify(requestObserver).onCancel(); }