@Override public void deliverResponse(Exchange exchange, Response response) { if (response == null) { throw new RuntimeException("Response must not be null"); } else if (exchange == null) { throw new RuntimeException("Exchange must not be null"); } else if (exchange.getRequest() == null) { throw new IllegalArgumentException("Exchange does not contain request"); } else { exchange.getRequest().setResponse(response); } }
@Override public void deliverResponse(Exchange exchange, Response response) { if (exchange == null) throw new NullPointerException(); if (exchange.getRequest() == null) throw new NullPointerException(); if (response == null) throw new NullPointerException(); exchange.getRequest().setResponse(response); } }
/** * Gets the source port of the request. * * @return the source port */ public int getSourcePort() { return exchange.getRequest().getSourcePort(); }
/** * Gets the request code: <tt>GET</tt>, <tt>POST</tt>, <tt>PUT</tt> or * <tt>DELETE</tt>. * * @return the request code */ public Code getRequestCode() { return exchange.getRequest().getCode(); }
/** * Gets the request's options. * * @return the request options */ public OptionSet getRequestOptions() { return exchange.getRequest().getOptions(); }
/** * Gets the source address of the request. * * @return the source address */ public InetAddress getSourceAddress() { return exchange.getRequest().getSource(); }
/** * Gets the request payload as string. * * @return the request payload string */ public String getRequestText() { return exchange.getRequest().getPayloadString(); }
/** * Gets the request payload as byte array. * * @return the request payload */ public byte[] getRequestPayload() { return exchange.getRequest().getPayload(); }
@Override public void run() { if (!exchange.isComplete()) { if (exchange.getRequest() == null) { LOGGER.log(Level.INFO, "Block1 transfer timed out: {0}", exchange.getCurrentRequest()); } else { LOGGER.log(Level.INFO, "Block2 transfer timed out: {0}", exchange.getRequest()); } exchange.setComplete(); } } }
public ObserveRelation getObserveRelation(byte[] token) { for (ObserveRelation relation:relations) { if (Arrays.equals(relation.getExchange().getRequest().getToken(), token)) { return relation; } } return null; } }
@Override public boolean accept(ObserveRelation relation) { String relationURI = relation.getExchange().getRequest().getOptions().getUriPathString(); boolean result = relationURI.equals(notifyURI); if (LOG.isTraceEnabled()) { LOG.trace("observe " + relationURI + " / " + notifyURI + ": " + result); } return result; }
@Override public void onCancel() { if (!exchange.isComplete()) { LOGGER.log(Level.FINE, "completing canceled request [MID={0}, token={1}]", new Object[]{ exchange.getRequest().getMID(), exchange.getRequest().getTokenString() }); exchange.setComplete(); } } }
@Override public void deliverRequest(Exchange exchange) { receivedRequests.add(exchange.getRequest()); latch.countDown(); } };
@Override public void handleDELETE(CoapExchange exchange) { LOG.debug("DELETE received : {}", exchange.advanced().getRequest()); List<String> uri = exchange.getRequestOptions().getUriPath(); if (uri != null && uri.size() == 2 && RESOURCE_NAME.equals(uri.get(0))) { handleDeregister(exchange, uri.get(1)); } else { LOG.debug("Invalid deregistration"); exchange.respond(ResponseCode.NOT_FOUND); } }
@Override public void receiveRequest(final Exchange exchange, final Request request) { // if there is no BlockwiseLayer we still have to set it if (exchange.getRequest() == null) { exchange.setRequest(request); } if (hasDeliverer()) { deliverer.deliverRequest(exchange); } else { LOGGER.severe("Top of CoAP stack has no deliverer to deliver request"); } }
@Override public void handleRequest(Exchange exchange) { exchange.sendAccept(); Response response = forwardRequest(exchange.getRequest()); exchange.sendResponse(response); }
@Override public void receiveResponse(final Exchange exchange, final Response response) { if (response.getOptions().hasObserve() && exchange.getRequest().isCanceled()) { // The request was canceled and we no longer want notifications LOGGER.finer("Ignore notification for canceled TCP Exchange"); } else { // No observe option in response => always deliver upper().receiveResponse(exchange, response); } } }
@Override public void onTimeout() { ObserveRelation relation = exchange.getRelation(); LOGGER.log( Level.INFO, "Notification for token [{0}] timed out. Canceling all relations with source [{1}]", new Object[]{ relation.getExchange().getRequest().getTokenString(), relation.getSource() }); relation.cancelAll(); }
public static ServerIdentity extractServerIdentity(CoapExchange exchange, BootstrapHandler bootstrapHandler) { Identity identity = EndpointContextUtil.extractIdentity(exchange.advanced().getRequest().getSourceContext()); if (bootstrapHandler.isBootstrapServer(identity)) { return ServerIdentity.createLwm2mBootstrapServerIdentity(identity); } return ServerIdentity.createLwm2mServerIdentity(identity); } }
@Override public void deliverRequest(Exchange exchange) { OptionSet options = exchange.getRequest().getOptions(); List<String> paths = options.getUriPath(); handleRequest(getEventReceiver().getTenantEngine().getTenant(), paths, exchange); }