當前位置: 首頁>>代碼示例>>Java>>正文


Java BindingMode類代碼示例

本文整理匯總了Java中org.eclipse.leshan.core.request.BindingMode的典型用法代碼示例。如果您正苦於以下問題:Java BindingMode類的具體用法?Java BindingMode怎麽用?Java BindingMode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BindingMode類屬於org.eclipse.leshan.core.request包,在下文中一共展示了BindingMode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createX509CertClient

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
public void createX509CertClient(PrivateKey privatekey, Certificate[] trustedCertificates) {
    ObjectsInitializer initializer = new ObjectsInitializer();
    // TODO security instance with certificate info
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec(
            "coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(),
            12345));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));

    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
    // TODO we should read the config from the security object
    config.setIdentity(privatekey, clientX509CertChain, false);
    config.setTrustStore(trustedCertificates);

    CoapServer coapServer = new CoapServer();
    coapServer.addEndpoint(new CoapEndpoint(new DTLSConnector(config.build()), NetworkConfig.getStandard()));

    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:26,代碼來源:SecureIntegrationTestHelper.java

示例2: updateClient

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
/**
 * Returns an updated version of the client.
 * 
 * @param client the registered client
 * @return the updated client
 */
public Client updateClient(Client client) {
    InetAddress address = this.address != null ? this.address : client.getAddress();
    int port = this.port != null ? this.port : client.getPort();
    LinkObject[] linkObject = this.objectLinks != null ? this.objectLinks : client.getObjectLinks();
    long lifeTimeInSec = this.lifeTimeInSec != null ? this.lifeTimeInSec : client.getLifeTimeInSec();
    BindingMode bindingMode = this.bindingMode != null ? this.bindingMode : client.getBindingMode();
    String smsNumber = this.smsNumber != null ? this.smsNumber : client.getSmsNumber();

    // this needs to be done in any case, even if no properties have changed, in order
    // to extend the client registration's time-to-live period ...
    Date lastUpdate = new Date();

    Client.Builder builder = new Client.Builder(client.getRegistrationId(), client.getEndpoint(), address, port,
            client.getRegistrationEndpointAddress());

    builder.lwM2mVersion(client.getLwM2mVersion()).lifeTimeInSec(lifeTimeInSec).smsNumber(smsNumber)
            .bindingMode(bindingMode).objectLinks(linkObject).registrationDate(client.getRegistrationDate())
            .lastUpdate(lastUpdate).additionalRegistrationAttributes(client.getAdditionalRegistrationAttributes());

    return builder.build();

}
 
開發者ID:iotoasis,項目名稱:SI,代碼行數:29,代碼來源:ClientUpdate.java

示例3: update

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
/**
 * Returns an updated version of the registration.
 * 
 * @param registration the registration to update
 * @return the updated registration
 */
public Registration update(Registration registration) {
    Identity identity = this.identity != null ? this.identity : registration.getIdentity();
    Link[] linkObject = this.objectLinks != null ? this.objectLinks : registration.getObjectLinks();
    long lifeTimeInSec = this.lifeTimeInSec != null ? this.lifeTimeInSec : registration.getLifeTimeInSec();
    BindingMode bindingMode = this.bindingMode != null ? this.bindingMode : registration.getBindingMode();
    String smsNumber = this.smsNumber != null ? this.smsNumber : registration.getSmsNumber();

    // this needs to be done in any case, even if no properties have changed, in order
    // to extend the client registration time-to-live period ...
    Date lastUpdate = new Date();

    Registration.Builder builder = new Registration.Builder(registration.getId(), registration.getEndpoint(),
            identity, registration.getRegistrationEndpointAddress());

    builder.lwM2mVersion(registration.getLwM2mVersion()).lifeTimeInSec(lifeTimeInSec).smsNumber(smsNumber)
            .bindingMode(bindingMode).objectLinks(linkObject).registrationDate(registration.getRegistrationDate())
            .lastUpdate(lastUpdate)
            .additionalRegistrationAttributes(registration.getAdditionalRegistrationAttributes());

    return builder.build();

}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:29,代碼來源:RegistrationUpdate.java

示例4: createClient

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
public void createClient() {
    // Create objects Enabler
    ObjectsInitializer initializer = new ObjectsInitializer(new LwM2mModel(createObjectModels()));
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec(
            "coap://" + server.getUnsecuredAddress().getHostString() + ":" + server.getUnsecuredAddress().getPort(),
            12345));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U") {
        @Override
        public ExecuteResponse execute(int resourceid, String params) {
            if (resourceid == 4) {
                return ExecuteResponse.success();
            } else {
                return super.execute(resourceid, params);
            }
        }
    });
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.addAll(initializer.create(2, 2000));

    // Build Client
    LeshanClientBuilder builder = new LeshanClientBuilder(currentEndpointIdentifier.get());
    builder.setObjects(objects);
    client = builder.build();
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:26,代碼來源:IntegrationTestHelper.java

