org.eclipse.californium.core.coap.Request.getPayload()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.4k)|赞(0)|评价(0)|浏览(325)

本文整理了Java中org.eclipse.californium.core.coap.Request.getPayload方法的一些代码示例,展示了Request.getPayload的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getPayload方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:getPayload

Request.getPayload介绍

暂无

代码示例

代码示例来源:origin: org.eclipse.californium/californium-core

/**
 * Gets the request payload as byte array.
 *
 * @return the request payload
 */
public byte[] getRequestPayload() {
  return exchange.getRequest().getPayload();
}

代码示例来源:origin: eclipse/californium

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

代码示例来源:origin: eclipse/californium

/**
 * Gets the request payload as byte array.
 *
 * @return the request payload
 */
public byte[] getRequestPayload() {
  return exchange.getRequest().getPayload();
}

代码示例来源:origin: org.eclipse.californium/californium-core

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

代码示例来源:origin: sitewhere/sitewhere

/**
 * Handle device registration request.
 * 
 * @param tenant
 * @param deviceToken
 * @param exchange
 */
protected void handleDeviceRegistration(ITenant tenant, String deviceToken, Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(CoapJsonDecoder.META_EVENT_TYPE, Type.RegisterDevice.name());
metadata.put(CoapJsonDecoder.META_DEVICE_TOKEN, deviceToken);
getEventReceiver().onEventPayloadReceived(exchange.getRequest().getPayload(), metadata);
createAndSendResponse(ResponseCode.CONTENT, "Device registration submitted successfully.", exchange);
}

代码示例来源:origin: sitewhere/sitewhere

/**
 * Handle add device measurement.
 * 
 * @param tenant
 * @param deviceToken
 * @param paths
 * @param exchange
 */
protected void handleAddDeviceMeasurement(ITenant tenant, String deviceToken, List<String> paths,
  Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(CoapJsonDecoder.META_EVENT_TYPE, Type.DeviceMeasurement.name());
metadata.put(CoapJsonDecoder.META_DEVICE_TOKEN, deviceToken);
getEventReceiver().onEventPayloadReceived(exchange.getRequest().getPayload(), metadata);
createAndSendResponse(ResponseCode.CONTENT, "Device measurement submitted successfully.", exchange);
}

代码示例来源:origin: sitewhere/sitewhere

/**
 * Handle add device alert.
 * 
 * @param tenant
 * @param deviceToken
 * @param paths
 * @param exchange
 */
protected void handleAddDeviceAlert(ITenant tenant, String deviceToken, List<String> paths, Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(CoapJsonDecoder.META_EVENT_TYPE, Type.DeviceAlert.name());
metadata.put(CoapJsonDecoder.META_DEVICE_TOKEN, deviceToken);
getEventReceiver().onEventPayloadReceived(exchange.getRequest().getPayload(), metadata);
createAndSendResponse(ResponseCode.CONTENT, "Device alert submitted successfully.", exchange);
}

代码示例来源:origin: sitewhere/sitewhere

/**
 * Handle add device location.
 * 
 * @param tenant
 * @param deviceToken
 * @param paths
 * @param exchange
 */
protected void handleAddDeviceLocation(ITenant tenant, String deviceToken, List<String> paths, Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(CoapJsonDecoder.META_EVENT_TYPE, Type.DeviceLocation.name());
metadata.put(CoapJsonDecoder.META_DEVICE_TOKEN, deviceToken);
getEventReceiver().onEventPayloadReceived(exchange.getRequest().getPayload(), metadata);
createAndSendResponse(ResponseCode.CONTENT, "Device location submitted successfully.", exchange);
}

代码示例来源:origin: sitewhere/sitewhere

/**
 * Handle add device acknowledgement.
 * 
 * @param tenant
 * @param deviceToken
 * @param paths
 * @param exchange
 */
