public static CreateResponse notFound() { return new CreateResponse(ResponseCode.NOT_FOUND, null, null); }
@Override public boolean isSuccess() { return getCode() == ResponseCode.CREATED; }
protected CreateResponse doCreate(CreateRequest request) { // This should be a not implemented error, but this is not defined in the spec. return CreateResponse.internalServerError("not implemented"); }
if (response.getCode() == org.eclipse.leshan.ResponseCode.CREATED) { exchange.setLocationPath(response.getLocation()); exchange.respond(toCoapResponseCode(response.getCode())); return; } else { exchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage()); return;
public static JsonObject jSerialize(LwM2mResponse r) { final JsonObject o = Json.object(); o.add("code", r.getCode().toString()); if (r.isFailure()) { o.add("errorMessage", r.getErrorMessage()); return o; } if (r instanceof ReadResponse) { o.add("kind", "read"); o.add("content", LwM2mNodeSerDes.jSerialize(((ReadResponse) r).getContent())); } else if (r instanceof ObserveResponse) { o.add("kind", "observe"); o.add("content", LwM2mNodeSerDes.jSerialize(((ReadResponse) r).getContent())); } else if (r instanceof DiscoverResponse) { o.add("kind", "discover"); o.add("objectLinks", Link.serialize(((DiscoverResponse) r).getObjectLinks())); } else if (r instanceof DeleteResponse) { o.add("kind", "delete"); } else if (r instanceof ExecuteResponse) { o.add("kind", "execute"); } else if (r instanceof WriteResponse) { o.add("kind", "write"); } else if (r instanceof WriteAttributesResponse) { o.add("kind", "writeAttributes"); } else if (r instanceof CreateResponse) { o.add("kind", "create"); o.add("location", ((CreateResponse) r).getLocation()); } return o; }
@Override public synchronized CreateResponse create(ServerIdentity identity, CreateRequest request) { if (!identity.isSystem()) { // we can not create new instance on single object if (objectModel != null && !objectModel.multiple) { return CreateResponse.methodNotAllowed(); } if (id == LwM2mId.SECURITY) { return CreateResponse.notFound(); } } // TODO we could do a validation of request.getObjectInstance() by comparing with resourceSpec information. return doCreate(request); }
public static JsonObject jSerialize(LwM2mResponse r) { final JsonObject o = Json.object(); o.add("code", r.getCode().toString()); if (r.isFailure()) { o.add("errorMessage", r.getErrorMessage()); return o; } if (r instanceof ReadResponse) { o.add("kind", "read"); o.add("content", LwM2mNodeSerDes.jSerialize(((ReadResponse) r).getContent())); } else if (r instanceof ObserveResponse) { o.add("kind", "observe"); o.add("content", LwM2mNodeSerDes.jSerialize(((ReadResponse) r).getContent())); } else if (r instanceof DiscoverResponse) { o.add("kind", "discover"); o.add("objectLinks", Link.serialize(((DiscoverResponse) r).getObjectLinks())); } else if (r instanceof DeleteResponse) { o.add("kind", "delete"); } else if (r instanceof ExecuteResponse) { o.add("kind", "execute"); } else if (r instanceof WriteResponse) { o.add("kind", "write"); } else if (r instanceof WriteAttributesResponse) { o.add("kind", "writeAttributes"); } else if (r instanceof CreateResponse) { o.add("kind", "create"); o.add("location", ((CreateResponse) r).getLocation()); } return o; }
public static CreateResponse internalServerError(String errorMessage) { return new CreateResponse(ResponseCode.INTERNAL_SERVER_ERROR, null, errorMessage); } }
public static CreateResponse unauthorized() { return new CreateResponse(ResponseCode.UNAUTHORIZED, null, null); }
public static CreateResponse success(String location) { return new CreateResponse(ResponseCode.CREATED, location, null); }
public static CreateResponse unsupportedContentFormat() { return new CreateResponse(ResponseCode.UNSUPPORTED_CONTENT_FORMAT, null, null); }
public static CreateResponse badRequest(String errorMessage) { return new CreateResponse(ResponseCode.BAD_REQUEST, null, errorMessage); }
public static CreateResponse methodNotAllowed() { return new CreateResponse(ResponseCode.METHOD_NOT_ALLOWED, null, null); }
return new CreateResponse();
@Override public void visit(CreateRequest request) { if (coapResponse.isError()) { // handle error response: lwM2mresponse = new CreateResponse(toLwM2mResponseCode(coapResponse.getCode()), null, coapResponse.getPayloadString(), coapResponse); } else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.CREATED) { // handle success response: lwM2mresponse = new CreateResponse(ResponseCode.CREATED, coapResponse.getOptions().getLocationPathString(), null, coapResponse); } else { // handle unexpected response: handleUnexpectedResponseCode(registration.getEndpoint(), request, coapResponse); } }
@Override public void visit(final CreateRequest request) { switch (coapResponse.getCode()) { case CREATED: lwM2mresponse = new CreateResponse(fromCoapCode(coapResponse.getCode().value), coapResponse.getOptions() .getLocationPathString()); break; case BAD_REQUEST: case UNAUTHORIZED: case NOT_FOUND: case METHOD_NOT_ALLOWED: lwM2mresponse = new CreateResponse(fromCoapCode(coapResponse.getCode().value)); break; default: handleUnexpectedResponseCode(client.getEndpoint(), coapRequest, coapResponse); } }
case "create": { String location = o.getString("location", null); return new CreateResponse(code, location, errorMessage);
case "create": { String location = o.getString("location", null); return new CreateResponse(code, location, errorMessage);