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

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

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

Request.setType介绍

暂无

代码示例

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

private Request applyRequestType(Request request) {
  request.setType(this.type);
  return request;
}

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

/**
 * Schedules a retransmission for confirmable messages. 
 */
@Override
public void sendRequest(final Exchange exchange, final Request request) {
  LOGGER.log(Level.FINER, "Send request, failed transmissions: {0}", exchange.getFailedTransmissionCount());
  if (request.getType() == null) {
    request.setType(Type.CON);
  }
  if (request.getType() == Type.CON) {
    prepareRetransmission(exchange, new RetransmissionTask(exchange, request) {
      public void retransmit() {
        sendRequest(exchange, request);
      }
    });
  }
  super.sendRequest(exchange, request);
}

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

/**
 * Schedules a retransmission for confirmable messages.
 */
@Override
public void sendRequest(final Exchange exchange, final Request request) {
  LOGGER.log(Level.FINER, "Send request, failed transmissions: {0}", exchange.getFailedTransmissionCount());
  if (request.getType() == null) {
    request.setType(Type.CON);
  }
  if (request.getType() == Type.CON) {
    prepareRetransmission(exchange, new RetransmissionTask(exchange, request) {
      public void retransmit() {
        sendRequest(exchange, request);
      }
    });
  }
  lower().sendRequest(exchange, request);
}

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

/**
 * Sends the specified request over the specified endpoint.
 * 
 * @param request the request
 * @param outEndpoint the endpoint
 * @return the request
 */
protected Request send(Request request, Endpoint outEndpoint) {
  // use the specified message type
  request.setType(this.type);
  if (blockwise!=0) {
    request.getOptions().setBlock2(new BlockOption(BlockOption.size2Szx(this.blockwise), false, 0));
  }
  
  outEndpoint.sendRequest(request);
  return request;
}

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

/**
 * Verifies that the server cleans up all exchanges after serving a NON GET.
 * 
 * @throws Exception if the test fails.
 */
@Test
public void testSimpleNONGet() throws Exception {
  String uri = uriOf(URI);
  LOGGER.log(Level.FINE, "Test simple NON GET to {0}", uri);
  String currentResponseText = "simple NON GET";
  resource.setResponse(currentResponseText, Mode.PIGGY_BACKED_RESPONSE);
  Request request = Request.newGet();
  request.setURI(uri);
  request.setType(Type.NON);
  Response response = request.send(clientEndpoint).waitForResponse(ACK_TIMEOUT);
  assertThat("Client did not receive response to NON request in time", response, is(notNullValue()));
  LOGGER.log(Level.FINE, "Client received response [{0}] with msg type [{1}]", new Object[]{response.getPayloadString(), response.getType()});
  assertThat(response.getPayloadString(), is(currentResponseText));
  assertThat(response.getType(), is(Type.NON));
}

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

exchange.getCurrentRequest().setType(Type.CON);
} else if (exchange.getCurrentResponse() != null) {
  exchange.getCurrentResponse().setType(Type.CON);

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

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

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

exchange.getCurrentRequest().setType(Type.CON);
} else if (exchange.getCurrentResponse() != null) {
  exchange.getCurrentResponse().setType(Type.CON);

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

private static Request getNextRequestBlock(final Request request, final BlockwiseStatus status) {
  int num = status.getCurrentNum();
  int szx = status.getCurrentSzx();
  Request block = new Request(request.getCode());
  // do not enforce CON, since NON could make sense over SMS or similar transports
  block.setType(request.getType());
  block.setDestination(request.getDestination());
  block.setDestinationPort(request.getDestinationPort());
  // copy options
  block.setOptions(new OptionSet(request.getOptions()));
  // copy message observers so that a failing blockwise request also notifies observers registered with
  // the original request
  block.addMessageObservers(request.getMessageObservers());
  int currentSize = 1 << (4 + szx);
  int from = num * currentSize;
  int to = Math.min((num + 1) * currentSize, request.getPayloadSize());
  int length = to - from;
  byte[] blockPayload = new byte[length];
  System.arraycopy(request.getPayload(), from, blockPayload, 0, length);
  block.setPayload(blockPayload);
  boolean m = (to < request.getPayloadSize());
  block.getOptions().setBlock1(szx, m, num);
  status.setComplete(!m);
  return block;
}

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

block.setType(request.getType());
block.setDestination(request.getDestination());
block.setDestinationPort(request.getDestinationPort());

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

block.setType(request.getType());
block.setDestination(request.getDestination());
block.setDestinationPort(request.getDestinationPort());

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

相关文章