protected void handleAddDeviceAck(ITenant tenant, String deviceToken, List<String> paths, Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(CoapJsonDecoder.META_EVENT_TYPE, Type.Acknowledge.name());
metadata.put(CoapJsonDecoder.META_DEVICE_TOKEN, deviceToken);
getEventReceiver().onEventPayloadReceived(exchange.getRequest().getPayload(), metadata);
createAndSendResponse(ResponseCode.CONTENT, "Device acknowledgement submitted successfully.", exchange);
}

代码示例来源:origin: eclipse/californium

LOGGER.severe("ISO-8859-1 encoding not supported: " + e.getMessage());
byte[] payload = request.getPayload();

代码示例来源:origin: org.eclipse.californium/californium-proxy

LOGGER.severe("ISO-8859-1 encoding not supported: " + e.getMessage());
byte[] payload = request.getPayload();

代码示例来源:origin: eclipse/leshan

if (request.getPayload() != null && request.getPayload().length > 0) {
  objectLinks = Link.parse(request.getPayload());

代码示例来源:origin: org.eclipse.leshan/leshan-server-cf

if (request.getPayload() != null && request.getPayload().length > 0) {
  objectLinks = LinkObject.parse(request.getPayload());

代码示例来源:origin: com.sitewhere/sitewhere-core

/**
 * Handle operations related to device locations.
 * 
 * @param tenant
 * @param device
 * @param paths
 * @param exchange
 */
protected void handleDeviceLocations(ITenant tenant, IDevice device, List<String> paths, Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(META_EVENT_TYPE, Type.DeviceLocation.name());
metadata.put(META_HARDWARE_ID, device.getHardwareId());
switch (exchange.getRequest().getCode()) {
case POST: {
  try {
  EventProcessingLogic.processRawPayloadWithExceptionHandling(getEventReceiver(),
    exchange.getRequest().getPayload(), metadata);
  createAndSendResponse(ResponseCode.CONTENT, "Device location created successfully.", exchange);
  } catch (EventDecodeException e) {
  LOGGER.error("Unable to decode CoAP location payload.", e);
  createAndSendResponse(ResponseCode.BAD_REQUEST, "Unable to parse payload.", exchange);
  }
  break;
}
default: {
  createAndSendResponse(ResponseCode.BAD_REQUEST, "Device location operation not available.", exchange);
}
}
}

代码示例来源:origin: eclipse/leshan

public CoapMessage(Request request, boolean incoming) {
  this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request
      .getPayload());
  this.code = request.getCode().toString();
}

代码示例来源:origin: com.sitewhere/sitewhere-core

/**
 * Handle operations related to device measurements.
 * 
 * @param tenant
 * @param device
 * @param paths
 * @param exchange
 */
protected void handleDeviceMeasurements(ITenant tenant, IDevice device, List<String> paths, Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(META_EVENT_TYPE, Type.DeviceMeasurements.name());
metadata.put(META_HARDWARE_ID, device.getHardwareId());
switch (exchange.getRequest().getCode()) {
case POST: {
  try {
  EventProcessingLogic.processRawPayloadWithExceptionHandling(getEventReceiver(),
    exchange.getRequest().getPayload(), metadata);
  createAndSendResponse(ResponseCode.CONTENT, "Device measurements created successfully.", exchange);
  } catch (EventDecodeException e) {
  LOGGER.error("Unable to decode CoAP measurements payload.", e);
  createAndSendResponse(ResponseCode.BAD_REQUEST, "Unable to parse payload.", exchange);
  }
  break;
}
default: {
  createAndSendResponse(ResponseCode.BAD_REQUEST, "Device measurements operation not available.", exchange);
}
}
}

代码示例来源:origin: com.sitewhere/sitewhere-core

/**
 * Handle operations related to device alerts.
 * 
 * @param tenant
 * @param device
 * @param paths
 * @param exchange
 */
protected void handleDeviceAlerts(ITenant tenant, IDevice device, List<String> paths, Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(META_EVENT_TYPE, Type.DeviceAlert.name());
metadata.put(META_HARDWARE_ID, device.getHardwareId());
switch (exchange.getRequest().getCode()) {
case POST: {
  try {
  EventProcessingLogic.processRawPayloadWithExceptionHandling(getEventReceiver(),
    exchange.getRequest().getPayload(), metadata);
  createAndSendResponse(ResponseCode.CONTENT, "Device alert created successfully.", exchange);
  } catch (EventDecodeException e) {
  LOGGER.error("Unable to decode CoAP alert payload.", e);
  createAndSendResponse(ResponseCode.BAD_REQUEST, "Unable to parse payload.", exchange);
  }
  break;
}
default: {
  createAndSendResponse(ResponseCode.BAD_REQUEST, "Device alert operation not available.", exchange);
}
}
}

代码示例来源:origin: com.sitewhere/sitewhere-core

/**
 * Handle operations related to device command acknowledgements.
 * 
 * @param tenant
 * @param device
 * @param paths
 * @param exchange
 */
protected void handleDeviceAcks(ITenant tenant, IDevice device, List<String> paths, Exchange exchange) {
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put(META_EVENT_TYPE, Type.Acknowledge.name());
metadata.put(META_HARDWARE_ID, device.getHardwareId());
switch (exchange.getRequest().getCode()) {
case POST: {
  try {
  EventProcessingLogic.processRawPayloadWithExceptionHandling(getEventReceiver(),
    exchange.getRequest().getPayload(), metadata);
  createAndSendResponse(ResponseCode.CONTENT, "Device acknowledgement created successfully.", exchange);
  } catch (EventDecodeException e) {
  LOGGER.error("Unable to decode CoAP acknowledgement payload.", e);
  createAndSendResponse(ResponseCode.BAD_REQUEST, "Unable to parse payload.", exchange);
  }
  break;
}
default: {
  createAndSendResponse(ResponseCode.BAD_REQUEST, "Device location operation not available.", exchange);
}
}
}

代码示例来源:origin: eclipse/californium

/**
 * Create a key for the cache starting from a request and the
 * content-type of the corresponding response.
 * 
 * @param request
 * @return
 * @throws URISyntaxException
 */
private static CacheKey fromContentTypeOption(Request request) throws URISyntaxException {
  if (request == null) {
    throw new IllegalArgumentException("request == null");
  }
  Response response = request.getResponse();
  if (response == null) {
    return fromAcceptOptions(request).get(0);
  }
  String proxyUri = request.getOptions().getProxyUri();
  int mediaType = response.getOptions().getContentFormat();
  if (mediaType < 0) {
    // content-format option not set, use default
    mediaType = MediaTypeRegistry.TEXT_PLAIN;
  }
  byte[] payload = request.getPayload();
  // create the new cacheKey
  CacheKey cacheKey = new CacheKey(proxyUri, mediaType, payload);
  cacheKey.setResponse(response);
  return cacheKey;
}

代码示例来源:origin: org.eclipse.californium/californium-proxy

/**
 * Create a key for the cache starting from a request and the
 * content-type of the corresponding response.
 * 
 * @param request
 * @return
 * @throws URISyntaxException
 */
private static CacheKey fromContentTypeOption(Request request) throws URISyntaxException {
  if (request == null) {
    throw new IllegalArgumentException("request == null");
  }
  Response response = request.getResponse();
  if (response == null) {
    return fromAcceptOptions(request).get(0);
  }
  String proxyUri = request.getOptions().getProxyUri();
  int mediaType = response.getOptions().getContentFormat();
  if (mediaType < 0) {
    // content-format option not set, use default
    mediaType = MediaTypeRegistry.TEXT_PLAIN;
  }
  byte[] payload = request.getPayload();
  // create the new cacheKey
  CacheKey cacheKey = new CacheKey(proxyUri, mediaType, payload);
  cacheKey.setResponse(response);
  return cacheKey;
}

相关文章