本文整理了Java中org.eclipse.californium.core.coap.Request.getType
方法的一些代码示例,展示了Request.getType
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getType
方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:getType
暂无
代码示例来源: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: 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
/**
* 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
/**
* 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: 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
@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/leshan
@Override
public void handlePUT(CoapExchange exchange) {
Request request = exchange.advanced().getRequest();
LOG.debug("UPDATE received : {}", request);
if (!Type.CON.equals(request.getType())) {
exchange.respond(ResponseCode.BAD_REQUEST);
return;
}
List<String> uri = exchange.getRequestOptions().getUriPath();
if (uri == null || uri.size() != 2 || !RESOURCE_NAME.equals(uri.get(0))) {
exchange.respond(ResponseCode.BAD_REQUEST);
return;
}
LOG.debug(
"Warning a client made a registration update using a CoAP PUT, a POST must be used since version V1_0-20150615-D of the specification. Request: {}",
request);
handleUpdate(exchange, request, uri.get(1));
}
代码示例来源: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
@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: org.eclipse.californium/californium-core
/**
* Accept this exchange and therefore the request. Only if the request's
* type was a <code>CON</code> and the request has not been acknowledged
* yet, it sends an ACK to the client.
*/
public void sendAccept() {
assert (origin == Origin.REMOTE);
if (request.getType() == Type.CON && !request.isAcknowledged()) {
request.setAcknowledged(true);
EmptyMessage ack = EmptyMessage.newACK(request);
endpoint.sendEmptyMessage(this, ack);
}
}
代码示例来源:origin: eclipse/californium
/**
* Accept this exchange and therefore the request. Only if the request's
* type was a <code>CON</code> and the request has not been acknowledged
* yet, it sends an ACK to the client.
*/
public void sendAccept() {
assert (origin == Origin.REMOTE);
if (request.getType() == Type.CON && !request.isAcknowledged()) {
request.setAcknowledged(true);
EmptyMessage ack = EmptyMessage.newACK(request);
endpoint.sendEmptyMessage(this, ack);
}
}
代码示例来源:origin: eclipse/leshan
@Override
public void handlePOST(CoapExchange exchange) {
Request request = exchange.advanced().getRequest();
LOG.debug("POST received : {}", request);
// The LWM2M spec (section 8.2) mandates the usage of confirmable messages
if (!Type.CON.equals(request.getType())) {
exchange.respond(ResponseCode.BAD_REQUEST);
return;
}
List<String> uri = exchange.getRequestOptions().getUriPath();
if (uri == null || uri.size() == 0 || !RESOURCE_NAME.equals(uri.get(0))) {
exchange.respond(ResponseCode.BAD_REQUEST);
return;
}
if (uri.size() == 1) {
handleRegister(exchange, request);
return;
} else if (uri.size() == 2) {
handleUpdate(exchange, request, uri.get(1));
return;
} else {
exchange.respond(ResponseCode.BAD_REQUEST);
return;
}
}
代码示例来源: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 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/leshan
if (!Type.CON.equals(request.getType())) {
exchange.respond(ResponseCode.BAD_REQUEST);
return;
代码示例来源: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
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: 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;
}
内容来源于网络,如有侵权,请联系作者删除!