本文整理汇总了Java中org.eclipse.leshan.core.response.DiscoverResponse类的典型用法代码示例。如果您正苦于以下问题:Java DiscoverResponse类的具体用法?Java DiscoverResponse怎么用?Java DiscoverResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiscoverResponse类属于org.eclipse.leshan.core.response包,在下文中一共展示了DiscoverResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Override
public JsonElement serialize(LwM2mResponse src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject element = new JsonObject();
element.addProperty("status", src.getCode().toString());
if (typeOfSrc instanceof Class<?>) {
if (ReadResponse.class.isAssignableFrom((Class<?>) typeOfSrc)) {
element.add("content", context.serialize(((ReadResponse) src).getContent()));
}
else if (DiscoverResponse.class.isAssignableFrom((Class<?>) typeOfSrc)) {
element.add("objectLinks", context.serialize(((DiscoverResponse) src).getObjectLinks()));
}
}
return element;
}
示例2: serialize
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Override
public JsonElement serialize(LwM2mResponse src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject element = new JsonObject();
element.addProperty("status", src.getCode().toString());
element.addProperty("valid", src.isValid());
element.addProperty("success", src.isSuccess());
element.addProperty("failure", src.isFailure());
if (typeOfSrc instanceof Class<?>) {
if (ReadResponse.class.isAssignableFrom((Class<?>) typeOfSrc)) {
element.add("content", context.serialize(((ReadResponse) src).getContent()));
} else if (DiscoverResponse.class.isAssignableFrom((Class<?>) typeOfSrc)) {
element.add("objectLinks", context.serialize(((DiscoverResponse) src).getObjectLinks()));
}
}
return element;
}
示例3: can_discover_object
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void can_discover_object() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(2));
// verify result
assertEquals(CONTENT, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
Link[] payload = response.getObjectLinks();
assertArrayEquals(Link.parse("</2>, </2/0/0>, </2/0/1>, </2/0/2>, </2/0/3>".getBytes()), payload);
}
示例4: cant_discover_non_existent_object
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void cant_discover_non_existent_object() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(4));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
示例5: can_discover_object_instance
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void can_discover_object_instance() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(3, 0));
// verify result
assertEquals(CONTENT, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
Link[] payload = response.getObjectLinks();
assertArrayEquals(Link.parse("</3/0>".getBytes()), payload);
}
示例6: cant_discover_non_existent_instance
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void cant_discover_non_existent_instance() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(3, 1));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
示例7: can_discover_resource
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void can_discover_resource() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(3, 0, 0));
// verify result
assertEquals(CONTENT, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
Link[] payload = response.getObjectLinks();
assertArrayEquals(Link.parse("</3/0/0>".getBytes()), payload);
}
示例8: cant_discover_resource_of_non_existent_object
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void cant_discover_resource_of_non_existent_object() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(4, 0, 0));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
示例9: cant_discover_resource_of_non_existent_instance
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void cant_discover_resource_of_non_existent_instance() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(3, 1, 0));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
示例10: cant_discover_resource_of_non_existent_instance_and_resource
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void cant_discover_resource_of_non_existent_instance_and_resource() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(3, 1, 20));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
示例11: cant_discover_resource_of_non_existent_resource
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void cant_discover_resource_of_non_existent_resource() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(3, 0, 42));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
示例12: jSerialize
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
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;
}
示例13: ser_and_des_discover_response
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Test
public void ser_and_des_discover_response() throws Exception {
Link[] objs = new Link[2];
Map<String, Object> att = new HashMap<>();
att.put("ts", 12);
att.put("rt", "test");
objs[0] = new Link("/0/1024/2", att);
objs[1] = new Link("/0/2");
DiscoverResponse dr = DiscoverResponse.success(objs);
JsonObject obj = ResponseSerDes.jSerialize(dr);
LwM2mResponse dr2 = ResponseSerDes.deserialize(obj);
assertEquals(dr.toString(), dr2.toString());
}
示例14: discover
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
@Override
public synchronized DiscoverResponse discover(ServerIdentity identity, DiscoverRequest request) {
if (identity.isLwm2mBootstrapServer()) {
// discover is not supported for bootstrap
return DiscoverResponse.methodNotAllowed();
}
if (id == LwM2mId.SECURITY) {
return DiscoverResponse.notFound();
}
LwM2mPath path = request.getPath();
if (path.isObject()) {
// Manage discover on object
Link[] ObjectLinks = LinkFormatHelper.getObjectDescription(getObjectModel(), null);
return DiscoverResponse.success(ObjectLinks);
} else if (path.isObjectInstance()) {
// Manage discover on instance
if (!getAvailableInstanceIds().contains(path.getObjectInstanceId()))
return DiscoverResponse.notFound();
Link instanceLink = LinkFormatHelper.getInstanceDescription(getObjectModel(),
path.getObjectInstanceId(), null);
return DiscoverResponse.success(new Link[] { instanceLink });
} else if (path.isResource()) {
// Manage discover on resource
if (!getAvailableInstanceIds().contains(path.getObjectInstanceId()))
return DiscoverResponse.notFound();
ResourceModel resourceModel = getObjectModel().resources.get(path.getResourceId());
if (resourceModel == null)
return DiscoverResponse.notFound();
Link resourceLink = LinkFormatHelper.getResourceDescription(getObjectModel().id,
path.getObjectInstanceId(), resourceModel, null);
return DiscoverResponse.success(new Link[] { resourceLink });
}
return DiscoverResponse.badRequest(null);
}
示例15: discover
import org.eclipse.leshan.core.response.DiscoverResponse; //导入依赖的package包/类
DiscoverResponse discover(ServerIdentity identity, DiscoverRequest request);