本文整理汇总了Java中org.eclipse.californium.core.coap.CoAP.ResponseCode类的典型用法代码示例。如果您正苦于以下问题:Java ResponseCode类的具体用法?Java ResponseCode怎么用?Java ResponseCode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResponseCode类属于org.eclipse.californium.core.coap.CoAP包,在下文中一共展示了ResponseCode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePOST
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的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.coap.CoAP.ResponseCode; //导入依赖的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.coap.CoAP.ResponseCode; //导入依赖的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: convertToRuleEngineErrorResponse
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
private Response convertToRuleEngineErrorResponse(CoapSessionCtx ctx, RuleEngineErrorMsg msg) {
ResponseCode status = ResponseCode.INTERNAL_SERVER_ERROR;
switch (msg.getError()) {
case PLUGIN_TIMEOUT:
status = ResponseCode.GATEWAY_TIMEOUT;
break;
default:
if (msg.getInMsgType() == MsgType.TO_SERVER_RPC_REQUEST) {
status = ResponseCode.BAD_REQUEST;
}
break;
}
Response response = new Response(status);
response.setPayload(JsonConverter.toErrorJson(msg.getErrorMsg()).toString());
return response;
}
示例5: checkObserveRelation
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
/**
* This method is used to apply resource-specific knowledge on the exchange.
* If the request was successful, it sets the Observe option for the
* response. It is important to use the notificationOrderer of the resource
* here. Further down the layer, race conditions could cause local
* reordering of notifications. If the response has an error code, no
* observe relation can be established and if there was one previously it is
* canceled. When this resource allows to be observed by clients and the
* request is a GET request with an observe option, the
* {@link ServerMessageDeliverer} already created the relation, as it
* manages the observing endpoints globally.
*
* @param exchange the exchange
* @param response the response
*/
public void checkObserveRelation(Exchange exchange, Response response) {
/*
* If the request for the specified exchange tries to establish an observer
* relation, then the ServerMessageDeliverer must have created such a relation
* and added to the exchange. Otherwise, there is no such relation.
* Remember that different paths might lead to this resource.
*/
ObserveRelation relation = exchange.getRelation();
if (relation == null) return; // because request did not try to establish a relation
if (CoAP.ResponseCode.isSuccess(response.getCode())) {
response.getOptions().setObserve(notificationOrderer.getCurrent());
if (!relation.isEstablished()) {
relation.setEstablished(true);
addObserveRelation(relation);
} else if (observeType != null) {
// The resource can control the message type of the notification
response.setType(observeType);
}
} // ObserveLayer takes care of the else case
}
示例6: clearAndNotifyObserveRelations
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
/**
* Remove all observe relations to CoAP clients and notify them that the
* observe relation has been canceled.
*
* @param code
* the error code why the relation was terminated
* (e.g., 4.04 after deletion)
*/
public void clearAndNotifyObserveRelations(ResponseCode code) {
/*
* draft-ietf-core-observe-08, chapter 3.2 Notification states:
* In the event that the resource changes in a way that would cause
* a normal GET request at that time to return a non-2.xx response
* (for example, when the resource is deleted), the server sends a
* notification with a matching response code and removes the client
* from the list of observers.
* This method is called, when the resource is deleted.
*/
for (ObserveRelation relation:observeRelations) {
relation.cancel();
relation.getExchange().sendResponse(new Response(code));
}
}
示例7: deliverRequest
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
@Override
public void deliverRequest(final Exchange exchange) {
Request request = exchange.getRequest();
List<String> path = request.getOptions().getUriPath();
final Resource resource = findResource(path);
if (resource != null) {
checkForObserveOption(exchange, resource);
// Get the executor and let it process the request
Executor executor = resource.getExecutor();
if (executor != null) {
exchange.setCustomExecutor();
executor.execute(new Runnable() {
public void run() {
resource.handleRequest(exchange);
} });
} else {
resource.handleRequest(exchange);
}
} else {
LOGGER.info("Did not find resource " + path.toString() + " requested by " + request.getSource()+":"+request.getSourcePort());
exchange.sendResponse(new Response(ResponseCode.NOT_FOUND));
}
}
示例8: testSuccessDTLS
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
@Test
public void testSuccessDTLS() throws Exception {
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getResourceServers().get(0).getAud());
req.setClientID(config.getClients().get(0).getClient_id());
req.setClientSecret(config.getClients().get(0).getClient_secret());
req.setScopes(config.getResourceServers().get(0).getScopes());
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
System.out.println(response);
System.out.println("Time elapsed (ms): " + response.getRTT());
Assert.assertEquals(response.getCode(), ResponseCode.CONTENT);
}
示例9: testSuccessClientGeneratedECKeys
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
@Test
public void testSuccessClientGeneratedECKeys() throws Exception {
JsonWebKey popKey = EcJwkGenerator.generateJwk(EllipticCurves.P256);
popKey.setKeyId("testkid");
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getResourceServers().get(0).getAud());
req.setClientID(config.getClients().get(0).getClient_id());
req.setClientSecret(config.getClients().get(0).getClient_secret());
req.setScopes(config.getResourceServers().get(0).getScopes());
req.setKey(popKey);
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(ResponseCode.CONTENT, response.getCode());
TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
示例10: testSuccessClientGeneratedRSAKeys
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
@Test
public void testSuccessClientGeneratedRSAKeys() throws Exception {
JsonWebKey popKey = RsaJwkGenerator.generateJwk(2048);
popKey.setKeyId("testkid");
TokenRequest req = new TokenRequest();
req.setGrantType("client_credentials");
req.setAud(config.getResourceServers().get(0).getAud());
req.setClientID(config.getClients().get(0).getClient_id());
req.setClientSecret(config.getClients().get(0).getClient_secret());
req.setScopes(config.getResourceServers().get(0).getScopes());
req.setKey(popKey);
Response response = DTLSUtils.dtlsPSKRequest("coaps://localhost:"+config.getCoapsPort()+"/"+Constants.TOKEN_RESOURCE, "POST", req.toPayload(MediaTypeRegistry.APPLICATION_JSON), MediaTypeRegistry.APPLICATION_JSON, config.getPskIdentity(), config.getPskKey().getBytes());
Assert.assertEquals(ResponseCode.CONTENT, response.getCode());
TokenResponse tokenResponse = new TokenResponse(response.getPayload(), MediaTypeRegistry.APPLICATION_JSON);
TestUtils.validateToken(tokenResponse.getAccessToken().getBytes(), config.getResourceServers().get(0).getAud(), MediaTypeRegistry.APPLICATION_JSON);
}
示例11: handlePUT
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
@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));
}
示例12: unknown_lwm2m_code_to_unknown_coap_code
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
@Test
public void unknown_lwm2m_code_to_unknown_coap_code() {
// californium behavior is not really consistent
// for success : code value is lost but we know we use an unknown code
ResponseCode coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(206));
Assert.assertEquals(ResponseCode._UNKNOWN_SUCCESS_CODE, coapResponseCode);
// for client error,: unknown code is replace by BAD REQUEST ...
coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(425));
Assert.assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode);
// for server error : unknown code is replace by INTERNAL SERVER ERROR ...
coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(509));
Assert.assertEquals(ResponseCode.INTERNAL_SERVER_ERROR, coapResponseCode);
}
示例13: CoAPResponseAssertionGui
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
/**
* Create a new AssertionGui panel.
*/
public CoAPResponseAssertionGui() {
messagePanel = new CoAPResponseAssertionMessagePanel();
optionPanel = new CoAPResponseAssertionOptionPanel();
List<Type> types = new ArrayList<Type>();
types.add(Type.CON);
types.add(Type.NON);
types.add(Type.ACK);
types.add(Type.RST);
messagePanel.initCmbType(types);
List<ResponseCode> codes = new ArrayList<ResponseCode>();
for (ResponseCode code:ResponseCode.values())
codes.add(code);
messagePanel.initCmbCode(codes);
Set<Integer> registry = MediaTypeRegistry.getAllMediaTypes();
List<String> media_types = new ArrayList<String>();
media_types.add("");
for(Integer i : registry)
media_types.add(MediaTypeRegistry.toString(i));
optionPanel.initCmbAccept(media_types);
optionPanel.initCmbContentFormat(media_types);
init();
}
示例14: handleGET
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的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);
}
}
示例15: getMoods
import org.eclipse.californium.core.coap.CoAP.ResponseCode; //导入依赖的package包/类
public static String getMoods(GWConnection gateway, TradfriGroup group) {
CoapResponse resp = gateway.get("/15005/" + group.getGroupID());
if(!ResponseCode.isSuccess(resp.getCode())) {
System.out.println("Get moods failed!");
return "";
}else {
try {
JSONArray moodIDs = new JSONArray(resp.getResponseText());
JSONArray returnJSON = new JSONArray();
for(int i = 0; i < moodIDs.length(); i++) {
int currentID = moodIDs.getInt(i);
group.mood(currentID).update();
JSONObject currentKey = new JSONObject();
currentKey.put("groupid", group.mood(currentID).getGroupID());
currentKey.put("moodid", group.mood(currentID).getMoodID());
currentKey.put("name", group.mood(currentID).getName());
returnJSON.put(currentKey);
}
return returnJSON.toString();
}catch(Exception e) {
System.out.println("Unexpected response: " + e.getMessage());
return "";
}
}
}