本文整理了Java中org.eclipse.californium.core.coap.Request.getToken
方法的一些代码示例,展示了Request.getToken
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getToken
方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:getToken
暂无
代码示例来源:origin: eclipse/californium
public ObserveRelation getObserveRelation(byte[] token) {
for (ObserveRelation relation:relations) {
if (Arrays.equals(relation.getExchange().getRequest().getToken(), token)) {
return relation;
}
}
return null;
}
}
代码示例来源:origin: org.eclipse.californium/californium-core
public ObserveRelation getObserveRelation(byte[] token) {
for (ObserveRelation relation:relations) {
if (Arrays.equals(relation.getExchange().getRequest().getToken(), token)) {
return relation;
}
}
return null;
}
}
代码示例来源:origin: eclipse/californium
@Override
public void handleGET(CoapExchange exchange) {
// Check: Type, Code
StringBuilder payload = new StringBuilder();
Request request = exchange.advanced().getRequest();
payload.append(String.format("Type: %d (%s)\nCode: %d (%s)\nMID: %d",
request.getType().value,
request.getType(),
request.getCode().value,
request.getCode(),
request.getMID()));
if (request.getToken().length > 0) {
payload.append("\nToken: ");
StringBuilder tok = new StringBuilder(request.getToken()==null?"null":"");
if (request.getToken()!=null) for(byte b:request.getToken()) tok.append(String.format("%02x", b&0xff));
payload.append(tok);
}
if (payload.length() > 64) {
payload.delete(62, payload.length());
payload.append('»');
}
// complete the request
exchange.setMaxAge(30);
exchange.respond(CONTENT, payload.toString(), TEXT_PLAIN);
}
代码示例来源:origin: eclipse/californium
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
success &= hasObserve(response);
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 &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
return success;
}
}
代码示例来源:origin: eclipse/californium
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkType(Type.CON, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
// Token value = the same value as in the request sent by the client
// in step 2
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
return success;
}
}
代码示例来源: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
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkType(Type.CON, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
success &= hasObserve(response);
return success;
}
}
代码示例来源:origin: eclipse/californium
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkType(Type.CON, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
success &= hasObserve(response);
return success;
}
}
代码示例来源:origin: eclipse/californium
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkType(Type.CON, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
success &= hasObserve(response);
return success;
}
}
代码示例来源:origin: eclipse/californium
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkType(Type.CON, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
success &= hasObserve(response);
return success;
}
}
代码示例来源:origin: eclipse/californium
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkType(Type.CON, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
success &= hasObserve(response);
return success;
}
}
代码示例来源:origin: eclipse/californium
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkType(Type.CON, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
success &= hasObserve(response);
return success;
}
}
代码示例来源:origin: eclipse/californium
protected boolean checkResponse(Request request, Response response) {
boolean success = true;
success &= checkType(Type.CON, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= checkToken(request.getToken(), response.getToken());
success &= hasContentType(response);
success &= hasNonEmptyPalyoad(response);
success &= hasObserve(response);
return success;
}
}
代码示例来源: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
/**
* 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: 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 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
@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 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;
}
}
内容来源于网络,如有侵权,请联系作者删除!