Package ch.ethz.inf.vs.californium.server.resources

Examples of ch.ethz.inf.vs.californium.server.resources.ResourceBase


    scanner.useDelimiter("/");
    String next = "";
    boolean resourceExist = false;
    Resource resource = this; // It's the resource that represents the endpoint
   
    ResourceBase subResource = null;
    while (scanner.hasNext()) {
      resourceExist = false;
      next = scanner.next();
      for (Resource res : resource.getChildren()) {
        if (res.getName().equals(next)) {
          subResource = (ResourceBase) res;
          resourceExist = true;
        }
      }
      if (!resourceExist) {
        subResource = new RDTagResource(next,true, this);
        resource.add(subResource);
      }
      resource = subResource;
    }
    subResource.setPath(resource.getPath());
    subResource.setName(next);
    scanner.close();
    return subResource;
  }
View Full Code Here


      } else {
        scanner.close();
        return false;
      }
     
      ResourceBase resource = addNodeResource(path);
      /*
       * Since created the subResource, get all the attributes from
       * the payload. Each parameter is separated by a ";".
       */
      scanner.useDelimiter(";");
      while (scanner.hasNext()) {
        LinkAttribute attr = LinkAttribute.parse(scanner.next());
        if (attr.getValue() == null)
          resource.getAttributes().addAttribute(attr.getName());
        else resource.getAttributes().addAttribute(attr.getName(), attr.getValue());
      }
      resource.getAttributes().addAttribute(LinkFormat.END_POINT, getEndpointIdentifier());
    }
    scanner.close();
   
    return true;
  }
View Full Code Here

    }
    this.executor = Executors.newScheduledThreadPool(
        config.getInt(NetworkConfigDefaults.SERVER_THRESD_NUMER));
    this.deliverer = new ServerMessageDeliverer(root);
   
    ResourceBase well_known = new ResourceBase(".well-known");
    well_known.setVisible(false);
    well_known.add(new DiscoveryResource(root));
    root.add(well_known);
   
    for (int port:ports)
      bind(port);
  }
View Full Code Here

  protected static final Logger LOG = Logger.getLogger(LinkParser.class.getName());
 
  public static Resource parseTree(String linkFormat) {
    Pattern DELIMITER = Pattern.compile("\\s*,+\\s*");

    Resource root = new ResourceBase("");
   
    if (linkFormat!=null) {
      Scanner scanner = new Scanner(linkFormat);
     
      String path = null;
      while ((path = scanner.findInLine("</[^>]*>")) != null) {
       
        // Trim </...>
        path = path.substring(2, path.length() - 1);
       
        LOG.finer(String.format("Parsing link resource: %s", path));
 
        // Retrieve specified resource, create if necessary
        Resource resource = new ResourceBase(path);
       
        // Read link format attributes
        LinkAttribute attr = null;
        while (scanner.findWithinHorizon(DELIMITER, 1)==null && (attr = LinkAttribute.parse(scanner))!=null) {
          resource.getAttributes().addAttribute(attr.getName(), attr.getValue());
        }
       
        root.add(resource);
      }
    }
View Full Code Here

 
  public RunningResource(String name, Server s) {
    super(name);
    this.server = s;
   
    add(new ResourceBase("shutdown") {
      public void handlePOST(CoapExchange exchange) {
        exchange.respond(ResponseCode.CHANGED);
        sleep(100);
        server.stop();
      }
    });
   
    add(new ResourceBase("restart") {
      public void handlePOST(CoapExchange exchange) {
        restartCount++;
        server.stop();
        sleep(100);
        server.start();
View Full Code Here

  }

  public static void main(String[] args) {
   
    Server server = new Server();
    server.add(new ResourceBase("secure") { 
        @Override
        public void handleGET(CoapExchange exchange) {
          exchange.respond(ResponseCode.CONTENT, "hello security");
        }
      });
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.californium.server.resources.ResourceBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.