本文整理汇总了Java中org.eclipse.californium.core.network.CoapEndpoint类的典型用法代码示例。如果您正苦于以下问题:Java CoapEndpoint类的具体用法?Java CoapEndpoint怎么用?Java CoapEndpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CoapEndpoint类属于org.eclipse.californium.core.network包,在下文中一共展示了CoapEndpoint类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: createRPKClient
import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的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
示例17: main
import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
public static void main(String[] args) {
try {
SemanticsServer server = new SemanticsServer();
server.addEndpoint(new CoapEndpoint(new InetSocketAddress("2001:0470:cafe::38b2:cf50", 5681)));
server.start();
logger.info("Semantics-Server listening on port {}.\n", server.getEndpoints().get(0).getAddress().getPort());
} catch (Throwable t) {
logger.catching(t);
System.exit(ERR_INIT_FAILED);
}
}
开发者ID:mkovatsc,项目名称:iot-semantics,代码行数:13,代码来源:SemanticsServer.java
示例18: main
import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
int port = Integer.valueOf(Optional.fromNullable(System.getenv("PORT")).or("9090"));
WebServer server = SimpleWebServer.builder().setRouterPath("").setPort(port).build();
EndpointManager.getEndpointManager().setDefaultEndpoint(new CoapEndpoint(new InetSocketAddress("2001:0470:cafe::38b2:cf50",23498)));
/*
* load mode from system property if defined, or default to prod
* when using this class to launch your server in development, launch it with -Drestx.mode=dev
*/
System.setProperty("restx.mode", System.getProperty("restx.mode", "prod"));
System.setProperty("restx.app.package", "dynamicserver");
server.startAndAwait();
System.out.println("VISIT " + server.baseUrl() + "/ for Semantics IDE");
}
开发者ID:mkovatsc,项目名称:iot-semantics,代码行数:16,代码来源:IDEServer.java
示例19: initCoap
import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
protected void initCoap() {
DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(); //new InetSocketAddress(0)
builder.setPskStore(new StaticPskStore("", security_key.getBytes()));
coap = new CoapEndpoint(new DTLSConnector(builder.build()), NetworkConfig.getStandard());
}
开发者ID:ffleurey,项目名称:ThingML-Tradfri,代码行数:6,代码来源:TradfriGateway.java
示例20: connectionOpen
import org.eclipse.californium.core.network.CoapEndpoint; //导入依赖的package包/类
/**
* init the connection to the gateway
* @param gatewayIP IP or DNS of the gateway
* @param gatewaySecret Secret, is on the bottom label on the gateway
* @param configFile path to a Properties-File that is writeable, can be null (than a new file in the current directory will be created)
*/
public void connectionOpen(String gatewayIP, String gatewaySecret, Integer udpPort) {
this.gatewayIP = gatewayIP;
this.gatewaySecret = gatewaySecret;
this.udpPort = udpPort;
String connectionSecret = "", connectionIdentity = "";
Map<String, String> connectionParams = this.getIdentityInformation(this.gatewaySecret);
connectionSecret = connectionParams.get("psk");
connectionIdentity = connectionParams.get("identity");
try {
// load key store
KeyStore keyStore = KeyStore.getInstance("JKS");
InputStream in = getClass().getClassLoader().getResourceAsStream(KEY_STORE_LOCATION);
keyStore.load(in, KEY_STORE_PASSWORD.toCharArray());
in.close();
// load trust store
KeyStore trustStore = KeyStore.getInstance("JKS");
in = getClass().getClassLoader().getResourceAsStream(TRUST_STORE_LOCATION);
trustStore.load(in, TRUST_STORE_PASSWORD.toCharArray());
in.close();
// You can load multiple certificates if needed
Certificate[] trustedCertificates = new Certificate[1];
trustedCertificates[0] = trustStore.getCertificate("root");
DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder();
builder.setAddress(new InetSocketAddress(this.udpPort));
builder.setPskStore(new StaticPskStore(connectionIdentity, connectionSecret.getBytes()));
builder.setIdentity((PrivateKey)keyStore.getKey("client", KEY_STORE_PASSWORD.toCharArray()),
keyStore.getCertificateChain("client"), true);
builder.setTrustStore(trustedCertificates);
//try to fix timeouts at user
builder.setRetransmissionTimeout(50000);
dtlsConnector = new DTLSConnector(builder.build());
} catch (Exception e) {
System.err.println("[GWConnection] Error while initializing key store: ");
e.printStackTrace();
System.exit(-1);
}
//custom network config without a config file
NetworkConfig networkConfig = NetworkConfig.createStandardWithoutFile();
networkConfig.set(Keys.ACK_TIMEOUT, 40000);
networkConfig.setInt(Keys.MAX_RESOURCE_BODY_SIZE, 8192);
NetworkConfig.setStandard(networkConfig);
client = new CoapClient();
client.setEndpoint(new CoapEndpoint(dtlsConnector, networkConfig));
client.setTimeout(60000);
//client.setEndpoint(new CoapEndpoint(dtlsConnector, NetworkConfig.getStandard()));
//after opening connection: fetch well known
System.out.println("[GWConnection] Fetching well-known...");
System.out.println("[GWConnection] " + this.get("/.well-known/core").getResponseText());
}
开发者ID:peterkappelt,项目名称:JTradfri,代码行数:70,代码来源:GWConnection.java
注:本文中的org.eclipse.californium.core.network.CoapEndpoint类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论