示例5: sync_send_without_acknowleged

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
@Test
public void sync_send_without_acknowleged() throws Exception {
    // Register client
    LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
    client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null,
            Link.parse("</1>,</2>,</3>".getBytes()), null));
    client.expectResponse().go();
    helper.waitForRegistration(1);

    // Send read
    Future<ReadResponse> future = Executors.newSingleThreadExecutor().submit(new Callable<ReadResponse>() {
        @Override
        public ReadResponse call() throws Exception {
            // send a request with 3 seconds timeout
            return helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000);
        }
    });
    // Request should timedout in ~1s we don't send ACK
    ReadResponse response = future.get(1500, TimeUnit.MILLISECONDS);
    Assert.assertNull("we should timeout", response);
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:22,代碼來源:FailingTest.java

示例6: async_send_without_acknowleged

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
@Test
public void async_send_without_acknowleged() throws Exception {
    // register client
    LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
    client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null,
            Link.parse("</1>,</2>,</3>".getBytes()), null));
    client.expectResponse().go();
    helper.waitForRegistration(1);

    // send read
    Callback<ReadResponse> callback = new Callback<ReadResponse>();
    helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000l, callback, callback);

    // Request should timedout in ~1s we don't send ACK
    callback.waitForResponse(1500);
    Assert.assertTrue("we should timeout", callback.getException() instanceof TimeoutException);

}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:19,代碼來源:FailingTest.java

示例7: async_send_with_acknowleged_request_without_response

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
@Test
public void async_send_with_acknowleged_request_without_response() throws Exception {
    // register client
    LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
    client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null,
            Link.parse("</1>,</2>,</3>".getBytes()), null));
    client.expectResponse().go();
    helper.waitForRegistration(1);

    // send read
    Callback<ReadResponse> callback = new Callback<ReadResponse>();
    helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000l, callback, callback);

    // Acknowledge the response
    client.expectRequest().storeMID("R").go();
    client.sendEmpty(Type.ACK).loadMID("R").go();

    // Request should timedout in ~3s as we send a ack
    Thread.sleep(1500);
    Assert.assertTrue("we should still wait for response", callback.getException() == null);
    callback.waitForResponse(2000);
    Assert.assertTrue("we should timeout", callback.getException() instanceof TimeoutException);
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:24,代碼來源:FailingTest.java

示例8: createPSKClient

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
public void createPSKClient() {
    ObjectsInitializer initializer = new ObjectsInitializer();
    initializer.setInstancesForObject(LwM2mId.SECURITY,
            Security.psk(
                    "coaps://" + server.getSecuredAddress().getHostString() + ":"
                            + server.getSecuredAddress().getPort(),
                    12345, GOOD_PSK_ID.getBytes(StandardCharsets.UTF_8), GOOD_PSK_KEY));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));

    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:19,代碼來源:SecureIntegrationTestHelper.java

