basic-lib/src/main/java/com/streamsets/pipeline/stage/origin/http/HttpClientSource.java
private void makeRequest(WebTarget target) throws StageException {
    hasher = HF.newHasher();

    MultivaluedMap<String, Object> resolvedHeaders = resolveHeaders();
    final Invocation.Builder invocationBuilder = target
        .request()
        .property(OAuth1ClientSupport.OAUTH_PROPERTY_ACCESS_TOKEN, authToken)
        .headers(resolvedHeaders);

    boolean keepRequesting = !getContext().isStopped();
    boolean gotNewToken = false;
    while (keepRequesting) {
      long startTime = System.currentTimeMillis();
      try {
        if (conf.requestBody != null && !conf.requestBody.isEmpty() && conf.httpMethod != HttpMethod.GET) {
          final String requestBody = bodyEval.eval(bodyVars, conf.requestBody, String.class);
          final String contentType = HttpStageUtil.getContentTypeWithDefault(
              resolvedHeaders, conf.defaultRequestContentType);
          hasher.putString(requestBody, Charset.forName(conf.dataFormatConfig.charset));
          setResponse(invocationBuilder.method(conf.httpMethod.getLabel(), Entity.entity(requestBody, contentType)));
        } else {
          setResponse(invocationBuilder.method(conf.httpMethod.getLabel()));
        }
        LOG.debug("Retrieved response in {} ms", System.currentTimeMillis() - startTime);

        lastRequestTimedOut = false;
        final int status = response.getStatus();
        final boolean statusOk = status >= 200 && status < 300;
        if (conf.client.useOAuth2 && status == 403) { // Token may have expired
          if (gotNewToken) {
            LOG.error(HTTP_21.getMessage());
            throw new StageException(HTTP_21);
          }
          gotNewToken = HttpStageUtil.getNewOAuth2Token(conf.client.oauth2, client);
        } else if (!statusOk && this.statusToActionConfigs.containsKey(status)) {
          final HttpResponseActionConfigBean actionConf = this.statusToActionConfigs.get(status);
          final boolean statusChanged = lastStatus != status || lastRequestTimedOut;

          keepRequesting = applyResponseAction(
              actionConf,
              statusChanged,
              input -> {
                final StageException stageException = new StageException(
                    Errors.HTTP_14,
                    status,
                    response.readEntity(String.class)
                );
                LOG.error(stageException.getMessage());
                return stageException;
              }
          );

        } else {
          keepRequesting = false;
          retryCount = 0;
        }
        lastStatus = status;
      } catch (Exception e) {
        LOG.debug("Request failed after {} ms", System.currentTimeMillis() - startTime);
        final Throwable cause = e.getCause();
        if (cause != null && (cause instanceof TimeoutException || cause instanceof SocketTimeoutException)) {
          LOG.warn(
              "{} attempting to read response in HttpClientSource: {}",
              cause.getClass().getSimpleName(),
              e.getMessage(),
              e
          );
          // read timeout; consult configured action to decide on backoff and retry strategy
          if (this.timeoutActionConfig != null) {
            final HttpResponseActionConfigBean actionConf = this.timeoutActionConfig;

            final boolean firstTimeout = !lastRequestTimedOut;

            applyResponseAction(actionConf, firstTimeout, input -> {
                  LOG.error(Errors.HTTP_18.getMessage());
                  return new StageException(Errors.HTTP_18);
                }
            );

          }

          lastRequestTimedOut = true;
          keepRequesting = false;
        } else if (cause != null && cause instanceof InterruptedException) {
          LOG.error(
            String.format(
                "InterruptedException attempting to make request in HttpClientSource; stopping: %s",
                e.getMessage()
            ),
          e);
          keepRequesting = false;
        } else {
          LOG.error(
            String.format(
                "ProcessingException attempting to make request in HttpClientSource: %s",
                e.getMessage()
            ),
          e);
          Throwable reportEx = cause != null ? cause : e;
          final StageException stageException = new StageException(Errors.HTTP_32, reportEx.toString(), reportEx);
          LOG.error(stageException.getMessage());
          throw stageException;
        }
      }
      keepRequesting &= !getContext().isStopped();
    }

    // Calculate request parameter hash
    currentParameterHash = hasher.hash().toString();
  }
