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

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

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

Request.getToken介绍

暂无

代码示例

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

  1. public ObserveRelation getObserveRelation(byte[] token) {
  2. for (ObserveRelation relation:relations) {
  3. if (Arrays.equals(relation.getExchange().getRequest().getToken(), token)) {
  4. return relation;
  5. }
  6. }
  7. return null;
  8. }
  9. }

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

  1. public ObserveRelation getObserveRelation(byte[] token) {
  2. for (ObserveRelation relation:relations) {
  3. if (Arrays.equals(relation.getExchange().getRequest().getToken(), token)) {
  4. return relation;
  5. }
  6. }
  7. return null;
  8. }
  9. }

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

  1. @Override
  2. public void handleGET(CoapExchange exchange) {
  3. // Check: Type, Code
  4. StringBuilder payload = new StringBuilder();
  5. Request request = exchange.advanced().getRequest();
  6. payload.append(String.format("Type: %d (%s)\nCode: %d (%s)\nMID: %d",
  7. request.getType().value,
  8. request.getType(),
  9. request.getCode().value,
  10. request.getCode(),
  11. request.getMID()));
  12. if (request.getToken().length > 0) {
  13. payload.append("\nToken: ");
  14. StringBuilder tok = new StringBuilder(request.getToken()==null?"null":"");
  15. if (request.getToken()!=null) for(byte b:request.getToken()) tok.append(String.format("%02x", b&0xff));
  16. payload.append(tok);
  17. }
  18. if (payload.length() > 64) {
  19. payload.delete(62, payload.length());
  20. payload.append('»');
  21. }
  22. // complete the request
  23. exchange.setMaxAge(30);
  24. exchange.respond(CONTENT, payload.toString(), TEXT_PLAIN);
  25. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  4. success &= checkToken(request.getToken(), response.getToken());
  5. success &= hasContentType(response);
  6. success &= hasNonEmptyPalyoad(response);
  7. success &= hasObserve(response);
  8. return success;
  9. }
  10. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.ACK, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value,
  5. response.getCode().value, "code");
  6. success &= checkToken(request.getToken(), response.getToken());
  7. success &= hasContentType(response);
  8. success &= hasNonEmptyPalyoad(response);
  9. return success;
  10. }
  11. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.CON, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  5. // Token value = the same value as in the request sent by the client
  6. // in step 2
  7. success &= checkToken(request.getToken(), response.getToken());
  8. success &= hasContentType(response);
  9. success &= hasNonEmptyPalyoad(response);
  10. return success;
  11. }
  12. }

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

  1. private void registerWithToken(final Exchange exchange) {
  2. Request request = exchange.getCurrentRequest();
  3. KeyToken idByToken;
  4. if (request.getToken() == null) {
  5. idByToken = tokenProvider.getUnusedToken(request);
  6. request.setToken(idByToken.getToken());
  7. } else {
  8. idByToken = KeyToken.fromOutboundMessage(request);
  9. // ongoing requests may reuse token
  10. if (!(exchange.getFailedTransmissionCount() > 0 || request.getOptions().hasBlock1()
  11. || request.getOptions().hasBlock2() || request.getOptions().hasObserve())
  12. && tokenProvider.isTokenInUse(idByToken)) {
  13. LOGGER.log(Level.WARNING, "Manual token overrides existing open request: {0}", idByToken);
  14. }
  15. }
  16. exchangesByToken.put(idByToken, exchange);
  17. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.CON, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  5. success &= checkToken(request.getToken(), response.getToken());
  6. success &= hasContentType(response);
  7. success &= hasNonEmptyPalyoad(response);
  8. success &= hasObserve(response);
  9. return success;
  10. }
  11. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.CON, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  5. success &= checkToken(request.getToken(), response.getToken());
  6. success &= hasContentType(response);
  7. success &= hasNonEmptyPalyoad(response);
  8. success &= hasObserve(response);
  9. return success;
  10. }
  11. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.CON, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  5. success &= checkToken(request.getToken(), response.getToken());
  6. success &= hasContentType(response);
  7. success &= hasNonEmptyPalyoad(response);
  8. success &= hasObserve(response);
  9. return success;
  10. }
  11. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.CON, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  5. success &= checkToken(request.getToken(), response.getToken());
  6. success &= hasContentType(response);
  7. success &= hasNonEmptyPalyoad(response);
  8. success &= hasObserve(response);
  9. return success;
  10. }
  11. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.CON, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  5. success &= checkToken(request.getToken(), response.getToken());
  6. success &= hasContentType(response);
  7. success &= hasNonEmptyPalyoad(response);
  8. success &= hasObserve(response);
  9. return success;
  10. }
  11. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.CON, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  5. success &= checkToken(request.getToken(), response.getToken());
  6. success &= hasContentType(response);
  7. success &= hasNonEmptyPalyoad(response);
  8. success &= hasObserve(response);
  9. return success;
  10. }
  11. }

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

  1. protected boolean checkResponse(Request request, Response response) {
  2. boolean success = true;
  3. success &= checkType(Type.CON, response.getType());
  4. success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
  5. success &= checkToken(request.getToken(), response.getToken());
  6. success &= hasContentType(response);
  7. success &= hasNonEmptyPalyoad(response);
  8. success &= hasObserve(response);
  9. return success;
  10. }
  11. }

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

  1. /**
  2. * Serializes a request to the wire format.
  3. * <p>
  4. * The main difference between this and the <em>serializeRequest</em> method is that this method
  5. * does <em>not</em> cache the byte array in the request's <em>bytes</em> property.
  6. *
  7. * @param request The request to serialize.
  8. * @return The encoded request.
  9. */
  10. public final byte[] getByteArray(final Request request) {
  11. DatagramWriter writer = new DatagramWriter();
  12. byte[] body = serializeOptionsAndPayload(request);
  13. MessageHeader header = new MessageHeader(CoAP.VERSION, request.getType(), request.getToken(),
  14. request.getRawCode(), request.getMID(), body.length);
  15. serializeHeader(writer, header);
  16. writer.writeBytes(body);
  17. return writer.toByteArray();
  18. }

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

  1. /**
  2. * Send request with option "cancel observe" (GET with Observe=1).
  3. */
  4. private void sendCancelObserve() {
  5. Request request = this.request;
  6. Request cancel = Request.newGet();
  7. cancel.setDestination(request.getDestination());
  8. cancel.setDestinationPort(request.getDestinationPort());
  9. // use same Token
  10. cancel.setToken(request.getToken());
  11. // copy options, but set Observe to cancel
  12. cancel.setOptions(request.getOptions());
  13. cancel.setObserveCancel();
  14. // dispatch final response to the same message observers
  15. for (MessageObserver mo : request.getMessageObservers()) {
  16. cancel.addMessageObserver(mo);
  17. }
  18. endpoint.sendRequest(cancel);
  19. }

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

  1. /**
  2. * Send request with option "cancel observe" (GET with Observe=1).
  3. */
  4. private void sendCancelObserve() {
  5. Request request = this.request;
  6. Request cancel = Request.newGet();
  7. cancel.setDestination(request.getDestination());
  8. cancel.setDestinationPort(request.getDestinationPort());
  9. // use same Token
  10. cancel.setToken(request.getToken());
  11. // copy options, but set Observe to cancel
  12. cancel.setOptions(request.getOptions());
  13. cancel.setObserveCancel();
  14. // dispatch final response to the same message observers
  15. for (MessageObserver mo: request.getMessageObservers()) {
  16. cancel.addMessageObserver(mo);
  17. }
  18. endpoint.sendRequest(cancel);
  19. }

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

  1. private static Response responseFor(final Request request) {
  2. Response response = new Response(ResponseCode.CONTENT);
  3. response.setMID(request.getMID());
  4. response.setToken(request.getToken());
  5. response.setBytes(new byte[]{});
  6. response.setSource(request.getDestination());
  7. response.setSourcePort(request.getDestinationPort());
  8. response.setDestination(request.getSource());
  9. response.setDestinationPort(request.getSourcePort());
  10. return response;
  11. }
  12. }

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

  1. @Test public void testRequestParsing() {
  2. Request request = new Request(Code.POST);
  3. request.setType(Type.NON);
  4. request.setMID(expectedMid);
  5. request.setToken(new byte[] { 11, 82, -91, 77, 3 });
  6. request.getOptions().addIfMatch(new byte[] { 34, -17 }).addIfMatch(new byte[] { 88, 12, -2, -99, 5 })
  7. .setContentFormat(40).setAccept(40);
  8. RawData rawData = serializer.serializeRequest(request);
  9. // MessageHeader header = parser.parseHeader(rawData);
  10. // assertTrue(CoAP.isRequest(header.getCode()));
  11. //
  12. // Request result = parser.parseRequest(rawData);
  13. Request result = (Request) parser.parseMessage(rawData);
  14. assertEquals(request.getMID(), result.getMID());
  15. assertArrayEquals(request.getToken(), result.getToken());
  16. assertEquals(request.getOptions().asSortedList(), result.getOptions().asSortedList());
  17. }

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

  1. private Response responseFor(final Request request) {
  2. Response response = new Response(ResponseCode.CONTENT);
  3. response.setMID(request.getMID());
  4. response.setToken(request.getToken());
  5. response.setBytes(new byte[]{});
  6. response.setSource(request.getDestination());
  7. response.setSourcePort(request.getDestinationPort());
  8. response.setDestination(request.getSource());
  9. response.setDestinationPort(request.getSourcePort());
  10. return response;
  11. }
  12. }

相关文章