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

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

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

Request.getMID介绍

暂无

代码示例

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

@Override
public void sendRequest(final Exchange exchange, final Request request) {
  observe(exchange);
  exchangeStore.registerOutboundRequest(exchange);
  if (LOGGER.isLoggable(Level.FINER)) {
    LOGGER.log(
        Level.FINER,
        "Tracking open request [MID: {0}, Token: {1}]",
        new Object[] { request.getMID(), request.getTokenString() });
  }
}

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

/**
 * Formats a {@link Request} into a readable String representation. 
 * 
 * @param r the Request
 * @return the pretty print
 */
public static String prettyPrint(Request r) {
  StringBuilder sb = new StringBuilder();
  sb.append("==[ CoAP Request ]=============================================").append(System.lineSeparator());
  sb.append(String.format("MID    : %d", r.getMID())).append(System.lineSeparator());
  sb.append(String.format("Token  : %s", r.getTokenString())).append(System.lineSeparator());
  sb.append(String.format("Type   : %s", r.getType().toString())).append(System.lineSeparator());
  sb.append(String.format("Method : %s", r.getCode().toString())).append(System.lineSeparator());
  sb.append(String.format("Options: %s", r.getOptions().toString())).append(System.lineSeparator());
  sb.append(String.format("Payload: %d Bytes", r.getPayloadSize())).append(System.lineSeparator());
  if (r.getPayloadSize() > 0 && MediaTypeRegistry.isPrintable(r.getOptions().getContentFormat())) {
    sb.append("---------------------------------------------------------------").append(System.lineSeparator());
    sb.append(r.getPayloadString());
    sb.append(System.lineSeparator());
  }
  sb.append("===============================================================");
  return sb.toString();
}

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

@Override
  public void handleGET(CoapExchange exchange) {

    // get request to read out details
    Request request = exchange.advanced().getRequest();
    
    StringBuilder payload = new StringBuilder();
    payload.append(String.format("Type: %d (%s)\nCode: %d (%s)\nMID: %d\n",
                   request.getType().value,
                   request.getType(),
                   request.getCode().value,
                   request.getCode(),
                   request.getMID()
                  ));
    payload.append("?").append(request.getOptions().getUriQueryString());
    if (payload.length()>64) {
      payload.delete(63, payload.length());
      payload.append('»');
    }
    
    // complete the request
    exchange.respond(CONTENT, payload.toString(), TEXT_PLAIN);
  }
}

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

@Override
public String toString() {
  String payload = getPayloadTracingString();
  return String.format("%s-%-6s MID=%5d, Token=%s, OptionSet=%s, %s", getType(), getCode(), getMID(), getTokenString(), getOptions(), payload);
}

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

@Override
  public void onCancel() {
    if (!exchange.isComplete()) {
      LOGGER.log(Level.FINE, "completing canceled request [MID={0}, token={1}]",
          new Object[]{ exchange.getRequest().getMID(), exchange.getRequest().getTokenString() });
      exchange.setComplete();
    }
  }
}

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

@Override
public String toString() {
  String payload = getPayloadTracingString();
  return String.format("%s-%-6s MID=%5d, Token=%s, OptionSet=%s, %s", getType(), getCode(), getMID(), getTokenString(), getOptions(), payload);
}

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

protected boolean checkResponse(Request request, Response response) {
    boolean success = true;

    success &= checkType(Type.ACK, response.getType());
    success &= checkInt(EXPECTED_RESPONSE_CODE.value,
        response.getCode().value, "code");
    success &= checkInt(request.getMID(), response.getMID(), "MID");

    return success;
  }
}

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

@Override
  public void handleGET(CoapExchange exchange) {
    Request request = exchange.advanced().getRequest();
    
    String payload = String.format("Long path resource\n" +
                    "Type: %d (%s)\nCode: %d (%s)\nMID: %d",
                    request.getType().value,
                    request.getType(),
                    request.getCode().value,
                    request.getCode(),
                    request.getMID()
                   );
    
    // complete the request
    exchange.respond(CONTENT, payload, TEXT_PLAIN);
  }
}

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

protected boolean checkResponse(Request request, Response response) {
    boolean success = true;

    success &= checkType(Type.ACK, response.getType());
    // Code = 65(2.01 Created) or 68 (2.04 changed)
    success &= checkInts(expectedResponseCodes,
        response.getCode().value, "code");
    success &= checkInt(request.getMID(), response.getMID(), "MID");

    return success;
  }
}

代码示例来源: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: eclipse/californium

protected boolean checkResponse(Request request, Response response) {
    boolean success = true;

    success &= checkType(Type.ACK, response.getType());
    // Code = 68 (2.04 Changed) or 65 (2.01 Created)
    success &= checkInts(expectedResponseCodes,
        response.getCode().value, "code");
    success &= checkInt(request.getMID(), response.getMID(), "MID");

    return success;
  }
}

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

