本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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();
}
示例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");
}
示例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();
}
示例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);
}
示例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!");
}
示例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);
}
};
}
示例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!");
}
示例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();
}
}
示例12: doStop
import org.eclipse.californium.core.CoapServer; //导入依赖的package包/类
@Override
protected void doStop() throws Exception {
for (CoapServer s : servers.values()) {
s.stop();
}
super.doStop();
}
示例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);
}
示例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();
}
示例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();
}