private void makeRequest(WebTarget target) throws StageException {
    hasher = HF.newHasher();

    MultivaluedMap<String, Object> resolvedHeaders = resolveHeaders();
    final Invocation.Builder invocationBuilder = target
        .request()
        .property(OAuth1ClientSupport.OAUTH_PROPERTY_ACCESS_TOKEN, authToken)
        .headers(resolvedHeaders);

    boolean keepRequesting = !getContext().isStopped();
    boolean gotNewToken = false;
    while (keepRequesting) {
      long startTime = System.currentTimeMillis();
      try {
        if (conf.requestBody != null && !conf.requestBody.isEmpty() && conf.httpMethod != HttpMethod.GET) {
          final String requestBody = bodyEval.eval(bodyVars, conf.requestBody, String.class);
          final String contentType = HttpStageUtil.getContentTypeWithDefault(
              resolvedHeaders, conf.defaultRequestContentType);
          hasher.putString(requestBody, Charset.forName(conf.dataFormatConfig.charset));
          setResponse(invocationBuilder.method(conf.httpMethod.getLabel(), Entity.entity(requestBody, contentType)));
        } else {
          setResponse(invocationBuilder.method(conf.httpMethod.getLabel()));
        }
        LOG.debug("Retrieved response in {} ms", System.currentTimeMillis() - startTime);

        lastRequestTimedOut = false;
        final int status = response.getStatus();
        final boolean statusOk = status >= 200 && status < 300;
        if (conf.client.useOAuth2 && status == 403) { // Token may have expired
          if (gotNewToken) {
            LOG.error(HTTP_21.getMessage());
            throw new StageException(HTTP_21);
          }
          gotNewToken = HttpStageUtil.getNewOAuth2Token(conf.client.oauth2, client);
        } else if (!statusOk && this.statusToActionConfigs.containsKey(status)) {
          final HttpResponseActionConfigBean actionConf = this.statusToActionConfigs.get(status);
          final boolean statusChanged = lastStatus != status || lastRequestTimedOut;

          keepRequesting = applyResponseAction(
              actionConf,
              statusChanged,
              input -> {
                final StageException stageException = new StageException(
                    Errors.HTTP_14,
                    status,
                    response.readEntity(String.class)
                );
                LOG.error(stageException.getMessage());
                return stageException;
              }
          );

        } else {
          keepRequesting = false;
          retryCount = 0;
        }
        lastStatus = status;
      } catch (Exception e) {
        LOG.debug("Request failed after {} ms", System.currentTimeMillis() - startTime);
        final Throwable cause = e.getCause();
        if (cause != null && (cause instanceof TimeoutException || cause instanceof SocketTimeoutException)) {
          LOG.warn(
              "{} attempting to read response in HttpClientSource: {}",
              cause.getClass().getSimpleName(),
              e.getMessage(),
              e
          );
          // read timeout; consult configured action to decide on backoff and retry strategy
          if (this.timeoutActionConfig != null) {
            final HttpResponseActionConfigBean actionConf = this.timeoutActionConfig;

            final boolean firstTimeout = !lastRequestTimedOut;

            applyResponseAction(actionConf, firstTimeout, input -> {
                  LOG.error(Errors.HTTP_18.getMessage());
                  return new StageException(Errors.HTTP_18);
                }
            );

          }

          lastRequestTimedOut = true;
          keepRequesting = false;
        } else if (cause != null && cause instanceof InterruptedException) {
          LOG.error(
            String.format(
                "InterruptedException attempting to make request in HttpClientSource; stopping: %s",
                e.getMessage()
            ),
          e);
          keepRequesting = false;
        } else {
          LOG.error(
            String.format(
                "ProcessingException attempting to make request in HttpClientSource: %s",
                e.getMessage()
            ),
          e);
          Throwable reportEx = cause != null ? cause : e;
          final StageException stageException = new StageException(Errors.HTTP_32, reportEx.toString(), reportEx);
          LOG.error(stageException.getMessage());
          throw stageException;
        }
      }
      keepRequesting &= !getContext().isStopped();
    }

    // Calculate request parameter hash
    currentParameterHash = hasher.hash().toString();
  }
