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


Java CoapResource类代码示例

本文整理汇总了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();
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:22,代码来源:HCoapServer.java

示例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();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:20,代码来源:TestCoapClientTarget.java

示例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();
    }
 
开发者ID:jvermillard,项目名称:hands-on-coap,代码行数:19,代码来源:HelloWorld2.java

示例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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:CoAPConsumer.java

示例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)));
}
 
开发者ID:semiotproject,项目名称:simulator-electric-meters,代码行数:13,代码来源:Server.java

示例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);
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:6,代码来源:CoapTransportService.java

示例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);
              }

          }
      });
  }
 
开发者ID:beduino-project,项目名称:dcaf-java,代码行数:47,代码来源:ExampleServer.java

示例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);
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:6,代码来源:CoapTransportService.java

示例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;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:14,代码来源:CoapExchange.java


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