本文整理汇总了Java中org.eclipse.californium.core.server.resources.CoapExchange.respond方法的典型用法代码示例。如果您正苦于以下问题:Java CoapExchange.respond方法的具体用法?Java CoapExchange.respond怎么用?Java CoapExchange.respond使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.californium.core.server.resources.CoapExchange
的用法示例。
在下文中一共展示了CoapExchange.respond方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePOST
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePOST(CoapExchange exchange) {
Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
if (!featureType.isPresent()) {
log.trace("Missing feature type parameter");
exchange.respond(ResponseCode.BAD_REQUEST);
} else {
switch (featureType.get()) {
case ATTRIBUTES:
processRequest(exchange, MsgType.POST_ATTRIBUTES_REQUEST);
break;
case TELEMETRY:
processRequest(exchange, MsgType.POST_TELEMETRY_REQUEST);
break;
case RPC:
Optional<Integer> requestId = getRequestId(exchange.advanced().getRequest());
if (requestId.isPresent()) {
processRequest(exchange, MsgType.TO_DEVICE_RPC_RESPONSE);
} else {
processRequest(exchange, MsgType.TO_SERVER_RPC_REQUEST);
}
break;
}
}
}
示例2: handleGET
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
if (!featureType.isPresent()) {
log.trace("Missing feature type parameter");
exchange.respond(ResponseCode.BAD_REQUEST);
} else if (featureType.get() == FeatureType.TELEMETRY) {
log.trace("Can't fetch/subscribe to timeseries updates");
exchange.respond(ResponseCode.BAD_REQUEST);
} else if (exchange.getRequestOptions().hasObserve()) {
processExchangeGetRequest(exchange, featureType.get());
} else if (featureType.get() == FeatureType.ATTRIBUTES) {
processRequest(exchange, MsgType.GET_ATTRIBUTES_REQUEST);
} else {
log.trace("Invalid feature type parameter");
exchange.respond(ResponseCode.BAD_REQUEST);
}
}
示例3: handlePOST
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePOST(CoapExchange exchange) {
Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
if (!featureType.isPresent()) {
log.trace("Missing feature type parameter");
exchange.respond(ResponseCode.BAD_REQUEST);
} else {
switch (featureType.get()) {
case ATTRIBUTES:
processRequest(exchange, MsgType.POST_ATTRIBUTES_REQUEST);
break;
case TELEMETRY:
processRequest(exchange, MsgType.POST_TELEMETRY_REQUEST);
break;
case RPC:
Optional<Integer> requestId = getRequestId(exchange.advanced().getRequest());
if (requestId.isPresent()) {
processRequest(exchange, MsgType.TO_DEVICE_RPC_RESPONSE);
} else {
processRequest(exchange, MsgType.TO_SERVER_RPC_REQUEST);
}
break;
}
}
}
示例4: handle
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
public void handle(CoapExchange exchange) {
if (shuttingDown) {
LOG.debug("Shutting down, discarding incoming request from '{}'", exchange.getSourceAddress());
exchange.respond(CoAP.ResponseCode.SERVICE_UNAVAILABLE);
} else {
long start = System.currentTimeMillis();
LOG.debug("Request accepted from '{}'", exchange.getSourceAddress());
try {
if (receiver.process(exchange.getRequestPayload())) {
exchange.respond(CoAP.ResponseCode.VALID);
exchange.accept();
requestMeter.mark();
} else {
exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
exchange.accept();
errorRequestMeter.mark();
}
} catch (IOException ex) {
exchange.reject();
errorQueue.offer(ex);
errorRequestMeter.mark();
} finally {
requestTimer.update(System.currentTimeMillis() - start, TimeUnit.MILLISECONDS);
}
}
}
示例5: handleGET
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
Optional<FeatureType> featureType = getFeatureType(exchange.advanced().getRequest());
if (!featureType.isPresent()) {
log.trace("Missing feature type parameter");
exchange.respond(ResponseCode.BAD_REQUEST);
} else if (featureType.get() == FeatureType.TELEMETRY) {
log.trace("Can't fetch/subscribe to timeseries updates");
exchange.respond(ResponseCode.BAD_REQUEST);
} else if (exchange.getRequestOptions().hasObserve()) {
boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1;
MsgType msgType;
if (featureType.get() == FeatureType.RPC) {
msgType = unsubscribe ? MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST : MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST;
} else {
msgType = unsubscribe ? MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST : MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST;
}
Optional<SessionId> sessionId = processRequest(exchange, msgType);
if (sessionId.isPresent()) {
if (exchange.getRequestOptions().getObserve() == 1) {
exchange.respond(ResponseCode.VALID);
}
}
} else if (featureType.get() == FeatureType.ATTRIBUTES) {
processRequest(exchange, MsgType.GET_ATTRIBUTES_REQUEST);
} else {
log.trace("Invalid feature type parameter");
exchange.respond(ResponseCode.BAD_REQUEST);
}
}
示例6: processExchangeGetRequest
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
private void processExchangeGetRequest(CoapExchange exchange, FeatureType featureType) {
boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1;
MsgType msgType;
if (featureType == FeatureType.RPC) {
msgType = unsubscribe ? MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST : MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST;
} else {
msgType = unsubscribe ? MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST : MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST;
}
Optional<SessionId> sessionId = processRequest(exchange, msgType);
if (sessionId.isPresent()) {
if (exchange.getRequestOptions().getObserve() == 1) {
exchange.respond(ResponseCode.VALID);
}
}
}
示例7: sendCoapResponse
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
private boolean sendCoapResponse(OneM2mResponse resMessage, CoapExchange exchange) {
if (exchange == null) {
return false;
}
coapMap.remove(resMessage.getRequestIdentifier());
try {
Response response = CoapResponseCodec.encode(resMessage, exchange);
log.debug("<< SEND CoAP MESSAGE:");
log.debug(response.toString());
log.debug(response.getPayloadString());
exchange.respond(response);
// added in 2017-10-31 to support CSE-relative Unstructured addressing
System.out.println("############### uripath-size=" + exchange.getRequestOptions().getUriPath().size());
//System.out.println("############### resMessage.getResponseStatusCode()=" + resMessage.getResponseStatusCode());
///System.out.println("############### resourceId=" + ((Resource)resMessage.getContentObject()).getResourceID());
int len = exchange.getRequestOptions().getUriPath().size();
int resCode = resMessage.getResponseStatusCode();
if(resCode == 2001 && len == 1) {
String resourceId = ((Resource)resMessage.getContentObject()).getResourceID();
coapServer.add(coapServer.new HCoapResource(resourceId));
}
//coapServer.add(resources)
return true;
} catch (Exception e) {
e.printStackTrace();
exchange.respond(ResponseCode.INTERNAL_SERVER_ERROR, "Respose encoding failed");
}
return false;
}
示例8: receiveRequest
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
private void receiveRequest(CoapExchange exchange) {
if(listener != null) {
listener.receiveCoapRequest(exchange);
} else {
exchange.respond(ResponseCode.INTERNAL_SERVER_ERROR, "Not found listener");
}
}
示例9: respond
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
public static void respond(CoapExchange exchange, ResponseCode code, byte[] payload, int contentFormat) {
exchange.respond(code, payload, contentFormat);
logger.info("--------------------------- RESPONSE ----------------------------------------");
logger.info("Header: " + code + " Content (T=" + exchange.advanced().getRequest().getType() + ", Code=" + code + ", MID=" + exchange.advanced().getRequest().getMID() + ")");
logger.info("Options: " + exchange.advanced().getResponse().getOptions());
logger.info("Token: " + exchange.advanced().getRequest().getTokenString());
if(contentFormat == MediaTypeRegistry.APPLICATION_JSON) {
logger.info("Payload:\n" + new String(payload) + "\n");
}
else if(contentFormat == MediaTypeRegistry.APPLICATION_CBOR) {
logger.info("Payload (Diagnostic):\n" + new String(payload) + "\n");
}
}
示例10: handlePOST
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@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;
}
}
示例11: handleGET
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
// TODO Auto-generated method stub
Log.i("DIMXML", "Using GET");
exchange.respond(CONTENT, bloodPressureStr, dataCf);
}
示例12: handleGET
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
// TODO Auto-generated method stub
exchange.setMaxAge(5);
exchange.respond(CONTENT, m_device_10472.m_Msg.toString(),dataCf);
}
示例13: handleDELETE
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleDELETE(CoapExchange exchange) {
if (!StringUtils.isEmpty(exchange.getRequestOptions().getUriPathString())) {
exchange.respond(ResponseCode.METHOD_NOT_ALLOWED);
return;
}
ServerIdentity identity = ResourceUtil.extractServerIdentity(exchange, bootstrapHandler);
BootstrapDeleteResponse response = bootstrapHandler.delete(identity, new BootstrapDeleteRequest());
exchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage());
}
示例14: handlePUT
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handlePUT(CoapExchange exchange) {
// TODO Auto-generated method stub
System.out.println(this.getClass().getName() + " PUT ");
if (!exchange.getRequestOptions().hasContentFormat()) {
exchange.respond(BAD_REQUEST, "Content-Format not set");
return;
}
// store payload
storeDate(exchange.getRequestPayload(), exchange.getRequestOptions()
.getContentFormat());
exchange.respond(CHANGED);
}
示例15: handleGET
import org.eclipse.californium.core.server.resources.CoapExchange; //导入方法依赖的package包/类
@Override
public void handleGET(CoapExchange exchange) {
// TODO Auto-generated method stub
Log.i("DIMXML", "Using GET");
exchange.respond(CONTENT, bloodPressureStr, dataCf);
}