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


Java CoapEndpoint类代码示例

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


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

示例1: dtlsPSKRequest

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
public static Response dtlsPSKRequest(String uri, String method, byte[] payload, int contentFormat, String pskIdentity, byte[] pskKey) throws Exception {

		Request request = Utils.newRequest(method);
		request.setURI(uri);
		request.setPayload(payload);
		request.getOptions().setContentFormat(contentFormat);

		DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0));
		builder.setPskStore(new StaticPskStore(pskIdentity, pskKey));
		builder.setSupportedCipherSuites(new CipherSuite[] {CipherSuite.TLS_PSK_WITH_AES_128_CCM_8});

		DTLSConnector dtlsconnector = new DTLSConnector(builder.build(), null);

		NetworkConfig nc = NetworkConfig.getStandard().setInt("COAP_SECURE_PORT", 15686);

		dtlsEndpoint = new CoapEndpoint(dtlsconnector, nc);
		dtlsEndpoint.start();

		// execute request
		request.send(dtlsEndpoint);
		Response response = request.waitForResponse();
		
		return response;
	}
 
开发者ID:erwah,项目名称:acetest,代码行数:25,代码来源:DTLSUtils.java

示例2: createX509CertClient

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

示例3: CoAPSAuthorizationServer

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
public CoAPSAuthorizationServer() throws Exception {
   
      add(new TokenResource());
      add(new IntrospectResource());

   InMemoryPskStore pskStore = new InMemoryPskStore();
   pskStore.setKey(config.getPskIdentity(), config.getPskKey().getBytes());

DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(config.getCoapsPort()));
builder.setClientAuthenticationRequired(true);
builder.setPskStore(pskStore);

DTLSConnector connector = new DTLSConnector(builder.build(), null);

  	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
  		// only binds to IPv4 addresses and localhost
	if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
		@SuppressWarnings("static-access")
		CoapEndpoint endpoint = new CoapEndpoint(connector, new NetworkConfig().getStandard()); 
		addEndpoint(endpoint);
		EndpointManager.getEndpointManager().setDefaultSecureEndpoint(endpoint);
	}
}
  }
 
开发者ID:erwah,项目名称:acetest,代码行数:25,代码来源:CoAPSAuthorizationServer.java

示例4: DtlsPSKServer

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
public DtlsPSKServer() throws Exception {
    
       add(new TemperatureResource());
    
	DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(config.getCoapsPort()));
	builder.setClientAuthenticationRequired(true);

	// use the global in memory psk key store thats populated using the access tokens from the global config object
	builder.setPskStore(config.getPskStorage());
	
	DTLSConnector connector = new DTLSConnector(builder.build(), null);

   	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
   		// only binds to IPv4 addresses and localhost
		if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
			@SuppressWarnings("static-access")
			CoapEndpoint endpoint = new CoapEndpoint(connector, new NetworkConfig().getStandard()); 
			addEndpoint(endpoint);
			EndpointManager.getEndpointManager().setDefaultSecureEndpoint(endpoint);
		}
	}
	
}
 
开发者ID:erwah,项目名称:acetest,代码行数:24,代码来源:DtlsPSKServer.java

示例5: register_with_invalid_request

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
@Test
public void register_with_invalid_request() throws InterruptedException, IOException {
    // Check registration
    helper.assertClientNotRegisterered();

    // create a register request without the list of supported object
    Request coapRequest = new Request(Code.POST);
    coapRequest.setDestinationContext(new AddressEndpointContext(helper.server.getUnsecuredAddress()));
    coapRequest.getOptions().setContentFormat(ContentFormat.LINK.getCode());
    coapRequest.getOptions().addUriPath("rd");
    coapRequest.getOptions().addUriQuery("ep=" + helper.currentEndpointIdentifier);

    // send request
    CoapEndpoint coapEndpoint = new CoapEndpoint(new InetSocketAddress(0));
    coapEndpoint.start();
    coapEndpoint.sendRequest(coapRequest);

    // check response
    Response response = coapRequest.waitForResponse(1000);
    assertEquals(response.getCode(), org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST);
    coapEndpoint.stop();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:23,代码来源:RegistrationTest.java

示例6: init

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

示例7: addEndpoints

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
/**
 * Add individual endpoints listening on default CoAP port on all ddresses of all network interfaces.
 */
private void addEndpoints() {
	int coapPort = NetworkConfig.getStandard().getInt(NetworkConfig.Keys.COAP_PORT);

	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
		InetSocketAddress bindToAddress = new InetSocketAddress(addr, coapPort);
		addEndpoint(new CoapEndpoint(bindToAddress));
	}
}
 
开发者ID:beduino-project,项目名称:dcaf-java,代码行数:12,代码来源:AllInterfacesCoapServer.java

示例8: init

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

