本文整理了Java中org.eclipse.californium.core.coap.Response.getMID
方法的一些代码示例,展示了Response.getMID
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getMID
方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Response
类名称:Response
方法名:getMID
暂无
代码示例来源:origin: eclipse/californium
/**
* Formats a {@link Response} into a readable String representation.
*
* @param r the Response
* @return the pretty print
*/
public static String prettyPrint(Response r) {
StringBuilder sb = new StringBuilder();
sb.append("==[ CoAP Response ]============================================").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("Status : %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: org.eclipse.californium/californium-core
/**
* Formats a {@link Response} into a readable String representation.
*
* @param r the Response
* @return the pretty print
*/
public static String prettyPrint(Response r) {
StringBuilder sb = new StringBuilder();
sb.append("==[ CoAP Response ]============================================").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("Status : %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: org.eclipse.californium/californium-core
private void removeNotificatoinsOf(Exchange exchange) {
ObserveRelation relation = exchange.getRelation();
if (null != relation) {
LOGGER.fine("Remove all remaining NON-notifications of observe relation");
for (Iterator<Response> iterator = relation.getNotificationIterator(); iterator.hasNext();) {
Response previous = iterator.next();
// notifications are local MID namespace
if (previous.hasMID()) {
KeyMID idByMID = new KeyMID(previous.getMID(), null, 0);
exchangesByMID.remove(idByMID, exchange);
iterator.remove();
}
else {
previous.cancel();
}
}
}
}
代码示例来源: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: 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
private void lose(Response response) {
System.out.println(System.lineSeparator() + "Lose response " + counter + " with MID " + response.getMID()
+ ", payload = " + response.getPayloadString());
response.cancel();
}
}
代码示例来源: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
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
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(Response request, boolean incoming) {
this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request
.getPayload());
this.code = request.getCode().toString();
}
代码示例来源:origin: org.eclipse.californium/californium-core
if (response.getType() == Type.ACK) {
idByMID = new KeyMID(response.getMID(), null, 0);
} else {
idByMID = new KeyMID(response.getMID(), response.getSource().getAddress(), response.getSourcePort());
if (response.getType() == Type.ACK && exchange.getCurrentRequest().getMID() != response.getMID()) {
LOGGER.warning("Possible MID reuse before lifetime end: "+response.getTokenString()+" expected MID "+exchange.getCurrentRequest().getMID()+" but received "+response.getMID());
代码示例来源: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: org.eclipse.californium/californium-core
public void sendResponse(Exchange exchange, Response response) {
if (response.getMID() == Message.NONE) {
response.setMID(currendMID.getAndIncrement() & 0x0000FFFF);
KeyMID idByMID = new KeyMID(response.getMID(), null, 0);
exchangesByMID.put(idByMID, exchange);
代码示例来源:origin: eclipse/californium
} else if (isResponseRelatedToRequest(exchange, responseContext)) {
if (response.getType() == Type.ACK && exchange.getCurrentRequest().getMID() != response.getMID()) {
response.getMID() });
代码示例来源:origin: org.eclipse.californium/californium-core
idByMID = new KeyMID(ongoing.getCurrentResponse().getMID(), null, 0);
if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Ongoing exchange got new request, cleaning up "+idByMID);
exchangesByMID.remove(idByMID, ongoing);
代码示例来源:origin: eclipse/californium
protected final void appendResponseDetails(final Response response) {
if (response.isCanceled()) {
buffer.append("CANCELED ");
}
buffer.append(response.getType()).append(" [MID=").append(response.getMID())
.append(", T=").append(response.getTokenString()).append("], ")
.append(response.getCode());
appendBlockOption(1, response.getOptions().getBlock1());
appendBlockOption(2, response.getOptions().getBlock2());
appendObserveOption(response.getOptions());
appendSize1(response.getOptions());
appendSize2(response.getOptions());
appendEtags(response.getOptions());
}
代码示例来源:origin: org.eclipse.californium/californium-core
KeyMID midKey = new KeyMID(response.getMID(), null, 0);
LOGGER.log(Level.FINE, "Remote ongoing completed, cleaning up {0}", midKey);
exchangesByMID.remove(midKey, exchange);
代码示例来源:origin: eclipse/californium
/**
* Serializes response and caches bytes on the request object to skip future serializations.
*
* @param response The response to serialize.
* @return The object containing the serialized response.
*/
public final RawData serializeResponse(final Response response) {
if (response.getBytes() == null) {
DatagramWriter writer = new DatagramWriter();
byte[] body = serializeOptionsAndPayload(response);
MessageHeader header = new MessageHeader(CoAP.VERSION, response.getType(), response.getToken(),
response.getCode().value, response.getMID(), body.length);
serializeHeader(writer, header);
writer.writeBytes(body);
byte[] bytes = writer.toByteArray();
response.setBytes(bytes);
}
return new RawData(response.getBytes(), response.getDestination(), response.getDestinationPort());
}
代码示例来源:origin: eclipse/californium
@Test public void testResponseParsing() {
Response response = new Response(ResponseCode.CONTENT);
response.setType(Type.NON);
response.setMID(expectedMid);
response.setToken(new byte[] { 22, -1, 0, 78, 100, 22 });
response.getOptions().addETag(new byte[] { 1, 0, 0, 0, 0, 1 })
.addLocationPath("/one/two/three/four/five/six/seven/eight/nine/ten")
.addOption(new Option(57453, "Arbitrary".hashCode())).addOption(new Option(19205, "Arbitrary1"))
.addOption(new Option(19205, "Arbitrary2")).addOption(new Option(19205, "Arbitrary3"));
RawData rawData = serializer.serializeResponse(response);
Response result = (Response) parser.parseMessage(rawData);
assertEquals(response.getMID(), result.getMID());
assertArrayEquals(response.getToken(), result.getToken());
assertEquals(response.getOptions().asSortedList(), result.getOptions().asSortedList());
}
代码示例来源:origin: eclipse/californium
@Test public void testUTF8Encoding() {
Response response = new Response(ResponseCode.CONTENT);
response.setType(Type.NON);
response.setMID(expectedMid);
response.setToken(new byte[] {});
response.getOptions().addLocationPath("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ").addLocationPath("γλώσσα")
.addLocationPath("пустынных").addLocationQuery("ვეპხის=யாமறிந்த").addLocationQuery("⠊⠀⠉⠁⠝=⠑⠁⠞⠀⠛⠇⠁⠎⠎");
response.setPayload("⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑");
RawData rawData = serializer.serializeResponse(response);
Response result = (Response) parser.parseMessage(rawData);
assertEquals("ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ/γλώσσα/пустынных", response.getOptions().getLocationPathString());
assertEquals("ვეპხის=யாமறிந்த&⠊⠀⠉⠁⠝=⠑⠁⠞⠀⠛⠇⠁⠎⠎", response.getOptions().getLocationQueryString());
assertEquals("⠊⠀⠉⠁⠝⠀⠑⠁⠞⠀⠛⠇⠁⠎⠎⠀⠁⠝⠙⠀⠊⠞⠀⠙⠕⠑⠎⠝⠞⠀⠓⠥⠗⠞⠀⠍⠑", result.getPayloadString());
assertEquals(response.getMID(), result.getMID());
}
}
内容来源于网络,如有侵权,请联系作者删除!