private static void earlyBlock2Negotiation(final Exchange exchange, final Request request) { // Call this method when a request has completely arrived (might have // been sent in one piece without blockwise). BlockOption block2 = request.getOptions().getBlock2(); if (block2 != null) { BlockwiseStatus status2 = new BlockwiseStatus(request.getOptions().getContentFormat(), block2.getNum(), block2.getSzx()); LOGGER.log(Level.FINE, "Request with early block negotiation {0}. Create and set new Block2 status: {1}", new Object[]{block2, status2}); exchange.setResponseBlockStatus(status2); } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= hasNonEmptyPalyoad(response); return success; } }
private BlockwiseStatus findResponseBlockStatus(final Exchange exchange, final Response response) { BlockwiseStatus status = exchange.getResponseBlockStatus(); if (status == null) { status = new BlockwiseStatus(response.getOptions().getContentFormat()); status.setCurrentSzx( computeSZX(preferred_block_size) ); status.setFirst(response); exchange.setResponseBlockStatus(status); LOGGER.finer("There is no blockwise status yet. Create and set new Block2 status: "+status); } else { LOGGER.finer("Current Block2 status: "+status); } // sets a timeout to complete exchange prepareBlockCleanup(exchange); return status; }
private BlockwiseStatus findRequestBlockStatus(final Exchange exchange, final Request request) { BlockwiseStatus status = exchange.getRequestBlockStatus(); if (status == null) { status = new BlockwiseStatus(request.getOptions().getContentFormat()); status.setFirst(request); status.setCurrentSzx( computeSZX(preferred_block_size) ); exchange.setRequestBlockStatus(status); LOGGER.finer("There is no assembler status yet. Create and set new Block1 status: "+status); } else { LOGGER.finer("Current Block1 status: "+status); } // sets a timeout to complete exchange prepareBlockCleanup(exchange); return status; }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= checkDiscoveryAttributes(EXPECTED_RT, response.getPayloadString()); return success; } }
private void earlyBlock2Negotiation(final Exchange exchange, final Request request) { // Call this method when a request has completely arrived (might have // been sent in one piece without blockwise). if (request.getOptions().hasBlock2()) { BlockOption block2 = request.getOptions().getBlock2(); BlockwiseStatus status2 = new BlockwiseStatus(request.getOptions().getContentFormat(), block2.getNum(), block2.getSzx()); LOGGER.fine("Request with early block negotiation "+block2+". Create and set new Block2 status: "+status2); exchange.setResponseBlockStatus(status2); } }
@Override public void handlePUT(CoapExchange exchange) { if (exchange.getRequestOptions().hasContentFormat()) { storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat()); exchange.respond(CHANGED); } else { exchange.respond(BAD_REQUEST, "Content-Format not set"); } }
private ValueResponse buildContentResponse(final LwM2mPath path, final Response coapResponse) { final ResponseCode code = ResponseCode.CONTENT; LwM2mNode content; try { content = LwM2mNodeDecoder.decode(coapResponse.getPayload(), ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path); } catch (final InvalidValueException e) { final String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString()); throw new ResourceAccessException(code, path.toString(), msg, e); } return new ValueResponse(code, content); }
@Override public void handlePUT(CoapExchange exchange) { if (!exchange.getRequestOptions().hasContentFormat()) { exchange.respond(BAD_REQUEST, "Content-Format not set"); return; } // store payload storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat()); // complete the request exchange.respond(CHANGED); }
@Override public void handlePUT(CoapExchange exchange) { if (!exchange.getRequestOptions().hasContentFormat()) { exchange.respond(BAD_REQUEST, "Content-Format not set"); return; } // store payload storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat()); // complete the request exchange.respond(CHANGED); }
@Override public void onResponse(Response coapResponse) { if (coapResponse.getCode() == CoAP.ResponseCode.CHANGED || coapResponse.getCode() == CoAP.ResponseCode.CONTENT) { try { LwM2mNode content = LwM2mNodeDecoder.decode(coapResponse.getPayload(), ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path); ValueResponse response = new ValueResponse(ResponseCode.CHANGED, content); for (ObservationListener listener : listeners) { listener.newValue(this, response.getContent()); } } catch (InvalidValueException e) { String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString()); LOG.debug(msg); } } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= checkDiscoveryAttributes(EXPECTED_HREF, response.getPayloadString()); return success; } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= checkDiscoveryAttributes(EXPECTED_IF, response.getPayloadString()); return success; } }
@Override public void handlePOST(CoapExchange exchange) { if (exchange.getRequestOptions().hasContentFormat()) { exchange.setLocationPath( storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat()) ); exchange.respond(CREATED); } else { exchange.respond(BAD_REQUEST, "Content-Format not set"); } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= checkDiscoveryAttributes(EXPECTED_HREF, response.getPayloadString()); return success; } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= checkDiscoveryAttributes(EXPECTED_RT, response.getPayloadString()); return success; } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content format"); success &= hasNonEmptyPalyoad(response); success &= checkDiscoveryAttributes(EXPECTED_RT, response.getPayloadString()); return success; } }
protected boolean checkResponse(Request request, Response response) { boolean success = true; success &= checkType(Type.ACK, response.getType()); success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code"); success &= checkOption(MediaTypeRegistry.APPLICATION_LINK_FORMAT, response.getOptions().getContentFormat(), "Content-Format"); success &= hasNonEmptyPalyoad(response); success &= checkDiscoveryAttributes(EXPECTED_SZ, response.getPayloadString()); return success; } }
public Set<WebLink> discover(String query) { Request discover = newGet(); discover.setURI(uri); // for scheme and authority, but then remove path and query discover.getOptions().clearUriPath().clearUriQuery().setUriPath("/.well-known/core"); if (query!=null) { discover.getOptions().setUriQuery(query); } CoapResponse links = synchronous(discover); // if no response, return null (e.g., timeout) if (links == null) { return null; } // check if Link Format if (links.getOptions().getContentFormat()!=MediaTypeRegistry.APPLICATION_LINK_FORMAT) return Collections.emptySet(); // parse and return return LinkFormat.parse(links.getResponseText()); }
@Override public void handlePUT(CoapExchange exchange) { if (data!=null && exchange.getRequestOptions().hasIfNoneMatch()) { exchange.respond(PRECONDITION_FAILED); // automatically reset data = null; } else { if (exchange.getRequestOptions().hasContentFormat()) { storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat()); exchange.respond(CREATED); } else { exchange.respond(BAD_REQUEST, "Content-Format not set"); } } }