当前位置: 首页>>代码示例>>Java>>正文


Java CoapServer类代码示例

本文整理汇总了Java中org.eclipse.californium.core.CoapServer的典型用法代码示例。如果您正苦于以下问题:Java CoapServer类的具体用法?Java CoapServer怎么用?Java CoapServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CoapServer类属于org.eclipse.californium.core包,在下文中一共展示了CoapServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createX509CertClient

import org.eclipse.californium.core.CoapServer; //导入依赖的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: addResources

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
private void addResources(CoapServer coapServer)
{
	coapServer.add(new ObservableResource("AndroidCoap")); // Add the observable resource ro the COAP server. 
	DIMXMLResource bloodPreDIMRes = new DIMXMLResource(MainActivity.this,
			"bloodPressure", "mds-attributes/blood-pressure.xml");
	DIMXMLResource spo2DIMRes = new DIMXMLResource(MainActivity.this,
			"Spo2", "mds-attributes/pulse-oximeter-NONIN.xml");
	DIMXMLResource bodyCompDIMRes = new DIMXMLResource(MainActivity.this,
			"BodyCompositionMonitor", "mds-attributes/body-composition-monitor.xml");
	DIMXMLResource cardioVascularDIMRes = new DIMXMLResource(MainActivity.this,
			"cardiovascularmonitor", "mds-attributes/cardio-vascular.xml");
	DIMXMLResource medicalMonitorDIMRes = new DIMXMLResource(MainActivity.this,
			"medicationmonitor", "mds-attributes/medication-monitor.xml");
	DIMXMLResource strengthfitnessEquiDIMRes= new DIMXMLResource(MainActivity.this,
			"strenghtfitnessmonitor", "mds-attributes/strength-fitness-equipment.xml");
	
	coapServer.add(bloodPreDIMRes);
	coapServer.add(spo2DIMRes);
	coapServer.add(bodyCompDIMRes);
	coapServer.add(cardioVascularDIMRes);
	coapServer.add(medicalMonitorDIMRes);
	coapServer.add(strengthfitnessEquiDIMRes);
}
 
开发者ID:AINLAB,项目名称:OHP-M2M,代码行数:24,代码来源:MainActivity.java

