本文整理了Java中org.eclipse.californium.core.coap.Request.getCode
方法的一些代码示例,展示了Request.getCode
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getCode
方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:getCode
[英]Gets the request code.
[中]获取请求代码。
代码示例来源:origin: org.eclipse.californium/californium-core
private boolean requiresBlockwise(final Request request) {
if (request.getCode() == Code.PUT || request.getCode() == Code.POST) {
return request.getPayloadSize() > max_message_size;
} else {
return false;
}
}
代码示例来源:origin: eclipse/californium
/**
* Gets the request code: <tt>GET</tt>, <tt>POST</tt>, <tt>PUT</tt> or
* <tt>DELETE</tt>.
*
* @return the request code
*/
public Code getRequestCode() {
return exchange.getRequest().getCode();
}
代码示例来源:origin: org.eclipse.californium/californium-core
/**
* Gets the request code: <tt>GET</tt>, <tt>POST</tt>, <tt>PUT</tt> or
* <tt>DELETE</tt>.
*
* @return the request code
*/
public Code getRequestCode() {
return exchange.getRequest().getCode();
}
代码示例来源:origin: eclipse/californium
private boolean requiresBlockwise(final Request request) {
boolean blockwiseRequired = false;
if (request.getCode() == Code.PUT || request.getCode() == Code.POST) {
blockwiseRequired = request.getPayloadSize() > maxMessageSize;
}
if (blockwiseRequired) {
LOGGER.log(Level.FINE, "request body [{0}/{1}] requires blockwise transfer",
new Object[]{request.getPayloadSize(), maxMessageSize});
}
return blockwiseRequired;
}
代码示例来源: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
@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: org.eclipse.californium/californium-core
public byte[] serializeRequest(Request request) {
writer = new DatagramWriter();
Code code = request.getCode();
serializeMessage(request, code == null ? 0 : code.value);
return writer.toByteArray();
}
代码示例来源: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: sitewhere/sitewhere
/**
* Handle a request for device-specific functionality.
*
* @param tenant
* @param paths
* @param exchange
*/
protected void handleDeviceRequest(ITenant tenant, List<String> paths, Exchange exchange) {
if (paths.size() == 0) {
createAndSendResponse(ResponseCode.BAD_REQUEST, "No device token specified.", exchange);
} else {
String deviceToken = paths.remove(0);
switch (exchange.getRequest().getCode()) {
case POST: {
handlePerDevicePostRequest(tenant, deviceToken, paths, exchange);
break;
}
default: {
createAndSendResponse(ResponseCode.BAD_REQUEST, "Operation not available for device.", exchange);
}
}
}
}
代码示例来源: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
public void check(Request request) {
assertEquals(code, request.getCode());
print("Correct code: " + code + " (" + code.value + ")");
}
});
代码示例来源: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: org.github.leshan/leshan-client
@Override
public void deliverRequest(final Exchange exchange) {
final Request request = exchange.getRequest();
final List<String> path = request.getOptions().getUriPath();
final Code code = request.getCode();
final Resource resource = findResource(path, code);
if (resource != null) {
checkForObserveOption(exchange, resource);
// Get the executor and let it process the request
final Executor executor = resource.getExecutor();
if (executor != null) {
executor.execute(new Runnable() {
@Override
public void run() {
resource.handleRequest(exchange);
}
});
} else {
resource.handleRequest(exchange);
}
} else {
LOGGER.info("Did not find resource " + path.toString());
exchange.sendResponse(new Response(ResponseCode.NOT_FOUND));
}
}
代码示例来源: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: org.eclipse.californium/californium-core
/**
* Handles any request in the given exchange. By default it responds
* with a 4.05 (Method Not Allowed). Override this method if your
* resource handler requires advanced access to the internal Exchange class.
* Most developer should be better off with overriding the called methods
* {@link #handleGET(CoapExchange)}, {@link #handlePOST(CoapExchange)},
* {@link #handlePUT(CoapExchange)}, and {@link #handleDELETE(CoapExchange)},
* which provide a better API through the {@link CoapExchange} class.
*
* @param exchange the exchange with the request
*/
@Override
public void handleRequest(final Exchange exchange) {
Code code = exchange.getRequest().getCode();
switch (code) {
case GET: handleGET(new CoapExchange(exchange, this)); break;
case POST: handlePOST(new CoapExchange(exchange, this)); break;
case PUT: handlePUT(new CoapExchange(exchange, this)); break;
case DELETE: handleDELETE(new CoapExchange(exchange, this)); break;
}
}
代码示例来源:origin: eclipse/californium
/**
* Handles any request in the given exchange. By default it responds
* with a 4.05 (Method Not Allowed). Override this method if your
* resource handler requires advanced access to the internal Exchange class.
* Most developer should be better off with overriding the called methods
* {@link #handleGET(CoapExchange)}, {@link #handlePOST(CoapExchange)},
* {@link #handlePUT(CoapExchange)}, and {@link #handleDELETE(CoapExchange)},
* which provide a better API through the {@link CoapExchange} class.
*
* @param exchange the exchange with the request
*/
@Override
public void handleRequest(final Exchange exchange) {
Code code = exchange.getRequest().getCode();
switch (code) {
case GET: handleGET(new CoapExchange(exchange, this)); break;
case POST: handlePOST(new CoapExchange(exchange, this)); break;
case PUT: handlePUT(new CoapExchange(exchange, this)); break;
case DELETE: handleDELETE(new CoapExchange(exchange, this)); break;
}
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!