private void makeRequest ( WebTarget target ) throws StageException { hasher = HF . newHasher ( ) ; MultivaluedMap < String , Object > resolvedHeaders = resolveHeaders ( ) ; final Invocation . Builder invocationBuilder = target . request ( ) . property ( OAuth1ClientSupport . OAUTH_PROPERTY_ACCESS_TOKEN , authToken ) . headers ( resolvedHeaders ) ; boolean keepRequesting = ! getContext ( ) . isStopped ( ) ; boolean gotNewToken = false ; while ( keepRequesting ) { long startTime = System . currentTimeMillis ( ) ; try { if ( conf . requestBody != null && ! conf . requestBody . isEmpty ( ) && conf . httpMethod != HttpMethod . GET ) { final String requestBody = bodyEval . eval ( bodyVars , conf . requestBody , String . class ) ; final String contentType = HttpStageUtil . getContentTypeWithDefault ( resolvedHeaders , conf . defaultRequestContentType ) ; hasher . putString ( requestBody , Charset . forName ( conf . dataFormatConfig . charset ) ) ; setResponse ( invocationBuilder . method ( conf . httpMethod . getLabel ( ) , Entity . entity ( requestBody , contentType ) ) ) ; } else { setResponse ( invocationBuilder . method ( conf . httpMethod . getLabel ( ) ) ) ; } LOG . debug ( "Retrieved response in {} ms" , System . currentTimeMillis ( ) - startTime ) ; lastRequestTimedOut = false ; final int status = response . getStatus ( ) ; final boolean statusOk = status >= 200 && status < 300 ; if ( conf . client . useOAuth2 && status == 403 ) { // Token may have expired if ( gotNewToken ) { LOG . error ( HTTP_21 . getMessage ( ) ) ; throw new StageException ( HTTP_21 ) ; } gotNewToken = HttpStageUtil . getNewOAuth2Token ( conf . client . oauth2 , client ) ; } else if ( ! statusOk && this . statusToActionConfigs . containsKey ( status ) ) { final HttpResponseActionConfigBean actionConf = this . statusToActionConfigs . get ( status ) ; final boolean statusChanged = lastStatus != status || lastRequestTimedOut ; keepRequesting = applyResponseAction ( actionConf , statusChanged , input -> { final StageException stageException = new StageException ( Errors . HTTP_14 , status , response . readEntity ( String . class ) ) ; LOG . error ( stageException . getMessage ( ) ) ; return stageException ; } ) ; } else { keepRequesting = false ; retryCount = 0 ; } lastStatus = status ; } catch ( Exception e ) { LOG . debug ( "Request failed after {} ms" , System . currentTimeMillis ( ) - startTime ) ; final Throwable cause = e . getCause ( ) ; if ( cause != null && ( cause instanceof TimeoutException || cause instanceof SocketTimeoutException ) ) { LOG . warn ( "{} attempting to read response in HttpClientSource: {}" , cause . getClass ( ) . getSimpleName ( ) , e . getMessage ( ) , e ) ; // read timeout; consult configured action to decide on backoff and retry strategy if ( this . timeoutActionConfig != null ) { final HttpResponseActionConfigBean actionConf = this . timeoutActionConfig ; final boolean firstTimeout = ! lastRequestTimedOut ; applyResponseAction ( actionConf , firstTimeout , input -> { LOG . error ( Errors . HTTP_18 . getMessage ( ) ) ; return new StageException ( Errors . HTTP_18 ) ; } ) ; } lastRequestTimedOut = true ; keepRequesting = false ; } else if ( cause != null && cause instanceof InterruptedException ) { LOG . error ( String . format ( "InterruptedException attempting to make request in HttpClientSource; stopping: %s" , e . getMessage ( ) ) , e ) ; keepRequesting = false ; } else { LOG . error ( String . format ( "ProcessingException attempting to make request in HttpClientSource: %s" , e . getMessage ( ) ) , e ) ; Throwable reportEx = cause != null ? cause : e ; final StageException stageException = new StageException ( Errors . HTTP_32 , reportEx . toString ( ) , reportEx ) ; LOG . error ( stageException . getMessage ( ) ) ; throw stageException ; } } keepRequesting &= ! getContext ( ) . isStopped ( ) ; } // Calculate request parameter hash currentParameterHash = hasher . hash ( ) . toString ( ) ; }
Helper method to construct an HTTP request and fetch a response.

@param target the target url to fetch.
@throws StageException if an unhandled error is encountered
Helper method to construct an HTTP request and fetch a response .