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

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

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

Request.setDestinationContext介绍

暂无

代码示例

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

private void buildRequestSettings() {
    coapRequest.setDestinationContext(new AddressEndpointContext(serverAddress));
  }
}

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

@Override
public void visit(BootstrapDeleteRequest request) {
  coapRequest = Request.newDelete();
  coapRequest.setConfirmable(true);
  EndpointContext context = EndpointContextUtil.extractContext(destination);
  coapRequest.setDestinationContext(context);
  setTarget(coapRequest, request.getPath());
}

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

public static Observation deserialize(byte[] data) {
  JsonObject v = (JsonObject) Json.parse(new String(data));
  EndpointContext endpointContext = EndpointContextSerDes.deserialize(v.get("peer").asObject());
  byte[] req = Hex.decodeHex(v.getString("request", null).toCharArray());
  RawData rawData = RawData.outbound(req, endpointContext, null, false);
  Request request = (Request) parser.parseMessage(rawData);
  request.setDestinationContext(endpointContext);
  JsonValue ctxValue = v.get("context");
  if (ctxValue != null) {
    Map<String, String> context = new HashMap<>();
    JsonObject ctxObject = (JsonObject) ctxValue;
    for (String name : ctxObject.names()) {
      context.put(name, ctxObject.getString(name, null));
    }
    request.setUserContext(context);
  }
  return new Observation(request, endpointContext);
}

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

public static Observation deserialize(byte[] data) {
  JsonObject v = (JsonObject) Json.parse(new String(data));
  EndpointContext endpointContext = EndpointContextSerDes.deserialize(v.get("peer").asObject());
  byte[] req = Hex.decodeHex(v.getString("request", null).toCharArray());
  RawData rawData = RawData.outbound(req, endpointContext, null, false);
  Request request = (Request) parser.parseMessage(rawData);
  request.setDestinationContext(endpointContext);
  JsonValue ctxValue = v.get("context");
  if (ctxValue != null) {
    Map<String, String> context = new HashMap<>();
    JsonObject ctxObject = (JsonObject) ctxValue;
    for (String name : ctxObject.names()) {
      context.put(name, ctxObject.getString(name, null));
    }
    request.setUserContext(context);
  }
  return new Observation(request, endpointContext);
}

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

@Override
public void visit(BootstrapFinishRequest request) {
  coapRequest = Request.newPost();
  coapRequest.setConfirmable(true);
  EndpointContext context = EndpointContextUtil.extractContext(destination);
  coapRequest.setDestinationContext(context);
  // root path
  if (rootPath != null) {
    for (String rootPathPart : rootPath.split("/")) {
      if (!StringUtils.isEmpty(rootPathPart)) {
        coapRequest.getOptions().addUriPath(rootPathPart);
      }
    }
  }
  coapRequest.getOptions().addUriPath("bs");
}

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

@Override
public void sendCoapRequest(final Registration destination, final Request coapRequest, long timeout,
    CoapResponseCallback responseCallback, ErrorCallback errorCallback) {
  // Define destination
  EndpointContext context = EndpointContextUtil.extractContext(destination.getIdentity());
  coapRequest.setDestinationContext(context);
  // Add CoAP request callback
  MessageObserver obs = new CoapAsyncRequestObserver(coapRequest, responseCallback, errorCallback, timeout);
  coapRequest.addMessageObserver(obs);
  // Store pending request to cancel it on de-registration
  addPendingRequest(destination.getId(), coapRequest);
  // Send CoAP request asynchronously
  Endpoint endpoint = getEndpointForClient(destination);
  endpoint.sendRequest(coapRequest);
}

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

private final void setTarget(Request coapRequest, LwM2mPath path) {
  EndpointContext context = EndpointContextUtil.extractContext(destination);
  coapRequest.setDestinationContext(context);
  // root path
  if (rootPath != null) {
    for (String rootPathPart : rootPath.split("/")) {
      if (!StringUtils.isEmpty(rootPathPart)) {
        coapRequest.getOptions().addUriPath(rootPathPart);
      }
    }
  }
  // objectId
  if (path.getObjectId() != null) {
    coapRequest.getOptions().addUriPath(Integer.toString(path.getObjectId()));
  }
  // objectInstanceId
  if (path.getObjectInstanceId() == null) {
    if (path.getResourceId() != null) {
      coapRequest.getOptions().addUriPath("0"); // default instanceId
    }
  } else {
    coapRequest.getOptions().addUriPath(Integer.toString(path.getObjectInstanceId()));
  }
  // resourceId
  if (path.getResourceId() != null) {
    coapRequest.getOptions().addUriPath(Integer.toString(path.getResourceId()));
  }
}

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

@Override
public Response sendCoapRequest(final Registration destination, final Request coapRequest, long timeout)
    throws InterruptedException {
  // Define destination
  EndpointContext context = EndpointContextUtil.extractContext(destination.getIdentity());
  coapRequest.setDestinationContext(context);
  // Send CoAP request synchronously
  CoapSyncRequestObserver syncMessageObserver = new CoapSyncRequestObserver(coapRequest, timeout);
  coapRequest.addMessageObserver(syncMessageObserver);
  // Store pending request to cancel it on de-registration
  addPendingRequest(destination.getId(), coapRequest);
  // Send CoAP request asynchronously
  Endpoint endpoint = getEndpointForClient(destination);
  endpoint.sendRequest(coapRequest);
  // Wait for response, then return it
  return syncMessageObserver.waitForCoapResponse();
}

相关文章

微信公众号

最新文章

更多