本文整理汇总了Java中org.eclipse.leshan.core.request.WriteRequest.Mode类的典型用法代码示例。如果您正苦于以下问题:Java Mode类的具体用法?Java Mode怎么用?Java Mode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mode类属于org.eclipse.leshan.core.request.WriteRequest包,在下文中一共展示了Mode类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeOperation
import org.eclipse.leshan.core.request.WriteRequest.Mode; //导入依赖的package包/类
private void writeOperation(String path, Object value, ResourceModel rm){
try{
String[] path_ary = path.split("/");
if(path_ary.length == 5){
String epName = path_ary[1];
String target = path.substring(epName.length() + 1, path.length());
int rsID = Integer.parseInt(path_ary[4]);
JSONObject root = new JSONObject();
root.put("id", rsID);
root.put("value", value);
Registration registration = lwServer.getRegistrationService().getByEndpoint(epName);
ContentFormat contentFormat = ContentFormat.fromName("TLV");
// create & process request
LwM2mNode node = gson.fromJson(root.toString(), LwM2mNode.class);
WriteRequest request = new WriteRequest(Mode.REPLACE, contentFormat, target, node);
WriteResponse cResponse = lwServer.send(registration, request, 5000);
}
}catch(Exception exp){
exp.printStackTrace();
}
}
示例2: build_write_request
import org.eclipse.leshan.core.request.WriteRequest.Mode; //导入依赖的package包/类
@Test
public void build_write_request() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(),
reg.getEndpoint(), model, encoder);
WriteRequest request = new WriteRequest(Mode.UPDATE, 3, 0, LwM2mSingleResource.newStringResource(4, "value"));
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.POST, coapRequest.getCode());
assertEquals("127.0.0.1", coapRequest.getDestinationContext().getPeerAddress().getAddress().getHostAddress());
assertEquals(12354, coapRequest.getDestinationContext().getPeerAddress().getPort());
assertEquals(ContentFormat.TLV.getCode(), coapRequest.getOptions().getContentFormat());
assertNotNull(coapRequest.getPayload());
// assert it is encoded as array of resources TLV
Tlv[] tlvs = TlvDecoder.decode(ByteBuffer.wrap(coapRequest.getPayload()));
assertEquals(TlvType.RESOURCE_VALUE, tlvs[0].getType());
assertEquals("value", TlvDecoder.decodeString(tlvs[0].getValue()));
assertEquals("coap://127.0.0.1:12354/3/0", coapRequest.getURI());
}
示例3: can_write_object_instance
import org.eclipse.leshan.core.request.WriteRequest.Mode; //导入依赖的package包/类
public void can_write_object_instance(ContentFormat format) throws InterruptedException {
// write device timezone and offset
LwM2mResource utcOffset = LwM2mSingleResource.newStringResource(14, "+02");
LwM2mResource timeZone = LwM2mSingleResource.newStringResource(15, "Europe/Paris");
WriteResponse response = helper.server.send(helper.getCurrentRegistration(),
new WriteRequest(Mode.REPLACE, format, 3, 0, utcOffset, timeZone));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// read the timezone to check the value changed
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0));
LwM2mObjectInstance instance = (LwM2mObjectInstance) readResponse.getContent();
assertEquals(utcOffset, instance.getResource(14));
assertEquals(timeZone, instance.getResource(15));
}
示例4: doPut
import org.eclipse.leshan.core.request.WriteRequest.Mode; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String[] path = StringUtils.split(req.getPathInfo(), '/');
String clientEndpoint = path[0];
// at least /endpoint/objectId/instanceId
if (path.length < 3) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid path");
return;
}
try {
String target = StringUtils.removeStart(req.getPathInfo(), "/" + clientEndpoint);
Registration registration = server.getRegistrationService().getByEndpoint(clientEndpoint);
if (registration != null) {
// get content format
String contentFormatParam = req.getParameter(FORMAT_PARAM);
ContentFormat contentFormat = contentFormatParam != null
? ContentFormat.fromName(contentFormatParam.toUpperCase()) : null;
// create & process request
LwM2mNode node = extractLwM2mNode(target, req);
WriteRequest request = new WriteRequest(Mode.REPLACE, contentFormat, target, node);
WriteResponse cResponse = server.send(registration, request, TIMEOUT);
processDeviceResponse(req, resp, cResponse);
} else {
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
resp.getWriter().format("No registered client with id '%s'", clientEndpoint).flush();
}
} catch (RuntimeException | InterruptedException e) {
handleException(e, resp);
}
}
示例5: can_write_replacing_object_instance
import org.eclipse.leshan.core.request.WriteRequest.Mode; //导入依赖的package包/类
@Test
public void can_write_replacing_object_instance() throws InterruptedException {
// setup server object
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(1, 0, 3, 60));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// write server object
LwM2mResource lifetime = LwM2mSingleResource.newIntegerResource(1, 120);
LwM2mResource defaultMinPeriod = LwM2mSingleResource.newIntegerResource(2, 10);
LwM2mResource notificationStoring = LwM2mSingleResource.newBooleanResource(6, false);
LwM2mResource binding = LwM2mSingleResource.newStringResource(7, "U");
response = helper.server.send(helper.getCurrentRegistration(),
new WriteRequest(Mode.REPLACE, 1, 0, lifetime, defaultMinPeriod, notificationStoring, binding));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// read the values to check the value changed
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(1, 0));
LwM2mObjectInstance instance = (LwM2mObjectInstance) readResponse.getContent();
assertEquals(lifetime, instance.getResource(1));
assertEquals(defaultMinPeriod, instance.getResource(2));
assertEquals(notificationStoring, instance.getResource(6));
assertEquals(binding, instance.getResource(7));
assertNull(instance.getResource(3)); // removed not contained optional writable resource
}
示例6: cannot_write_replacing_incomplete_object_instance
import org.eclipse.leshan.core.request.WriteRequest.Mode; //导入依赖的package包/类
@Test
public void cannot_write_replacing_incomplete_object_instance() throws InterruptedException {
// write server object
LwM2mResource lifetime = LwM2mSingleResource.newIntegerResource(1, 120);
LwM2mResource defaultMinPeriod = LwM2mSingleResource.newIntegerResource(2, 10);
WriteResponse response = helper.server.send(helper.getCurrentRegistration(),
new WriteRequest(Mode.REPLACE, 1, 0, lifetime, defaultMinPeriod));
// verify result
assertEquals(ResponseCode.BAD_REQUEST, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
示例7: can_write_updating_object_instance
import org.eclipse.leshan.core.request.WriteRequest.Mode; //导入依赖的package包/类
@Test
public void can_write_updating_object_instance() throws InterruptedException {
// setup server object
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(1, 0, 3, 60));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// write server object
LwM2mResource lifetime = LwM2mSingleResource.newIntegerResource(1, 120);
LwM2mResource defaultMinPeriod = LwM2mSingleResource.newIntegerResource(2, 10);
response = helper.server.send(helper.getCurrentRegistration(),
new WriteRequest(Mode.UPDATE, 1, 0, lifetime, defaultMinPeriod));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// read the values to check the value changed
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(1, 0));
LwM2mObjectInstance instance = (LwM2mObjectInstance) readResponse.getContent();
assertEquals(lifetime, instance.getResource(1));
assertEquals(defaultMinPeriod, instance.getResource(2));
// no resources are removed when updating
assertNotNull(instance.getResource(3));
assertNotNull(instance.getResource(6));
assertNotNull(instance.getResource(7));
}
示例8: ser_and_des_write_request
import org.eclipse.leshan.core.request.WriteRequest.Mode; //导入依赖的package包/类
@Test
public void ser_and_des_write_request() throws Exception {
ser_and_des_are_equals(new WriteRequest(Mode.REPLACE, ContentFormat.TLV, 3, 0,
new LwM2mResource[] { LwM2mSingleResource.newStringResource(1, "value") }));
}