@Override public void onReject() { exception.set(new RequestRejectedException("Request %s rejected", coapRequest.getURI())); latch.countDown(); }
public OperationResponse waitForResponse() { try { final boolean latchTimeout = latch.await(timeout, TimeUnit.MILLISECONDS); if (!latchTimeout || coapTimeout.get()) { coapRequest.cancel(); if (exception.get() != null) { throw exception.get(); } else { throw new RuntimeException("Request Timed Out: " + coapRequest.getURI() + " (timeout)"); } } } catch (final InterruptedException e) { // no idea why some other thread should have interrupted this thread // but anyway, go ahead as if the timeout had been reached LOG.info("Caught an unexpected InterruptedException during execution of CoAP request " + e); } finally { coapRequest.removeMessageObserver(this); } if (exception.get() != null) { throw exception.get(); } return ref.get(); } }
public OperationResponse waitForResponse() { try { final boolean latchTimeout = latch.await(timeout, TimeUnit.MILLISECONDS); if (!latchTimeout || coapTimeout.get()) { coapRequest.cancel(); if (exception.get() != null) { throw exception.get(); } else { throw new RuntimeException("Request Timed Out: " + coapRequest.getURI() + " (timeout)"); } } } catch (final InterruptedException e) { // no idea why some other thread should have interrupted this thread // but anyway, go ahead as if the timeout had been reached LOG.info("Caught an unexpected InterruptedException during execution of CoAP request " + e); } finally { coapRequest.removeMessageObserver(this); } if (exception.get() != null) { throw exception.get(); } return ref.get(); } }
@Override public void onCancel() { cancelCleaningTask(); if (responseTimedOut.get()) errorCallback.onError(new org.eclipse.leshan.core.request.exception.TimeoutException("Request %s timed out", coapRequest.getURI())); else errorCallback.onError(new RequestCanceledException("Request %s cancelled", coapRequest.getURI())); }
public T waitForResponse() { try { final boolean latchTimeout = latch.await(timeout, TimeUnit.MILLISECONDS); if (!latchTimeout || coapTimeout.get()) { clientRegistry.deregisterClient(client.getRegistrationId()); coapRequest.cancel(); if (exception.get() != null) { throw exception.get(); } else { throw new RequestTimeoutException(coapRequest.getURI(), timeout); } } } catch (final InterruptedException e) { // no idea why some other thread should have interrupted this thread // but anyway, go ahead as if the timeout had been reached LOG.debug("Caught an unexpected InterruptedException during execution of CoAP request", e); } finally { coapRequest.removeMessageObserver(this); } if (exception.get() != null) { throw exception.get(); } return ref.get(); } }
@Override public void onReject() { cancelCleaningTask(); errorCallback.onError(new RequestRejectedException("Request %s rejected", coapRequest.getURI())); }
@Override public void onSendError(Throwable error) { cancelCleaningTask(); errorCallback.onError(new SendFailedException(error, "Unable to send request %s", coapRequest.getURI())); }
@Override public void onTimeout() { cancelCleaningTask(); errorCallback.onError(new org.eclipse.leshan.core.request.exception.TimeoutException("Request %s timed out", coapRequest.getURI())); }
/** * Throws a generic {@link ResourceAccessException} indicating that the client returned an unexpected response code. * * @param request * @param coapRequest * @param coapResponse */ private void handleUnexpectedResponseCode(final String clientEndpoint, final Request coapRequest, final Response coapResponse) { final String msg = String.format("Client [%s] returned unexpected response code [%s]", clientEndpoint, coapResponse.getCode()); throw new ResourceAccessException(fromCoapCode(coapResponse.getCode().value), coapRequest.getURI(), msg); } }
/** * Verifies that a URI composed from options contains the literal destination IP address if * no Uri-Host option value is set. */ @Test public void testGetURIContainsLiteralIpAddressDestination() { Request req = Request.newGet().setURI("coap://192.168.0.1:12000"); URI uri = URI.create(req.getURI()); assertThat(uri.getHost(), is("192.168.0.1")); }
/** * Verifies that a URI without "path" and "query part" is well formed. */ @Test public void testGetURIWithoutPathAndQuery() { Request req = Request.newGet().setURI("coap://192.168.0.1:12000"); String uri = req.getURI(); assertThat(uri, is("coap://192.168.0.1:12000/")); }
/** * Verifies that the getURI method escapes non-ASCII characters contained in path and query. * @throws UnknownHostException */ @Test public void testGetURIEscapesNonAsciiCharacters() throws UnknownHostException { Request req = Request.newGet().setURI("coap://192.168.0.1"); req.getOptions().addUriPath("non-ascii-path-äöü").addUriQuery("non-ascii-query=äöü"); String derivedUri = req.getURI(); System.out.println(derivedUri); URI uri = URI.create(derivedUri); assertThat(uri.getRawPath(), is("/non-ascii-path-%C3%A4%C3%B6%C3%BC")); assertThat(uri.getRawQuery(), is("non-ascii-query=%C3%A4%C3%B6%C3%BC")); }
/** * Verifies that a URI with "path" and without "query part" is well formed. */ @Test public void testGetURIWithPathAndWithoutQuery() { Request req = Request.newGet().setURI("coap://192.168.0.1:12000/30/40"); String uri = req.getURI(); assertThat(uri, is("coap://192.168.0.1:12000/30/40")); }
/** * Verifies that a URI without "path" and with "query part" is well formed. */ @Test public void testGetURIWithoutPathAndWithQuery() { Request req = Request.newGet().setURI("coap://192.168.0.1:12000?parameter"); String uri = req.getURI(); assertThat(uri, is("coap://192.168.0.1:12000/?parameter")); }
Exchange.KeyUri idByUri = new Exchange.KeyUri(request.getURI(), response.getDestination().getAddress(), response.getDestinationPort());
return exchange; } else { Exchange.KeyUri idByUri = new Exchange.KeyUri(request.getURI(), request.getSource().getAddress(), request.getSourcePort()); LOGGER.log(Level.FINE, "Looking up ongoing exchange for {0}", idByUri);
KeyUri idByUri = new KeyUri(request.getURI(), response.getDestination().getAddress(), response.getDestinationPort());
Exchange.KeyUri uriKey = new Exchange.KeyUri(request.getURI(), request.getSource().getAddress(), request.getSourcePort()); LOGGER.log(Level.FINE, "Remote ongoing completed, cleaning up ", uriKey);
KeyUri idByUri = new KeyUri(request.getURI(), response.getDestination().getAddress(), response.getDestinationPort());