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

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

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

Request.setToken介绍

暂无

代码示例

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

public CC12(String serverURI) {
  super(CC12.class.getSimpleName());
  // create the request
  Request request = new Request(Code.GET, Type.CON);
  // request.requiresToken(false); // TODO
  request.setToken(new byte[0]);
  // set the parameters and execute the request
  executeRequest(request, serverURI, RESOURCE_URI);
}

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

public CC11(String serverURI) {
  super(CC11.class.getSimpleName());
  // create the request
  Request request = new Request(Code.GET, Type.CON);
  request.setToken(new byte[]{(byte) 0xBE, (byte) 0xEF});
  executeRequest(request, serverURI, RESOURCE_URI);
}

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

private static boolean ping(String address) {
  try {
    Request request = new Request(null);
    request.setType(Type.CON);
    request.setToken(new byte[0]);
    request.setURI(address);
    System.out.println("++++++ Sending Ping ++++++");
    request.send().waitForResponse(5000);
    return request.isRejected();
  } catch (Exception e) {
    e.printStackTrace();
    return false;
  }
}

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

/**
 * Performs a CoAP ping and gives up after the given number of milliseconds.
 * 
 * @param timeout the time to wait for a pong in ms
 * @return success of the ping
 */
public boolean ping(long timeout) {
  try {
    Request request = new Request(null, Type.CON);
    request.setToken(new byte[0]);
    request.setURI(uri);
    send(request).waitForResponse(timeout);
    return request.isRejected();
  } catch (InterruptedException e) {
    // waiting was interrupted, which is fine
  }
  return false;
}

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

/**
 * Performs a CoAP ping and gives up after the given number of milliseconds.
 * 
 * @param timeout the time to wait for a pong in ms
 * @return success of the ping
 */
public boolean ping(long timeout) {
  try {
    Request request = new Request(null, Type.CON);
    request.setToken(new byte[0]);
    request.setURI(uri);
    send(request).waitForResponse(timeout);
    return request.isRejected();
  } catch (InterruptedException e) {
    // waiting was interrupted, which is fine
  }
  return false;
}

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

} while (exchangesByToken.get(idByToken) != null);
request.setToken(token);

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

Request deregister = Request.newGet();
deregister.setURI(uri);
deregister.setToken(request.getToken());
deregister.setObserveCancel();
request = deregister;

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

private void registerWithToken(final Exchange exchange) {
  Request request = exchange.getCurrentRequest();
  KeyToken idByToken;
  if (request.getToken() == null) {
    idByToken = tokenProvider.getUnusedToken(request);
    request.setToken(idByToken.getToken());
  } else {
    idByToken = KeyToken.fromOutboundMessage(request);
    // ongoing requests may reuse token
    if (!(exchange.getFailedTransmissionCount() > 0 || request.getOptions().hasBlock1()
        || request.getOptions().hasBlock2() || request.getOptions().hasObserve())
        && tokenProvider.isTokenInUse(idByToken)) {
      LOGGER.log(Level.WARNING, "Manual token overrides existing open request: {0}", idByToken);
    }
  }
  exchangesByToken.put(idByToken, exchange);
}

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

Request reregister = Request.newGet();
reregister.setURI(uri);
reregister.setToken(request.getToken());
reregister.setObserve();
request = reregister;

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

System.out.println("---------------\nGET /test w/o Token\n---------------");
req12.setToken(new byte[0]);
response = client.advanced(req12);
System.out.println(response.advanced().getType() + "-" + response.getCode());

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

refresh.setDestinationPort(request.getDestinationPort());
refresh.setToken(request.getToken());

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

refresh.setDestinationPort(request.getDestinationPort());
refresh.setToken(request.getToken());

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

/**
 * Verifies that the getByteArray() method does not set the Message's <em>bytes</em> property.
 */
@Test
public void testGetByteArrayDoesNotAlterMessage() {
  // GIVEN a CoAP request
  Request req = Request.newGet();
  req.setToken(new byte[]{0x00});
  req.getOptions().setObserve(0);
  req.setDestination(InetAddress.getLoopbackAddress());
  // WHEN serializing the request to a byte array
  serializer.getByteArray(req);
  // THEN the serialized byte array is not written to the request's bytes property
  assertNull(req.getBytes());
}

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

/**
 * Send request with option "cancel observe" (GET with Observe=1).
 */