示例9: ser_and_des_are_equals

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
@Test
public void ser_and_des_are_equals() throws Exception {
    Link[] objs = new Link[2];
    Map<String, Object> att = new HashMap<>();
    att.put("ts", 12);
    att.put("rt", "test");
    att.put("hb", null);
    objs[0] = new Link("/0/1024/2", att);
    objs[1] = new Link("/0/2");

    RegistrationUpdate ru = new RegistrationUpdate("myId",
            Identity.unsecure(Inet4Address.getByName("127.0.0.1"), LwM2m.DEFAULT_COAP_PORT), 60000l, null,
            BindingMode.U, objs);

    byte[] ser = RegistrationUpdateSerDes.bSerialize(ru);
    RegistrationUpdate ru2 = RegistrationUpdateSerDes.deserialize(ser);

    assertEquals(ru, ru2);
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:20,代碼來源:RegistrationUpdateSerDesTest.java

示例10: visit

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
@Override
public void visit(UpdateRequest request) {
    coapRequest = Request.newPost();
    buildRequestSettings();
    coapRequest.getOptions().setUriPath(request.getRegistrationId());

    Long lifetime = request.getLifeTimeInSec();
    if (lifetime != null)
        coapRequest.getOptions().addUriQuery("lt=" + lifetime);

    String smsNumber = request.getSmsNumber();
    if (smsNumber != null)
        coapRequest.getOptions().addUriQuery("sms=" + smsNumber);

    BindingMode bindingMode = request.getBindingMode();
    if (bindingMode != null)
        coapRequest.getOptions().addUriQuery("b=" + bindingMode.toString());

    Link[] linkObjects = request.getObjectLinks();
    if (linkObjects != null) {
        coapRequest.getOptions().setContentFormat(ContentFormat.LINK.getCode());
        coapRequest.setPayload(Link.serialize(linkObjects));
    }
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:25,代碼來源:CoapRequestBuilder.java

示例11: ClientUpdate

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
public ClientUpdate(String registrationId, InetAddress address, Integer port, Long lifeTimeInSec, String smsNumber,
        BindingMode bindingMode, LinkObject[] objectLinks) {
    Validate.notNull(registrationId);
    Validate.notNull(address);
    Validate.notNull(port);
    this.registrationId = registrationId;
    this.address = address;
    this.port = port;

    this.lifeTimeInSec = lifeTimeInSec;
    this.smsNumber = smsNumber;
    this.bindingMode = bindingMode;
    this.objectLinks = objectLinks;
}
 
開發者ID:iotoasis,項目名稱:SI,代碼行數:15,代碼來源:ClientUpdate.java

示例12: handleUpdate

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
private void handleUpdate(CoapExchange exchange, Request request, String registrationId) {
    // Get identity
    Identity sender = extractIdentity(request.getSourceContext());

    // Create LwM2m request from CoAP request
    Long lifetime = null;
    String smsNumber = null;
    BindingMode binding = null;
    Link[] objectLinks = null;
    for (String param : request.getOptions().getUriQuery()) {
        if (param.startsWith(QUERY_PARAM_LIFETIME)) {
            lifetime = Long.valueOf(param.substring(3));
        } else if (param.startsWith(QUERY_PARAM_SMS)) {
            smsNumber = param.substring(4);
        } else if (param.startsWith(QUERY_PARAM_BINDING_MODE)) {
            binding = BindingMode.valueOf(param.substring(2));
        }
    }
    if (request.getPayload() != null && request.getPayload().length > 0) {
        objectLinks = Link.parse(request.getPayload());
    }
    UpdateRequest updateRequest = new UpdateRequest(registrationId, lifetime, smsNumber, binding, objectLinks);

    // Handle request
    final SendableResponse<UpdateResponse> sendableResponse = registrationHandler.update(sender, updateRequest);
    UpdateResponse updateResponse = sendableResponse.getResponse();

    // Create CoAP Response from LwM2m request
    exchange.respond(toCoapResponseCode(updateResponse.getCode()), updateResponse.getErrorMessage());
    sendableResponse.sent();
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:32,代碼來源:RegisterResource.java

示例13: RegistrationUpdate

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
public RegistrationUpdate(String registrationId, Identity identity, Long lifeTimeInSec, String smsNumber,
        BindingMode bindingMode, Link[] objectLinks) {
    Validate.notNull(registrationId);
    Validate.notNull(identity);
    this.registrationId = registrationId;
    this.identity = identity;
    this.lifeTimeInSec = lifeTimeInSec;
    this.smsNumber = smsNumber;
    this.bindingMode = bindingMode;
    this.objectLinks = objectLinks;
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:12,代碼來源:RegistrationUpdate.java

示例14: sync_send_with_acknowleged_request_without_response

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
@Test
public void sync_send_with_acknowleged_request_without_response() throws Exception {
    // Register client
    LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
    client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null,
            Link.parse("</1>,</2>,</3>".getBytes()), null));
    client.expectResponse().go();
    helper.waitForRegistration(1);

    // Send read
    Future<ReadResponse> future = Executors.newSingleThreadExecutor().submit(new Callable<ReadResponse>() {
        @Override
        public ReadResponse call() throws Exception {
            // send a request with 3 seconds timeout
            return helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000);
        }
    });

    // Acknowledge the response
    client.expectRequest().storeMID("R").go();
    client.sendEmpty(Type.ACK).loadMID("R").go();

    // Request should timedout in ~3s as we send the ACK
    Thread.sleep(1500);
    Assert.assertFalse("we should still wait for response", future.isDone());
    ReadResponse response = future.get(2000, TimeUnit.MILLISECONDS);
    Assert.assertNull("we should timeout", response);
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:29,代碼來源:FailingTest.java

示例15: createRPKClient

import org.eclipse.leshan.core.request.BindingMode; //導入依賴的package包/類
public void createRPKClient() {
    ObjectsInitializer initializer = new ObjectsInitializer();
    initializer.setInstancesForObject(LwM2mId.SECURITY,
            Security.rpk(
                    "coaps://" + server.getSecuredAddress().getHostString() + ":"
                            + server.getSecuredAddress().getPort(),
                    12345, clientPublicKey.getEncoded(), clientPrivateKey.getEncoded(),
                    serverPublicKey.getEncoded()));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.add(initializer.create(2));

    InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
    DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
    // TODO we should read the config from the security object
    // TODO no way to provide a dynamic config with the current scandium API
    config.setIdentity(clientPrivateKey, clientPublicKey);

    CoapServer coapServer = new CoapServer();
    coapServer.addEndpoint(new CoapEndpoint(new DTLSConnector(config.build()), NetworkConfig.getStandard()));

    LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
    builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
    builder.setObjects(objects);
    client = builder.build();
}
 
開發者ID:eclipse,項目名稱:leshan,代碼行數:28,代碼來源:SecureIntegrationTestHelper.java


注:本文中的org.eclipse.leshan.core.request.BindingMode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。