Search in sources :

Example 6 with LeshanServerBuilder

use of org.eclipse.leshan.server.californium.LeshanServerBuilder in project leshan by eclipse.

the class LeshanClusterServer method createAndStartServer.

public static void createAndStartServer(String clusterInstanceId, String localAddress, int localPort, String secureLocalAddress, int secureLocalPort, String modelsFolderPath, String redisUrl) throws Exception {
    // Create Redis connector.
    // TODO: support sentinel pool and make pool configurable
    Pool<Jedis> jedis = new JedisPool(new URI(redisUrl));
    // Prepare LWM2M server.
    LeshanServerBuilder builder = new LeshanServerBuilder();
    builder.setLocalAddress(localAddress, localPort);
    builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
    DefaultLwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();
    builder.setDecoder(decoder);
    builder.setCoapConfig(NetworkConfig.getStandard());
    List<ObjectModel> models = ObjectLoader.loadDefault();
    if (modelsFolderPath != null) {
        models.addAll(ObjectLoader.loadObjectsFromDir(new File(modelsFolderPath)));
    }
    LwM2mModelProvider modelProvider = new StaticModelProvider(models);
    builder.setObjectModelProvider(modelProvider);
    RedisRegistrationStore registrationStore = new RedisRegistrationStore(jedis);
    builder.setRegistrationStore(registrationStore);
    // TODO add support of public and private server key
    builder.setSecurityStore(new RedisSecurityStore(jedis));
    // Create and start LWM2M server
    LeshanServer lwServer = builder.build();
    // Create Clustering support
    RedisTokenHandler tokenHandler = new RedisTokenHandler(jedis, clusterInstanceId);
    new RedisRequestResponseHandler(jedis, lwServer, lwServer.getRegistrationService(), tokenHandler, lwServer.getObservationService());
    lwServer.getRegistrationService().addListener(tokenHandler);
    lwServer.getRegistrationService().addListener(new RedisRegistrationEventPublisher(jedis));
    // Start Jetty & Leshan
    lwServer.start();
}
Also used : StaticModelProvider(org.eclipse.leshan.server.model.StaticModelProvider) ObjectModel(org.eclipse.leshan.core.model.ObjectModel) URI(java.net.URI) Jedis(redis.clients.jedis.Jedis) LeshanServerBuilder(org.eclipse.leshan.server.californium.LeshanServerBuilder) DefaultLwM2mNodeDecoder(org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder) LwM2mModelProvider(org.eclipse.leshan.server.model.LwM2mModelProvider) LeshanServer(org.eclipse.leshan.server.californium.impl.LeshanServer) JedisPool(redis.clients.jedis.JedisPool) File(java.io.File)

Example 7 with LeshanServerBuilder

use of org.eclipse.leshan.server.californium.LeshanServerBuilder in project leshan by eclipse.

the class RedisSecureIntegrationTestHelper method createServer.

@Override
public void createServer() {
    LeshanServerBuilder builder = new LeshanServerBuilder();
    StaticModelProvider modelProvider = new StaticModelProvider(createObjectModels());
    builder.setObjectModelProvider(modelProvider);
    DefaultLwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();
    builder.setDecoder(decoder);
    builder.setLocalAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
    builder.setLocalSecureAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
    // Create redis store
    String redisURI = System.getenv("REDIS_URI");
    if (redisURI == null)
        redisURI = "";
    Pool<Jedis> jedis = new JedisPool(redisURI);
    builder.setRegistrationStore(new RedisRegistrationStore(jedis));
    builder.setSecurityStore(new RedisSecurityStore(jedis));
    // Build server !
    server = builder.build();
    // monitor client registration
    resetLatch();
    server.getRegistrationService().addListener(new RegistrationListener() {

        @Override
        public void updated(RegistrationUpdate update, Registration updatedRegistration, Registration previousRegistration) {
            if (updatedRegistration.getEndpoint().equals(getCurrentEndpoint())) {
                updateLatch.countDown();
            }
        }

        @Override
        public void unregistered(Registration registration, Collection<Observation> observations, boolean expired, Registration newReg) {
            if (registration.getEndpoint().equals(getCurrentEndpoint())) {
                deregisterLatch.countDown();
            }
        }

        @Override
        public void registered(Registration registration, Registration previousReg, Collection<Observation> previousObsersations) {
            if (registration.getEndpoint().equals(getCurrentEndpoint())) {
                last_registration = registration;
                registerLatch.countDown();
            }
        }
    });
}
Also used : StaticModelProvider(org.eclipse.leshan.server.model.StaticModelProvider) RegistrationListener(org.eclipse.leshan.server.registration.RegistrationListener) InetSocketAddress(java.net.InetSocketAddress) Jedis(redis.clients.jedis.Jedis) RedisSecurityStore(org.eclipse.leshan.server.cluster.RedisSecurityStore) LeshanServerBuilder(org.eclipse.leshan.server.californium.LeshanServerBuilder) DefaultLwM2mNodeDecoder(org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder) Registration(org.eclipse.leshan.server.registration.Registration) RedisRegistrationStore(org.eclipse.leshan.server.cluster.RedisRegistrationStore) Observation(org.eclipse.leshan.core.observation.Observation) JedisPool(redis.clients.jedis.JedisPool) RegistrationUpdate(org.eclipse.leshan.server.registration.RegistrationUpdate)

Example 8 with LeshanServerBuilder

use of org.eclipse.leshan.server.californium.LeshanServerBuilder in project leshan by eclipse.

the class SecureIntegrationTestHelper method createServerWithX509Cert.

public void createServerWithX509Cert(Certificate[] trustedCertificates) {
    LeshanServerBuilder builder = new LeshanServerBuilder();
    builder.setLocalAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
    builder.setLocalSecureAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
    builder.setPrivateKey(serverPrivateKeyFromCert);
    builder.setCertificateChain(serverX509CertChain);
    builder.setTrustedCertificates(trustedCertificates);
    builder.setSecurityStore(new InMemorySecurityStore());
    server = builder.build();
    // monitor client registration
    setupRegistrationMonitoring();
}
Also used : LeshanServerBuilder(org.eclipse.leshan.server.californium.LeshanServerBuilder) InMemorySecurityStore(org.eclipse.leshan.server.impl.InMemorySecurityStore) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

LeshanServerBuilder (org.eclipse.leshan.server.californium.LeshanServerBuilder)8 InetSocketAddress (java.net.InetSocketAddress)5 StaticModelProvider (org.eclipse.leshan.server.model.StaticModelProvider)5 DefaultLwM2mNodeDecoder (org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder)4 InMemorySecurityStore (org.eclipse.leshan.server.impl.InMemorySecurityStore)4 Jedis (redis.clients.jedis.Jedis)4 JedisPool (redis.clients.jedis.JedisPool)4 RedisRegistrationStore (org.eclipse.leshan.server.cluster.RedisRegistrationStore)3 File (java.io.File)2 URI (java.net.URI)2 ObjectModel (org.eclipse.leshan.core.model.ObjectModel)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 AlgorithmParameters (java.security.AlgorithmParameters)1 Key (java.security.Key)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PrivateKey (java.security.PrivateKey)1