本文整理了Java中org.eclipse.californium.core.coap.Request.getResponse
方法的一些代码示例,展示了Request.getResponse
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getResponse
方法的具体详情如下:
包路径:org.eclipse.californium.core.coap.Request
类名称:Request
方法名:getResponse
[英]Gets the response or null if none has arrived yet.
[中]获取响应,如果还没有响应,则返回null。
代码示例来源:origin: eclipse/californium
/**
* Create a key for the cache starting from a request and the
* content-type of the corresponding response.
*
* @param request
* @return
* @throws URISyntaxException
*/
private static CacheKey fromContentTypeOption(Request request) throws URISyntaxException {
if (request == null) {
throw new IllegalArgumentException("request == null");
}
Response response = request.getResponse();
if (response == null) {
return fromAcceptOptions(request).get(0);
}
String proxyUri = request.getOptions().getProxyUri();
int mediaType = response.getOptions().getContentFormat();
if (mediaType < 0) {
// content-format option not set, use default
mediaType = MediaTypeRegistry.TEXT_PLAIN;
}
byte[] payload = request.getPayload();
// create the new cacheKey
CacheKey cacheKey = new CacheKey(proxyUri, mediaType, payload);
cacheKey.setResponse(response);
return cacheKey;
}
代码示例来源:origin: org.eclipse.californium/californium-proxy
/**
* Create a key for the cache starting from a request and the
* content-type of the corresponding response.
*
* @param request
* @return
* @throws URISyntaxException
*/
private static CacheKey fromContentTypeOption(Request request) throws URISyntaxException {
if (request == null) {
throw new IllegalArgumentException("request == null");
}
Response response = request.getResponse();
if (response == null) {
return fromAcceptOptions(request).get(0);
}
String proxyUri = request.getOptions().getProxyUri();
int mediaType = response.getOptions().getContentFormat();
if (mediaType < 0) {
// content-format option not set, use default
mediaType = MediaTypeRegistry.TEXT_PLAIN;
}
byte[] payload = request.getPayload();
// create the new cacheKey
CacheKey cacheKey = new CacheKey(proxyUri, mediaType, payload);
cacheKey.setResponse(response);
return cacheKey;
}
代码示例来源:origin: eclipse/californium
response = request.getResponse();
代码示例来源:origin: eclipse/californium
/**
* Verifies that incoming responses are not delivered to their originating requests
* if a subclass has already processed the response.
*/
@Test
public void testDeliverResponseYieldsToSubclass() {
// GIVEN a message deliverer subclass that processes all incoming responses
ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) {
@Override
protected boolean preDeliverResponse(Exchange exchange, Response response) {
return true;
}
};
// WHEN a response is received
deliverer.deliverResponse(outboundRequest, incomingResponse);
// THEN the response is not delivered to the request
assertNull(outboundRequest.getRequest().getResponse());
}
代码示例来源:origin: eclipse/californium
/**
* Verifies that incoming responses are delivered to their originating requests
* if a subclass has not already processed the response.
*/
@Test
public void testDeliverResponseProcessesResponseAfterPreDeliverResponse() {
// GIVEN a message deliverer subclass that adds a custom option to incoming
// responses
ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) {
@Override
protected boolean preDeliverResponse(Exchange exchange, Response response) {
response.getOptions().addOption(new Option(200));
return false;
}
};
// WHEN a response is received
deliverer.deliverResponse(outboundRequest, incomingResponse);
// THEN the response is delivered to the request
assertNotNull(outboundRequest.getRequest().getResponse());
// and the response contains the custom option
assertTrue(outboundRequest.getRequest().getResponse().getOptions().hasOption(200));
}
}
内容来源于网络,如有侵权,请联系作者删除!