示例3: init

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
public List<Stage.ConfigIssue> init(Stage.Context context) {
  List<Stage.ConfigIssue> issues = new ArrayList<>();
  NetworkConfig networkConfig = NetworkConfig.createStandardWithoutFile();
  networkConfig.set(NetworkConfig.Keys.DEDUPLICATOR, NetworkConfig.Keys.NO_DEDUPLICATOR);
  networkConfig.set(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT, coAPServerConfigs.maxConcurrentRequests);
  networkConfig.set(NetworkConfig.Keys.NETWORK_STAGE_RECEIVER_THREAD_COUNT, coAPServerConfigs.maxConcurrentRequests);
  if (coAPServerConfigs.networkConfigs != null) {
    for (String key: coAPServerConfigs.networkConfigs.keySet()) {
      networkConfig.set(key, coAPServerConfigs.networkConfigs.get(key));
    }
  }
  coapServer = new CoapServer(networkConfig, coAPServerConfigs.port);
  coapReceiverResource = new CoapReceiverResource(context, receiver, errorQueue);
  coapServer.add(coapReceiverResource);
  coapServer.start();
  return issues;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:18,代码来源:CoapReceiverServer.java

示例4: setUp

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  int port =  TestHttpClientTarget.getFreePort();
  coapServer = new CoapServer(NetworkConfig.createStandardWithoutFile(), port);
  coapServer.add(new CoapResource("test") {
    @Override
    public void handlePOST(CoapExchange exchange) {
      serverRequested = true;
      if (returnErrorResponse) {
        exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
        return;
      }
      requestPayload = new String(exchange.getRequestPayload());
      exchange.respond(CoAP.ResponseCode.VALID);
    }
  });
  resourceURl = "coap://localhost:" + port + "/test";
  coapServer.start();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:20,代码来源:TestCoapClientTarget.java

示例5: HTTPCoAPCrossProxy

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
public HTTPCoAPCrossProxy() throws IOException {
	ForwardingResource coap2coap = new ProxyCoapClientResource("coap2coap");
	ForwardingResource coap2http = new ProxyHttpClientResource("coap2http");
	
	// Create CoAP Server on PORT with proxy resources form CoAP to CoAP and HTTP
	targetServerA = new CoapServer(PORT);
	targetServerA.add(coap2coap);
	targetServerA.add(coap2http);
	//targetServerA.add(new TargetResource("target"));
	targetServerA.start();
	
	ProxyHttpServer httpServer = new ProxyHttpServer(8080);
	
	httpServer.setProxyCoapResolver(new DirectProxyCoAPResolver(coap2coap));
	
	System.out.println("CoAP resource \"target\" available over HTTP at: http://localhost:8080/proxy/coap://localhost:PORT/target");
}
 
开发者ID:telecombretagne,项目名称:LoRaFABIAN_OLD,代码行数:18,代码来源:HTTPCoAPCrossProxy.java

示例6: main

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
public static void main(String[] args) {

        // binds on UDP port 5683
        CoapServer server = new CoapServer();

        // "hello"
        server.add(new HelloResource());

        // "subpath/Another"
        CoapResource path = new CoapResource("subpath");
        path.add(new AnotherResource());
        server.add(path);

        // "removeme!, "time", "writeme!"
        server.add(new RemovableResource(), new TimeResource(), new WritableResource());

        server.start();
    }
 
开发者ID:jvermillard,项目名称:hands-on-coap,代码行数:19,代码来源:HelloWorld2.java

示例7: setUp

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
@Before
  public void setUp() throws Exception {
      // start the server
      server = Main.startServer();
      // create the client
      Client c = ClientBuilder.newClient();

      // create a local CoAP server
      CoapServer coap_server = new CoapServer();
      coap_server.add(new HelloWorldResource());
//      coap_server.addResource(new TimeResource());
      coap_server.start();


      target = c.target(Main.BASE_URI);
  }
 
开发者ID:sieben,项目名称:gateway-calipso,代码行数:17,代码来源:ServersTest.java

示例8: init

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
@PostConstruct
public void init() throws UnknownHostException {
  log.info("Starting CoAP transport...");
  log.info("Lookup CoAP transport adaptor {}", adaptorName);
  // this.adaptor = (CoapTransportAdaptor) appContext.getBean(adaptorName);
  log.info("Starting CoAP transport server");
  this.server = new CoapServer();
  createResources();
  InetAddress addr = InetAddress.getByName(host);
  InetSocketAddress sockAddr = new InetSocketAddress(addr, port);
  server.addEndpoint(new CoapEndpoint(sockAddr));
  server.start();
  log.info("CoAP transport started!");
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:15,代码来源:CoapTransportService.java

示例9: CoAPServer

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
public CoAPServer(int port, RESTHandler root)
{
  server = new CoapServer(port) {
    @Override
    protected Resource createRoot()
    {
      return new CoAPRESTResource(root);
    }
  };
}
 
开发者ID:thingweb,项目名称:thingweb-directory,代码行数:11,代码来源:CoAPServer.java

示例10: init

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
@PostConstruct
public void init() throws UnknownHostException {
    log.info("Starting CoAP transport...");
    log.info("Lookup CoAP transport adaptor {}", adaptorName);
    this.adaptor = (CoapTransportAdaptor) appContext.getBean(adaptorName);
    log.info("Starting CoAP transport server");
    this.server = new CoapServer();
    createResources();
    InetAddress addr = InetAddress.getByName(host);
    InetSocketAddress sockAddr = new InetSocketAddress(addr, port);
    server.addEndpoint(new CoapEndpoint(sockAddr));
    server.start();
    log.info("CoAP transport started!");
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:15,代码来源:CoapTransportService.java

示例11: doStart

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
    super.doStart();

    RestConfiguration config = getCamelContext().getRestConfiguration("coap", true);
    // configure additional options on coap configuration
    if (config.getComponentProperties() != null && !config.getComponentProperties().isEmpty()) {
        setProperties(this, config.getComponentProperties());
    }
    defaultServer = getServer(config.getPort());
    
    for (CoapServer s : servers.values()) {
        s.start();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:CoAPComponent.java

示例12: doStop

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
@Override
protected void doStop() throws Exception {
    for (CoapServer s : servers.values()) {
        s.stop();
    }
    super.doStop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:CoAPComponent.java

示例13: LeshanBootstrapServer

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
public LeshanBootstrapServer(CoapEndpoint unsecuredEndpoint, CoapEndpoint securedEndpoint, BootstrapStore bsStore,
        BootstrapSecurityStore bsSecurityStore, BootstrapSessionManager bsSessionManager, LwM2mModel model,
        NetworkConfig coapConfig) {

    Validate.notNull(bsStore, "bootstrap store must not be null");
    Validate.notNull(bsSessionManager, "session manager must not be null");
    Validate.notNull(model, "model must not be null");
    Validate.notNull(coapConfig, "coapConfig must not be null");

    this.bsStore = bsStore;
    this.bsSecurityStore = bsSecurityStore;

    // init CoAP server
    coapServer = new CoapServer(coapConfig);
    this.unsecuredEndpoint = unsecuredEndpoint;
    if (unsecuredEndpoint != null)
        coapServer.addEndpoint(unsecuredEndpoint);

    // init DTLS server
    this.securedEndpoint = securedEndpoint;
    if (securedEndpoint != null)
        coapServer.addEndpoint(securedEndpoint);

    // create request sender
    LwM2mBootstrapRequestSender requestSender = new CaliforniumLwM2mBootstrapRequestSender(securedEndpoint,
            unsecuredEndpoint, model);

    BootstrapResource bsResource = new BootstrapResource(
            new BootstrapHandler(bsStore, requestSender, bsSessionManager));
    coapServer.add(bsResource);
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:32,代码来源:LeshanBootstrapServer.java

示例14: createRPKClient

import org.eclipse.californium.core.CoapServer; //导入依赖的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

示例15: contextInitialized

import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
@Override
    public void contextInitialized(ServletContextEvent sce) {
        // start the thread

        System.out.println("intializing CoAP server");
        System.out.println("context-path: " + sce.getServletContext().getContextPath());
        System.out.println("real-path: " + sce.getServletContext().getRealPath(File.separator));

        server = new CoapServer(5700);//deafult is 5683
        server.setExecutor(Executors.newScheduledThreadPool(4));

        //test
//        server.add(new HelloWorldResource("hello"));

        //Standard Operations        
        server.add(new CoapR01_ContextRegistration("ngsi9/registerContext"));
        server.add(new CoapR02_Discovery("ngsi9/discoverContextAvailability"));
        server.add(new CoapR03_AvailabilitySubscription("ngsi9/subscribeContextAvailability"));
        server.add(new CoapR04_AvailabilitySubscriptionUpdate("ngsi9/updateContextAvailabilitySubscription"));
        server.add(new CoapR05_AvailabilitySubscriptionDeletion("ngsi9/unsubscribeContextAvailability"));

        //Convenience Operations
//        server.add(new CoapRC01_Individual("ngsi9/contextEntities/{EntityID}"));       
        
        server.start();

    }
 
开发者ID:UniSurreyIoT,项目名称:fiware-iot-discovery-ngsi9,代码行数:28,代码来源:CoapServerContextListener.java


注:本文中的org.eclipse.californium.core.CoapServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。