/** * Returns the Content-Format Identifier of the Content-Format option (see * <a href="http://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats">IANA Registry</a>). * @return the ID as int or -1 if undefined */ public int getContentFormat() { return hasContentFormat() ? content_format : MediaTypeRegistry.UNDEFINED; }
/** * Returns the Content-Format Identifier of the Content-Format option (see * <a href="http://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats">IANA Registry</a>). * @return the ID as int or -1 if undefined */ public int getContentFormat() { return hasContentFormat() ? content_format : MediaTypeRegistry.UNDEFINED; }
@Override public void handlePOST(CoapExchange exchange) { if (exchange.getRequestOptions().hasContentFormat()) { exchange.respond(CHANGED, exchange.getRequestText().toUpperCase(), TEXT_PLAIN); } else { exchange.respond(BAD_REQUEST, "Content-Format not set"); } } }
/** * Checks for Content-Type option. * * @param response * the response * @return true, if successful */ protected boolean hasContentType(Response response) { boolean success = response.getOptions().hasContentFormat() || response.getPayloadSize()==0 || !CoAP.ResponseCode.isSuccess(response.getCode()); if (!success) { System.out.println("FAIL: Response without Content-Type"); } else { System.out.printf("PASS: Content-Type (%s)\n", MediaTypeRegistry.toString(response.getOptions() .getContentFormat())); } return success; }
if (options.hasContentFormat()) { String mt = MediaTypeRegistry.toString(options.getContentFormat()); camelExchange.getIn().setHeader(org.apache.camel.Exchange.CONTENT_TYPE, mt);
private LwM2mNode decodeCoapResponse(LwM2mPath path, Response coapResponse, LwM2mRequest<?> request, String endpoint) { // Get content format ContentFormat contentFormat = null; if (coapResponse.getOptions().hasContentFormat()) { contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()); } // Decode payload try { return decoder.decode(coapResponse.getPayload(), contentFormat, path, model); } catch (CodecException e) { if (LOG.isDebugEnabled()) { byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload(); LOG.debug( String.format("Unable to decode response payload of request [%s] from client [%s] [payload:%s]", request, endpoint, Hex.encodeHexString(payload))); } throw new InvalidResponseException(e, "Unable to decode response payload of request [%s] from client [%s]", request, endpoint); } }
@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"); } }
@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); }
if (! coapMessage.getOptions().hasContentFormat()) { contentType = ContentType.APPLICATION_OCTET_STREAM; } else {
if (! coapMessage.getOptions().hasContentFormat()) { contentType = ContentType.APPLICATION_OCTET_STREAM; } else {
@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"); } }
if (uri_path_list != null) for (String str:uri_path_list) options.add(new Option(OptionNumberRegistry.URI_PATH, str)); if (hasContentFormat()) options.add(new Option(OptionNumberRegistry.CONTENT_FORMAT, getContentFormat())); if (hasMaxAge())
if (uri_path_list != null) for (String str:uri_path_list) options.add(new Option(OptionNumberRegistry.URI_PATH, str)); if (hasContentFormat()) options.add(new Option(OptionNumberRegistry.CONTENT_FORMAT, getContentFormat())); if (hasMaxAge())
if (coapResponse.getOptions().hasContentFormat()) { contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat());
@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"); } } }
@Override public void handlePUT(CoapExchange exchange) { if (exchange.getRequestOptions().isIfMatch(etag)) { if (exchange.getRequestOptions().hasContentFormat()) { storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat()); exchange.setETag(etag.clone()); exchange.respond(CHANGED); } else { exchange.respond(BAD_REQUEST, "Content-Format not set"); } } else if (exchange.getRequestOptions().hasIfNoneMatch() && data==null) { storeData(exchange.getRequestPayload(), exchange.getRequestOptions().getContentFormat()); exchange.respond(CREATED); } else { exchange.respond(PRECONDITION_FAILED); // automatically change now storeData(null, UNDEFINED); } }
if (!exchange.getRequestOptions().hasContentFormat()) { exchange.respond(ResponseCode.BAD_REQUEST, "Content Format is mandatory"); return;
LwM2mPath path = new LwM2mPath(URI); if (!coapExchange.getRequestOptions().hasContentFormat()) { coapExchange.respond(ResponseCode.BAD_REQUEST, "Content Format is mandatory"); return;