private void sendCancelObserve() {
  Request request = this.request;
  Request cancel = Request.newGet();
  cancel.setDestination(request.getDestination());
  cancel.setDestinationPort(request.getDestinationPort());
  // use same Token
  cancel.setToken(request.getToken());
  // copy options, but set Observe to cancel
  cancel.setOptions(request.getOptions());
  cancel.setObserveCancel();
  // dispatch final response to the same message observers
  for (MessageObserver mo : request.getMessageObservers()) {
    cancel.addMessageObserver(mo);
  }
  endpoint.sendRequest(cancel);
}

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

/**
   * Verifies that the serializeRequest() method sets the Message's <em>bytes</em> property.
   */
  @Test
  public void testSerializeRequestStoresBytesInMessage() {

    // GIVEN a CoAP request
    Request req = Request.newGet();
    req.setToken(new byte[]{0x00});
    req.getOptions().setObserve(0);
    req.setDestination(InetAddress.getLoopbackAddress());

    // WHEN serializing the request to a RawData object
    RawData raw = serializer.serializeRequest(req);

    // THEN the serialized byte array is stored in the request's bytes property
    assertNotNull(req.getBytes());
    assertThat(raw.getBytes(), is(req.getBytes()));
  }
}

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

/**
 * Send request with option "cancel observe" (GET with Observe=1).
 */
private void sendCancelObserve() {
  Request request = this.request;
  Request cancel = Request.newGet();
  cancel.setDestination(request.getDestination());
  cancel.setDestinationPort(request.getDestinationPort());
  // use same Token
  cancel.setToken(request.getToken());
  // copy options, but set Observe to cancel
  cancel.setOptions(request.getOptions());
  cancel.setObserveCancel();
  
  // dispatch final response to the same message observers
  for (MessageObserver mo: request.getMessageObservers()) {
    cancel.addMessageObserver(mo);
  }
  
  endpoint.sendRequest(cancel);
}

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

private void sendNextBlock(final Exchange exchange, final Response response, final BlockOption block1, final BlockwiseStatus requestStatus) {
  // Send next block
  int currentSize = 1 << (4 + requestStatus.getCurrentSzx());
  // Define new size of the block depending of preferred size block
  int newSize, newSzx;
  if (block1.getSize() < currentSize) {
    newSize = block1.getSize();
    newSzx = block1.getSzx();
  } else {
    newSize = currentSize;
    newSzx = requestStatus.getCurrentSzx();
  }
  int nextNum = requestStatus.getCurrentNum() + currentSize / newSize;
  LOGGER.log(Level.FINER, "Sending next Block1 num={0}", nextNum);
  requestStatus.setCurrentNum(nextNum);
  requestStatus.setCurrentSzx(newSzx);
  Request nextBlock = getNextRequestBlock(exchange.getRequest(), requestStatus);
  // indicate overall body size to peer
  nextBlock.getOptions().setSize1(exchange.getRequest().getPayloadSize());
  // we use the same token to ease traceability
  nextBlock.setToken(response.getToken());
  exchange.setCurrentRequest(nextBlock);
  lower().sendRequest(exchange, nextBlock);
  // do not deliver response
}

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

if (!response.getOptions().hasObserve()) block.setToken(response.getToken());

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

Request nextBlock = getNextRequestBlock(exchange.getRequest(), status);
nextBlock.setToken(response.getToken());
  if (!response.getOptions().hasObserve()) block.setToken(response.getToken());

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

@Test public void testRequestParsing() {
    Request request = new Request(Code.POST);
    request.setType(Type.NON);
    request.setMID(expectedMid);
    request.setToken(new byte[] { 11, 82, -91, 77, 3 });
    request.getOptions().addIfMatch(new byte[] { 34, -17 }).addIfMatch(new byte[] { 88, 12, -2, -99, 5 })
        .setContentFormat(40).setAccept(40);

    RawData rawData = serializer.serializeRequest(request);
//        MessageHeader header = parser.parseHeader(rawData);
//        assertTrue(CoAP.isRequest(header.getCode()));
//
//        Request result = parser.parseRequest(rawData);
    Request result = (Request) parser.parseMessage(rawData);
    assertEquals(request.getMID(), result.getMID());
    assertArrayEquals(request.getToken(), result.getToken());
    assertEquals(request.getOptions().asSortedList(), result.getOptions().asSortedList());
  }

相关文章