@Override
  public void handleGET(CoapExchange exchange) {

    // promise the client that this request will be acted upon by sending an Acknowledgement
    exchange.accept();

    // do the time-consuming computation
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
    }

    // get request to read out details
    Request request = exchange.advanced().getRequest();

    String payload = String.format("Type: %d (%s)\nCode: %d (%s)\nMID: %d\n",
                   request.getType().value,
                   request.getType(),
                   request.getCode().value,
                   request.getCode(),
                   request.getMID()
                  );

    // complete the request
    exchange.respond(CONTENT, payload, TEXT_PLAIN);
  }
}

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

protected boolean checkResponse(Request request, Response response) {
    boolean success = true;

    success &= checkType(Type.ACK, response.getType());
    success &= checkInt(EXPECTED_RESPONSE_CODE.value,
        response.getCode().value, "code");
    success &= checkInt(request.getMID(), response.getMID(), "MID");
    success &= hasContentType(response);
    success &= hasNonEmptyPalyoad(response);

    return success;
  }
}

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

protected final void appendRequestDetails(final Request request) {
  if (request.isCanceled()) {
    buffer.append("CANCELED ");
  }
  buffer.append(request.getType()).append(" [MID=").append(request.getMID())
    .append(", T=").append(request.getTokenString()).append("], ")
    .append(request.getCode()).append(", /").append(request.getOptions().getUriPathString());
  appendBlockOption(1, request.getOptions().getBlock1());
  appendBlockOption(2, request.getOptions().getBlock2());
  appendObserveOption(request.getOptions());
  appendSize1(request.getOptions());
  appendEtags(request.getOptions());
}

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

/**
 * Serializes a request to the wire format.
 * <p>
 * The main difference between this and the <em>serializeRequest</em> method is that this method
 * does <em>not</em> cache the byte array in the request's <em>bytes</em> property.
 * 
 * @param request The request to serialize.
 * @return The encoded request.
 */
public final byte[] getByteArray(final Request request) {
  DatagramWriter writer = new DatagramWriter();
  byte[] body = serializeOptionsAndPayload(request);
  MessageHeader header = new MessageHeader(CoAP.VERSION, request.getType(), request.getToken(),
      request.getRawCode(), request.getMID(), body.length);
  serializeHeader(writer, header);
  writer.writeBytes(body);
  return writer.toByteArray();
}

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

@Test
public void testRegisterOutboundRequestAssignsMid() {
  Exchange exchange = newOutboundRequest();
  // WHEN registering the outbound request
  store.registerOutboundRequest(exchange);
  // THEN the request gets assigned an MID and is put to the store
  assertNotNull(exchange.getCurrentRequest().getMID());
  KeyMID key = KeyMID.fromOutboundMessage(exchange.getCurrentRequest());
  assertThat(store.get(key), is(exchange));
}

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

@Test
public void testRegisterOutboundRequestRejectsOtherRequestWithAlreadyUsedMid() {
  Exchange exchange = newOutboundRequest();
  store.registerOutboundRequest(exchange);
  // WHEN registering another request with the same MID
  Exchange newExchange = newOutboundRequest();
  newExchange.getCurrentRequest().setMID(exchange.getCurrentRequest().getMID());
  try {
    store.registerOutboundRequest(newExchange);
    fail("should have thrown IllegalArgumentException");
  } catch (IllegalArgumentException e) {
    // THEN the newExchange is not put to the store
    KeyMID key = KeyMID.fromOutboundMessage(exchange.getCurrentRequest());
    Exchange exchangeFromStore = store.get(key);
    assertThat(exchangeFromStore, is(exchange));
    assertThat(exchangeFromStore, is(not(newExchange)));
  }
}

代码示例来源: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());
  }

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

private static Response responseFor(final Request request) {
    Response response = new Response(ResponseCode.CONTENT);
    response.setMID(request.getMID());
    response.setToken(request.getToken());
    response.setBytes(new byte[]{});
    response.setSource(request.getDestination());
    response.setSourcePort(request.getDestinationPort());
    response.setDestination(request.getSource());
    response.setDestinationPort(request.getSourcePort());
    return response;
  }
}

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

private Response responseFor(final Request request) {
    Response response = new Response(ResponseCode.CONTENT);
    response.setMID(request.getMID());
    response.setToken(request.getToken());
    response.setBytes(new byte[]{});
    response.setSource(request.getDestination());
    response.setSourcePort(request.getDestinationPort());
    response.setDestination(request.getSource());
    response.setDestinationPort(request.getSourcePort());
    return response;
  }
}

相关文章

微信公众号

最新文章

更多