示例9: CoapServer

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
/**
 * Constructs a server with the specified configuration that listens to the
 * specified ports after method {@link #start()} is called.
 *
 * @param config the configuration, if <code>null</code> the configuration returned by
 * {@link NetworkConfig#getStandard()} is used.
 * @param ports the ports to bind to
 */
public CoapServer(NetworkConfig config, int... ports) {
	
	// global configuration that is passed down (can be observed for changes)
	if (config != null) {
		this.config = config;
	} else {
		this.config = NetworkConfig.getStandard();
	}
	
	// resources
	this.root = createRoot();
	this.deliverer = new ServerMessageDeliverer(root);
	
	CoapResource well_known = new CoapResource(".well-known");
	well_known.setVisible(false);
	well_known.add(new DiscoveryResource(root));
	root.add(well_known);
	
	// endpoints
	this.endpoints = new ArrayList<Endpoint>();
	// sets the central thread pool for the protocol stage over all endpoints
	this.executor = Executors.newScheduledThreadPool( config.getInt(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT) );
	// create endpoint for each port
	for (int port:ports)
		addEndpoint(new CoapEndpoint(port, this.config));
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:35,代码来源:CoapServer.java

示例10: start

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
/**
 * Starts the server by starting all endpoints this server is assigned to.
 * Each endpoint binds to its port. If no endpoint is assigned to the
 * server, an endpoint is started on the port defined in the config.
 */
@Override
public void start() {
	
	LOGGER.info("Starting server");
	
	if (endpoints.isEmpty()) {
		// servers should bind to the configured port (while clients should use an ephemeral port through the default endpoint)
		int port = config.getInt(NetworkConfig.Keys.COAP_PORT);
		LOGGER.info("No endpoints have been defined for server, setting up server endpoint on default port " + port);
		addEndpoint(new CoapEndpoint(port, this.config));
	}
	
	int started = 0;
	for (Endpoint ep:endpoints) {
		try {
			ep.start();
			// only reached on success
			++started;
		} catch (IOException e) {
			LOGGER.severe(e.getMessage() + " at " + ep.getAddress());
		}
	}
	if (started==0) {
		throw new IllegalStateException("None of the server endpoints could be started");
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:32,代码来源:CoapServer.java

示例11: CoAPAuthorizationServer

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
public CoAPAuthorizationServer() throws SocketException {
      add(new TokenResource());
      add(new IntrospectResource());
 
  	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
  		// only binds to IPv4 addresses and localhost
	if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
		InetSocketAddress bindToAddress = new InetSocketAddress(addr, config.getCoapPort());
		addEndpoint(new CoapEndpoint(bindToAddress));
	}
}

  }
 
开发者ID:erwah,项目名称:acetest,代码行数:14,代码来源:CoAPAuthorizationServer.java

示例12: AuthInfoIntrospectionServer

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
AuthInfoIntrospectionServer() {
    add(new AuthzInfoIntrospectionResource());

	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
		// only binds to IPv4 addresses and localhost
		if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
			InetSocketAddress bindToAddress = new InetSocketAddress(addr, config.getCoapPort());
			addEndpoint(new CoapEndpoint(bindToAddress));
		}
	}

}
 
开发者ID:erwah,项目名称:acetest,代码行数:13,代码来源:AuthInfoIntrospectionServer.java

示例13: DtlsRPKServer

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
public DtlsRPKServer() throws Exception {
    
       add(new TemperatureResource());
    
	DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(config.getCoapsPort()));
	builder.setClientAuthenticationRequired(true);
	// use the global in memory psk key store from the global config object
	builder.setTrustedPublicKeysStore(config.getPublicKeyStorage());
	
	PublicKey publicKey = config.getRpk().getPublicKey();
	PrivateKey privateKey = config.getRpk().getPrivateKey();
	
	builder.setIdentity(privateKey, publicKey);
	
	DTLSConnector connector = new DTLSConnector(builder.build(), null);

   	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
   		// only binds to IPv4 addresses and localhost
		if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
			@SuppressWarnings("static-access")
			CoapEndpoint endpoint = new CoapEndpoint(connector, new NetworkConfig().getStandard()); 
			addEndpoint(endpoint);
			EndpointManager.getEndpointManager().setDefaultSecureEndpoint(endpoint);
		}
	}
	
}
 
开发者ID:erwah,项目名称:acetest,代码行数:28,代码来源:DtlsRPKServer.java

示例14: AuthInfoLocalValidationServer

import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
AuthInfoLocalValidationServer() {
    add(new AuthzInfoLocalValidationResource());

	for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
		// only binds to IPv4 addresses and localhost
		if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
			InetSocketAddress bindToAddress = new InetSocketAddress(addr, config.getCoapPort());
			addEndpoint(new CoapEndpoint(bindToAddress));
		}
	}

}
 
开发者ID:erwah,项目名称:acetest,代码行数:13,代码来源:AuthInfoLocalValidationServer.java

示例15: LeshanBootstrapServer

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


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