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

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

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

Request.getSourceContext介绍

暂无

代码示例

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

@Override
  public Future<Device> getAuthenticatedDevice(final CoapExchange exchange) {
    final Principal peer = exchange.advanced().getRequest().getSourceContext().getPeerIdentity();
    if (PreSharedKeyIdentity.class.isInstance(peer)) {
      LOG.debug("authenticate psk identity {}", peer.getName());
      final PreSharedKeyDeviceIdentity handshakeIdentity = getHandshakeIdentity(
          ((PreSharedKeyIdentity) peer).getIdentity());
      if (handshakeIdentity != null) {
        final Device authorizedDevice = devices.getIfPresent(handshakeIdentity);
        if (authorizedDevice != null) {
          return Future.succeededFuture(authorizedDevice);
        }
      }
      return Future.failedFuture("missing device for " + peer + "!");
    }
    return Future.failedFuture(new IllegalArgumentException("Principal not supported by this handler!"));
  }
}

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

@Override
public void receiveRequest(Request request) {
  CoapMessageListener listener = listeners.get(toStringAddress(request.getSourceContext().getPeerAddress()));
  if (listener != null) {
    listener.trace(new CoapMessage(request, true));
  }
}

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

/**
 * Get authenticated device.
 * 
 * @param device origin device of message. If {@code null}, the message is sent from the authenticated device.
 * @param exchange coap exchange with peer's principal.
 * @param handler handler for determined extended device
 */
public void getAuthenticatedExtendedDevice(final Device device,
    final CoapExchange exchange, final Handler<ExtendedDevice> handler) {
  final Principal peer = exchange.advanced().getRequest().getSourceContext().getPeerIdentity();
  final CoapAuthenticationHandler authenticationHandler = getAuthenticationHandler(peer);
  if (authenticationHandler == null) {
    log.debug("device authentication handler missing for {}!", peer);
    exchange.respond(ResponseCode.INTERNAL_SERVER_ERROR);
  } else {
    authenticationHandler.getAuthenticatedDevice(exchange)
        .compose((authorizedDevice) -> {
          final Device originDevice = device != null ? device : authorizedDevice;
          final ExtendedDevice extendedDevice = new ExtendedDevice(authorizedDevice, originDevice);
          log.debug("used {}", extendedDevice);
          handler.handle(extendedDevice);
          return Future.succeededFuture();
        }).otherwise((error) -> {
          CoapErrorResponse.respond(exchange, error);
          return null;
        });
  }
}

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

public static ServerIdentity extractServerIdentity(CoapExchange exchange, BootstrapHandler bootstrapHandler) {
    Identity identity = EndpointContextUtil.extractIdentity(exchange.advanced().getRequest().getSourceContext());

    if (bootstrapHandler.isBootstrapServer(identity)) {
      return ServerIdentity.createLwm2mBootstrapServerIdentity(identity);
    }

    return ServerIdentity.createLwm2mServerIdentity(identity);
  }
}

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

private void handleRegister(CoapExchange exchange, Request request) {
  Identity sender = extractIdentity(request.getSourceContext());

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

private void handleUpdate(CoapExchange exchange, Request request, String registrationId) {
  Identity sender = extractIdentity(request.getSourceContext());

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

/**
 * Get extended device.
 * 
 * @param exchange coap exchange with URI and/or peer's principal.
 * @param handler handler for determined extended device
 */
public void getExtendedDevice(final CoapExchange exchange, final Handler<ExtendedDevice> handler) {
  try {
    final List<String> pathList = exchange.getRequestOptions().getUriPath();
    final String[] path = pathList.toArray(new String[pathList.size()]);
    final ResourceIdentifier identifier = ResourceIdentifier.fromPath(path);
    final Device device = new Device(identifier.getTenantId(), identifier.getResourceId());
    final Principal peer = exchange.advanced().getRequest().getSourceContext().getPeerIdentity();
    if (peer == null) {
      final ExtendedDevice extendedDevice = new ExtendedDevice(device, device);
      log.debug("use {}", extendedDevice);
      handler.handle(extendedDevice);
    } else {
      getAuthenticatedExtendedDevice(device, exchange, handler);
    }
  } catch (NullPointerException cause) {
    CoapErrorResponse.respond(exchange, "missing tenant and device!", ResponseCode.BAD_REQUEST);
  } catch (Throwable cause) {
    CoapErrorResponse.respond(exchange, cause, ResponseCode.INTERNAL_SERVER_ERROR);
  }
}

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

Identity clientIdentity = EndpointContextUtil.extractIdentity(request.getSourceContext());

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

private void handleDeregister(CoapExchange exchange, String registrationId) {
  // Get identity
  Identity sender = extractIdentity(exchange.advanced().getRequest().getSourceContext());
  // Create request
  DeregisterRequest deregisterRequest = new DeregisterRequest(registrationId);
  // Handle request
  final SendableResponse<DeregisterResponse> sendableResponse = registrationHandler.deregister(sender,
      deregisterRequest);
  DeregisterResponse deregisterResponse = sendableResponse.getResponse();
  // Create CoAP Response from LwM2m request
  if (deregisterResponse.getCode().isError()) {
    exchange.respond(toCoapResponseCode(deregisterResponse.getCode()), deregisterResponse.getErrorMessage());
  } else {
    exchange.respond(toCoapResponseCode(deregisterResponse.getCode()));
  }
  sendableResponse.sent();
}

相关文章