private void receiveResponse(final Response response, final RawData raw) { /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) { interceptor.receiveResponse(response); } // MessageInterceptor might have canceled if (!response.isCanceled()) { Exchange exchange = matcher.receiveResponse(response, raw.getCorrelationContext()); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); response.setRTT(System.currentTimeMillis() - exchange.getTimestamp()); coapstack.receiveResponse(exchange, response); } else if (response.getType() != Type.ACK) { LOGGER.log(Level.FINE, "Rejecting unmatchable response from {0}", raw.getInetSocketAddress()); reject(response); } } }
private void receiveEmptyMessage(final EmptyMessage message, final RawData raw) { /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) { interceptor.receiveEmptyMessage(message); } // MessageInterceptor might have canceled if (!message.isCanceled()) { // CoAP Ping if (message.getType() == Type.CON || message.getType() == Type.NON) { LOGGER.log(Level.FINER, "responding to ping from {0}", raw.getInetSocketAddress()); reject(message); } else { Exchange exchange = matcher.receiveEmptyMessage(message); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); coapstack.receiveEmptyMessage(exchange, message); } } } } }
private void receiveRequest(final Request request, final RawData raw) { // set request attributes from raw data request.setScheme(raw.isSecure() ? CoAP.COAP_SECURE_URI_SCHEME : CoAP.COAP_URI_SCHEME); request.setSenderIdentity(raw.getSenderIdentity()); /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) { interceptor.receiveRequest(request); } // MessageInterceptor might have canceled if (!request.isCanceled()) { Exchange exchange = matcher.receiveRequest(request); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); coapstack.receiveRequest(exchange, request); } } }
Exchange exchange = matcher.receiveRequest(request); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); coapstack.receiveRequest(exchange, request); Exchange exchange = matcher.receiveResponse(response); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); response.setRTT(System.currentTimeMillis() - exchange.getTimestamp()); coapstack.receiveResponse(exchange, response); Exchange exchange = matcher.receiveEmptyMessage(message); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); coapstack.receiveEmptyMessage(exchange, message);
@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()); }