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

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


      Utils.prettyPrint(request);
        }

        // execute the request
        try {
            Response response = null;
            boolean success = true;
            long time = 5000;
            boolean timedOut = false;

      request.send();
           
            System.out.println();
            System.out.println("**** TEST: " + testName + " ****");
            System.out.println("**** BEGIN CHECK ****");

      response = request.waitForResponse(time);
            if (response != null) {
        success &= checkType(Type.ACK, response.getType());
        success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
        success &= checkToken(request.getToken(), response.getToken());
        success &= hasContentType(response);
        success &= hasNonEmptyPalyoad(response);
        success &= hasObserve(response);
               
                if (success) {

                  time = response.getOptions().getMaxAge() * 1000;
            System.out.println("+++++ Max-Age: "+time+" +++++");
            if (time==0) time = 5000;
             
                for (int l = 0; success && (l < observeLoop); ++l) {
   
            response = request.waitForResponse(time + 1000);
                   
            // checking the response
            if (response != null) {
              System.out.println("Received notification " + l);
                     
                        // print response info
                        if (verbose) {
                            System.out.println("Response received");
                            System.out.println("Time elapsed (ms): " + response.getRTT());
                            Utils.prettyPrint(response);
                        }
   
                        success &= checkResponse(request, response);

              // update timeout
              time = response.getOptions().getMaxAge() * 1000;

              if (!timedOut && l >= 2) {
                System.out.println("+++++++++++++++++++++++");
                System.out.println("++++ REBOOT SERVER ++++");
                System.out.println("+++++++++++++++++++++++");

                System.out.println("++++ obs-reset PUT ++++");
                Request asyncRequest = new Request(Code.POST, Type.CON);
                asyncRequest.setPayload("sesame");
                asyncRequest.setURI(serverURI + "/obs-reset");
                asyncRequest.addMessageObserver(new MessageObserverAdapter() {
                    public void onResponse(Response response) {
                        if (response != null) {
                          System.out.println("Received: " + response.getCode());
                          System.out.println("+++++++++++++++++++++++");
                        }
                      }
                    });
                asyncRequest.send();
              }

            } else if (!timedOut) {
              timedOut = true;
              l = observeLoop / 2;
              System.out.println("PASS: Max-Age timed out");
              System.out.println("+++++ Re-registering +++++");
              Request reregister = Request.newGet();
              reregister.setURI(uri);
              reregister.setToken(request.getToken());
              reregister.setObserve();
              request = reregister;
              request.send();
             
              response = request.waitForResponse(time);
                    if (response != null) {
                success &= checkType(Type.ACK, response.getType());
                success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
                success &= checkToken(request.getToken(), response.getToken());
                success &= hasContentType(response);
                success &= hasNonEmptyPalyoad(response);
                success &= hasObserve(response);
                    } else {
                      System.out.println("FAIL: Re-registration failed");
View Full Code Here


      Utils.prettyPrint(request);
    }

    // execute the request
    try {
      Response response = null;
      boolean success = true;

      request.send();

      System.out.println();
      System.out.println("**** TEST: " + testName + " ****");
      System.out.println("**** BEGIN CHECK ****");

      response = request.waitForResponse(6000);
      if (response != null) {
        success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
        success &= checkType(Type.ACK, response.getType());
        success &= hasContentType(response);
        success &= hasToken(response);
        success &= hasObserve(response);
      }

      // receive multiple responses
      for (int l = 0; success && l < observeLoop; ++l) {
        response = request.waitForResponse(6000);

        // checking the response
        if (response != null) {
          System.out.println("Received notification " + l);

          // print response info
          if (verbose) {
            System.out.println("Response received");
            System.out.println("Time elapsed (ms): "
                + response.getRTT());
            Utils.prettyPrint(response);
          }
         
          success &= checkResponse(request, response);

          if (!hasObserve(response)) {
            break;
          }
        }
      }

      // Client is requested to update the /obs resource on Server
      System.out.println("+++++ Sending PUT +++++");
      Request asyncRequest = new Request(Code.PUT, Type.CON);
      asyncRequest.setPayload(newValue, contentType);
      asyncRequest.setURI(uri);
      asyncRequest.send();

      response = asyncRequest.waitForResponse(6000);

      // checking the response
      if (response != null) {
        success &= checkInt(EXPECTED_RESPONSE_CODE_1.value, response.getCode().value, "code");
      }

      response = request.waitForResponse(6000);
      if (response != null) {
        success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
        success &= hasObserve(response);
        success &= hasContentType(response);
        success &= hasToken(response);
        success &= checkString(newValue, response.getPayloadString(), "payload");
      }

      if (success) {
        System.out.println("**** TEST PASSED ****");
        addSummaryEntry(testName + ": PASSED");
View Full Code Here

      Utils.prettyPrint(request);
    }

    // execute the request
    try {
      Response response = null;
      boolean success = true;

      request.send();

      System.out.println();
      System.out.println("**** TEST: " + testName + " ****");
      System.out.println("**** BEGIN CHECK ****");

      response = request.waitForResponse(6000);

      if (response != null) {
        success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
        success &= checkType(Type.ACK, response.getType());
        success &= checkToken(request.getToken(), response.getToken());
        success &= hasContentType(response);
        success &= hasNonEmptyPalyoad(response);
        success &= hasObserve(response);
       
        time = response.getOptions().getMaxAge() * 1000;
        System.out.println("+++++ Max-Age: "+time+" +++++");
        if (time==0) time = 5000;

        // receive multiple responses
        for (int l = 0; success && l < observeLoop; ++l) {
          response = request.waitForResponse(time + 1000);
 
          // checking the response
          if (response != null) {
            System.out.println("Received notification " + l);
 
            // print response info
            if (verbose) {
              System.out.println("Response received");
              System.out.println("Time elapsed (ms): "
                  + response.getRTT());
              Utils.prettyPrint(response);
            }
           
            success &= checkResponse(request, response);
 
            if (!hasObserve(response)) {
              break;
            }
          }
        }
 
        // Delete the /obs resource of the server (either locally or by
        // having another CoAP client perform a DELETE request)
        System.out.println("+++++ Sending DELETE +++++");
        Request asyncRequest = new Request(Code.DELETE, Type.CON);
        asyncRequest.setURI(uri);
        asyncRequest.addMessageObserver(new MessageObserverAdapter() {
          public void onResponse(Response response) {
            if (response != null) {
              checkInt(EXPECTED_RESPONSE_CODE_1.value, response.getCode().value, "code");
            }
          }
        });
        asyncRequest.send();
 
        time = response.getOptions().getMaxAge() * 1000;
 
        response = request.waitForResponse(time + 1000);
 
        if (response != null) {
 
          Utils.prettyPrint(response);
 
          success &= checkInt(EXPECTED_RESPONSE_CODE_2.value, response.getCode().value, "code");
          success &= hasToken(response);
          success &= hasObserve(response, true);
        } else {
          System.out.println("FAIL: No " + EXPECTED_RESPONSE_CODE_2 + " received");
          success = false;
View Full Code Here

          }
        }
       
      } else if (parser.isResponse()) {
        // This is a response
        Response response = parser.parseResponse();
        response.setSource(raw.getAddress());
        response.setSourcePort(raw.getPort());

        /*
         * Logging here causes significant performance loss.
         * If necessary, add an interceptor that logs the messages,
         * e.g., the MessageTracer.
         */
       
        for (MessageInterceptor interceptor:interceptors)
          interceptor.receiveResponse(response);

        // MessageInterceptor might have canceled
        if (!response.isCanceled()) {
          Exchange exchange = matcher.receiveResponse(response);
          if (exchange != null) {
            exchange.setEndpoint(CoAPEndpoint.this);
            response.setRTT(System.currentTimeMillis() - exchange.getTimestamp());
            coapstack.receiveResponse(exchange, response);
          }
        }
       
      } else if (parser.isEmpty()) {
View Full Code Here

     * from the list of observers.
     * This method is called, when the resource is deleted.
     */
    for (ObserveRelation relation:observeRelations) {
      relation.cancel();
      relation.getExchange().sendResponse(new Response(code));
    }
  }
View Full Code Here

   * Respond the specified response code and no payload.
   *
   * @param code the code
   */
  public void respond(ResponseCode code) {
    respond(new Response(code));
  }
View Full Code Here

   *
   * @param code the response code
   * @param payload the payload
   */
  public void respond(ResponseCode code, String payload) {
    Response response = new Response(code);
    response.setPayload(payload);
    response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN);
    respond(response);
  }
View Full Code Here

   *
   * @param code the response code
   * @param payload the payload
   */
  public void respond(ResponseCode code, byte[] payload) {
    Response response = new Response(code);
    response.setPayload(payload);
    respond(response);
  }
View Full Code Here

   * @param code the response code
   * @param payload the payload
   * @param contentFormat the Content-Format of the payload
   */
  public void respond(ResponseCode code, byte[] payload, int contentFormat) {
    Response response = new Response(code);
    response.setPayload(payload);
    response.getOptions().setContentFormat(contentFormat);
    respond(response);
  }
View Full Code Here

   * @param code the response code
   * @param payload the payload
   * @param contentFormat the Content-Format of the payload
   */
  public void respond(ResponseCode code, String payload, int contentFormat) {
    Response response = new Response(code);
    response.setPayload(payload);
    response.getOptions().setContentFormat(contentFormat);
    respond(response);
  }
View Full Code Here

TOP

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

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.