本文整理汇总了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;
}
示例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();
}
示例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);
}
}
}
示例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);
}
}
}
示例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();
}
示例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!");
}
示例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));
}
}
示例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!");
}
示例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));
}
示例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");
}
}
示例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));
}
}
}
示例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));
}
}
}
示例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);
}
}
}
示例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));
}
}
}
示例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);
}