Package ch.ethz.inf.vs.californium.coap

Examples of ch.ethz.inf.vs.californium.coap.Request


      System.err.println("URI not specified");
      System.exit(ERR_MISSING_URI);
    }
   
    // create request according to specified method
    Request request = newRequest(method);

    // set request URI
    if (method.equals("DISCOVER") && (uri.getPath() == null || uri.getPath().isEmpty() || uri.getPath().equals("/"))) {
      // add discovery resource path to URI
      try {
        uri = new URI(uri.getScheme(), uri.getAuthority(), DISCOVERY_RESOURCE, uri.getQuery());
       
      } catch (URISyntaxException e) {
        System.err.println("Failed to parse URI: " + e.getMessage());
        System.exit(ERR_BAD_URI);
      }
    }
   
    request.setURI(uri);
    request.setPayload(payload);
    request.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN);
   
    if (request.getScheme().equals(CoAP.COAP_SECURE_URI_SCHEME)) {
      dtlsEndpoint = new CoAPEndpoint(new DTLSConnector(new InetSocketAddress(0)), NetworkConfig.getStandard());
      dtlsEndpoint.setMessageDeliverer(new ClientMessageDeliverer());
      dtlsEndpoint.start();
      EndpointManager.getEndpointManager().setDefaultSecureEndpoint(dtlsEndpoint);
    }
   
    // execute request
    try {
      request.send();

      // loop for receiving multiple responses
      do {
 
        // receive response
        Response response = null;
        try {
          response = request.waitForResponse();
        } catch (InterruptedException e) {
          System.err.println("Failed to receive response: " + e.getMessage());
          System.exit(ERR_RESPONSE_FAILED);
        }
 
View Full Code Here


    } else if (method.equals("DELETE")) {
      return Request.newDelete();
    } else if (method.equals("DISCOVER")) {
      return Request.newGet();
    } else if (method.equals("OBSERVE")) {
      Request request = Request.newGet();
      request.setObserve();
      loop = true;
      return request;
    } else {
      System.err.println("Unknown method: " + method);
      System.exit(ERR_UNKNOWN_METHOD);
View Full Code Here

    // TODO check with draft authors if update should be atomic
    if (newContext.equals("")) {
      context = "coap://" + request.getSource()+":"+request.getSourcePort();
    } else {
      Request checkRequest = Request.newGet();

      try {
        checkRequest.setURI(context);
      } catch (Exception e) {
        LOGGER.warning(e.toString());
        return false;
      }
    }
View Full Code Here

    @Override
    public void run() {

      LOGGER.info("Validating endpoint: "+getContext());
     
      Request validationRequest = Request.newGet();
      validationRequest.setURI(getContext()+"/.well-known/core");
      if (etag!=null) {
        validationRequest.getOptions().addETag(etag);
      }
      Response response = null;
     
      try {
        validationRequest.send();
        response = validationRequest.waitForResponse();
       
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
View Full Code Here

  public CO08(String serverURI) {
    super(CO08.class.getSimpleName());

    // create the request
    Request request = new Request(Code.GET, Type.CON);
    // request.setToken(TokenManager.getInstance().acquireToken(false));
    request.setObserve();
    // set the parameters and execute the request
    executeRequest(request, serverURI, RESOURCE_URI);

  }
View Full Code Here

      }

      // Delete the /obs resource of the server (either locally or by
      // having another CoAP client perform a DELETE request)
      System.out.println("+++++ Sending PUT +++++");
      Request asyncRequest = new Request(Code.PUT, Type.CON);
      asyncRequest.setURI(uri);
      asyncRequest.getOptions().setContentFormat((int) Math.random() * 0xFFFF + 1);
      asyncRequest.setPayload("Random");
      asyncRequest.addMessageObserver(new MessageObserverAdapter() {
        public void onResponse(Response response) {
          if (response != null) {
            checkInt(EXPECTED_RESPONSE_CODE_1.value,
                response.getCode().value, "code");
          }
        }
      });
      // enable response queue for synchronous I/O
      asyncRequest.send();

      long time = response.getOptions().getMaxAge() * 1000;

      response = request.waitForResponse(time + 1000);
      System.out.println("received " + response);
View Full Code Here

  public CC06(String serverURI) {
    super(CC06.class.getSimpleName());

    // create the request
    Request request = Request.newDelete();
    request.setConfirmable(false);
    // set the parameters and execute the request
    executeRequest(request, serverURI, RESOURCE_URI);
  }
View Full Code Here

  public CC02(String serverURI) {
    super(CC02.class.getSimpleName());

    // create the request
    Request request = Request.newDelete();
    // set the parameters and execute the request
    executeRequest(request, serverURI, RESOURCE_URI);
  }
View Full Code Here

  public CL08(String serverURI) {
    super(CL08.class.getSimpleName());

    // create the request
    Request request = new Request(Code.GET, Type.CON);
    // set query
    request.getOptions().addURIQuery(EXPECTED_HREF);
    // set the parameters and execute the request
    executeRequest(request, serverURI, RESOURCE_URI);
  }
View Full Code Here

  public CL05(String serverURI) {
    super(CL05.class.getSimpleName());

    // create the request
    Request request = new Request(Code.GET, Type.CON);
    // set query
    request.getOptions().addURIQuery(EXPECTED_IF);
    // set the parameters and execute the request
    executeRequest(request, serverURI, RESOURCE_URI);
  }
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.californium.coap.Request

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.