Java Code Examples for org.eclipse.californium.core.coap.Response#getOptions()
The following examples show how to use
org.eclipse.californium.core.coap.Response#getOptions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractVertxBasedCoapAdapter.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * Adds a command to a CoAP response. * <p> * This default implementation adds the command name, content format and response URI to the * CoAP response options and puts the command's input data (if any) to the response body. * * @param response The CoAP response. * @param commandContext The context containing the command to add. * @param currentSpan The Open Tracing span used for tracking the CoAP request. */ protected void addCommandToResponse( final Response response, final CommandContext commandContext, final Span currentSpan) { final Command command = commandContext.getCommand(); final OptionSet options = response.getOptions(); options.addLocationQuery(Constants.HEADER_COMMAND + "=" + command.getName()); if (command.isOneWay()) { options.setLocationPath(CommandConstants.COMMAND_ENDPOINT); } else { options.setLocationPath(CommandConstants.COMMAND_RESPONSE_ENDPOINT); } currentSpan.setTag(Constants.HEADER_COMMAND, command.getName()); log.debug("adding command [name: {}, request-id: {}] to response for device [tenant-id: {}, device-id: {}]", command.getName(), command.getRequestId(), command.getTenant(), command.getDeviceId()); commandContext.getCurrentSpan().log("forwarding command to device in CoAP response"); if (command.isTargetedAtGateway()) { options.addLocationPath(command.getTenant()); options.addLocationPath(command.getOriginalDeviceId()); currentSpan.setTag(Constants.HEADER_COMMAND_TARGET_DEVICE, command.getOriginalDeviceId()); } if (!command.isOneWay()) { options.addLocationPath(command.getRequestId()); currentSpan.setTag(Constants.HEADER_COMMAND_REQUEST_ID, command.getRequestId()); } final int formatCode = MediaTypeRegistry.parse(command.getContentType()); if (formatCode != MediaTypeRegistry.UNDEFINED) { options.setContentFormat(formatCode); } else { currentSpan.log("ignoring unknown content type [" + command.getContentType() + "] of command"); } Optional.ofNullable(command.getPayload()).ifPresent(b -> response.setPayload(b.getBytes())); }
Example 2
Source File: CoapMessage.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
public CoapMessage(Response request, boolean incoming) { this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request .getPayload()); this.code = request.getCode().toString(); }
Example 3
Source File: CoapMessage.java From SI with BSD 2-Clause "Simplified" License | 4 votes |
public CoapMessage(Response request, boolean incoming) { this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request .getPayload()); this.code = request.getCode().toString(); }