basic-lib/src/main/java/com/streamsets/pipeline/stage/origin/http/HttpClientSource.java
private Optional<String> processResponse(long start, int maxRecords, BatchMaker batchMaker) throws
      StageException {
    Optional<String> newSourceOffset = Optional.empty();

    if (getResponse() == null) {
      return newSourceOffset;
    }

    // Response was not in the OK range, so treat as an error
    int status = getResponse().getStatus();
    if (status < 200 || status >= 300) {
      lastRequestCompletedTime = System.currentTimeMillis();
      String reason = getResponse().getStatusInfo().getReasonPhrase();
      String respString = getResponse().readEntity(String.class);
      getResponse().close();
      setResponse(null);


      final String errorMsg = reason + " : " + respString;
      LOG.warn(Errors.HTTP_01.getMessage(), status, errorMsg);
      errorRecordHandler.onError(Errors.HTTP_01, status, errorMsg);

      return newSourceOffset;
    }

    if (conf.pagination.mode == PaginationMode.LINK_HEADER) {
      next = getResponse().getLink("next");
      if (next == null) {
        haveMorePages = false;
      }
    }


    if (getResponse().hasEntity()) {
      newSourceOffset = Optional.of(parseResponse(start, maxRecords, batchMaker));
    } else if (conf.httpMethod.getLabel() == "HEAD") {
      // Handle HEAD only requests, which have no body, by creating a blank record for output with headers.
      newSourceOffset = Optional.of(parseHeadersOnly(batchMaker));

    }
    return newSourceOffset;
  }
private Optional<String> processResponse(long start, int maxRecords, BatchMaker batchMaker) throws
      StageException {
    Optional<String> newSourceOffset = Optional.empty();

    if (getResponse() == null) {
      return newSourceOffset;
    }

    // Response was not in the OK range, so treat as an error
    int status = getResponse().getStatus();
    if (status < 200 || status >= 300) {
      lastRequestCompletedTime = System.currentTimeMillis();
      String reason = getResponse().getStatusInfo().getReasonPhrase();
      String respString = getResponse().readEntity(String.class);
      getResponse().close();
      setResponse(null);


      final String errorMsg = reason + " : " + respString;
      LOG.warn(Errors.HTTP_01.getMessage(), status, errorMsg);
      errorRecordHandler.onError(Errors.HTTP_01, status, errorMsg);

      return newSourceOffset;
    }

    if (conf.pagination.mode == PaginationMode.LINK_HEADER) {
      next = getResponse().getLink("next");
      if (next == null) {
        haveMorePages = false;
      }
    }


    if (getResponse().hasEntity()) {
      newSourceOffset = Optional.of(parseResponse(start, maxRecords, batchMaker));
    } else if (conf.httpMethod.getLabel() == "HEAD") {
      // Handle HEAD only requests, which have no body, by creating a blank record for output with headers.
      newSourceOffset = Optional.of(parseHeadersOnly(batchMaker));

    }
    return newSourceOffset;
  }
private Optional < String > processResponse ( long start , int maxRecords , BatchMaker batchMaker ) throws StageException { Optional < String > newSourceOffset = Optional . empty ( ) ; if ( getResponse ( ) == null ) { return newSourceOffset ; } // Response was not in the OK range, so treat as an error int status = getResponse ( ) . getStatus ( ) ; if ( status < 200 || status >= 300 ) { lastRequestCompletedTime = System . currentTimeMillis ( ) ; String reason = getResponse ( ) . getStatusInfo ( ) . getReasonPhrase ( ) ; String respString = getResponse ( ) . readEntity ( String . class ) ; getResponse ( ) . close ( ) ; setResponse ( null ) ; final String errorMsg = reason + " : " + respString ; LOG . warn ( Errors . HTTP_01 . getMessage ( ) , status , errorMsg ) ; errorRecordHandler . onError ( Errors . HTTP_01 , status , errorMsg ) ; return newSourceOffset ; } if ( conf . pagination . mode == PaginationMode . LINK_HEADER ) { next = getResponse ( ) . getLink ( "next" ) ; if ( next == null ) { haveMorePages = false ; } } if ( getResponse ( ) . hasEntity ( ) ) { newSourceOffset = Optional . of ( parseResponse ( start , maxRecords , batchMaker ) ) ; } else if ( conf . httpMethod . getLabel ( ) == "HEAD" ) { // Handle HEAD only requests, which have no body, by creating a blank record for output with headers. newSourceOffset = Optional . of ( parseHeadersOnly ( batchMaker ) ) ; } return newSourceOffset ; }
Verifies that the response was a successful one and has data and continues to parse the response.
@param maxRecords maximum number of records to add to the batch
@param batchMaker batch of records to populate
@return a new source offset if the response was successful
@throws StageException if an unhandled error is encountered
Verifies that the response was a successful one and has data and continues to parse the response .