本文整理汇总了Java中org.eclipse.californium.core.CoapResource类的典型用法代码示例。如果您正苦于以下问题:Java CoapResource类的具体用法?Java CoapResource怎么用?Java CoapResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CoapResource类属于org.eclipse.californium.core包,在下文中一共展示了CoapResource类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HCoapServer
import org.eclipse.californium.core.CoapResource; //导入依赖的package包/类
public HCoapServer(List<String> resourceList, int port, int sec_port) throws SocketException {
this.port = port;
this.sec_port = sec_port;
for(String res : resourceList) {
String[] split = res.split("\\^");
if (split == null) continue;
log.debug("resource[0]: {}", split[0] );
add(new HCoapResource(split[0]));
if(split.length >= 2) {
log.debug("resource[1]: {}", split[1] );
add(new CoapResource(split[0]).add(new HCoapResource(split[1])));
}
}
add(new HCoapResource("~")); // for SP-relative Resource ID
add(new HCoapResource("_")); // Absolute Resource ID
addEndpoints();
}
示例2: setUp
import org.eclipse.californium.core.CoapResource; //导入依赖的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();
}
示例3: main
import org.eclipse.californium.core.CoapResource; //导入依赖的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();
}
示例4: doStop
import org.eclipse.californium.core.CoapResource; //导入依赖的package包/类
@Override
protected void doStop() throws Exception {
for (CoapResource r : resources) {
r.getParent().remove(r);
}
resources.clear();
super.doStop();
}
示例5: Server
import org.eclipse.californium.core.CoapResource; //导入依赖的package包/类
public Server(int port) {
super(port);
amperage = new AmperageResource(port);
voltage = new VoltageResource(port);
power = new PowerResource(port);
description = new DescriptionResource(port);
add(description.add(
new CoapResource("amperage").add(amperage),
new CoapResource("voltage").add(voltage),
new CoapResource("power").add(power)));
}
示例6: createResources
import org.eclipse.californium.core.CoapResource; //导入依赖的package包/类
private void createResources() {
CoapResource api = new CoapResource(API);
api.add(new CoapTransportResource(msgProducer, attributesService, authService, V1, timeout));
server.add(api);
}
示例7: main
import org.eclipse.californium.core.CoapResource; //导入依赖的package包/类
public static void main(String[] args) {
/* Create CoAP Server listening on all interfaces (IPv6 & IPv4) */
AllInterfacesCoapServer server = new AllInterfacesCoapServer();
ClientAuthorizationManager cam = createCamWithLocalSam();
/* Add CoAP Resource to process incoming requests */
server.add(new CoapResource("client-authorize"){
{
/* Set title/description for the CoAP Resource */
getAttributes().setTitle("DCAF Client Authorization Manager");
}
@Override
public void handlePOST(CoapExchange exchange) {
byte[] requestPayload = exchange.getRequestPayload();
/* Deserialize incoming requests from CBOR to Java Objects */
Optional<AccessRequest> request = Utils.deserializeCbor(requestPayload, AccessRequest.class);
if (!request.isPresent()) {
logger.error("Error 500 - deserializeCbor failed");
exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
return;
}
/* Do something here (or even before deserialization to check if the client is allowed to
* get what he requested */
/* Get the ticket grant message by calling cam.process.
* The CAM is going to contact the SAM to get the TicketGrantMessage */
TicketGrantMessage grant = cam.process(request.get());
/* Serialize the grant answer and return it to the client. */
Optional<byte[]> answer = Utils.serializeCbor(grant);
if (answer.isPresent()) {
logger.debug("respond: h'" + Hex.encodeHexString(answer.get()) + "'");
exchange.respond(CoAP.ResponseCode.CONTENT, answer.get(), Utils.getDcafMediaType());
} else {
logger.error("Error 500 - serializeCbor failed");
exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
}
}
});
}
示例8: createResources
import org.eclipse.californium.core.CoapResource; //导入依赖的package包/类
private void createResources() {
CoapResource api = new CoapResource(API);
api.add(new CoapTransportResource(processor, authService, adaptor, V1, timeout));
server.add(api);
}
示例9: CoapExchange
import org.eclipse.californium.core.CoapResource; //导入依赖的package包/类
/**
* Constructs a new CoAP Exchange object representing the specified exchange
* and Resource.
*
* @param exchange the exchange
* @param resource the resource
*/
public CoapExchange(Exchange exchange, CoapResource resource) {
if (exchange == null) throw new NullPointerException();
if (resource == null) throw new NullPointerException();
this.exchange = exchange;
this.resource = resource;
}