src/main/java/net/leanix/api/common/ApiClient.java
public <T> T invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames, GenericType<T> returnType) throws ApiException {
    updateParamsForAuth(new String[]{"token", "apiKey"}/*authNames*/, queryParams, headerParams);

    // Not using `.target(this.basePath).path(path)` below,
    // to support (constant) query string in `path`, e.g. "/posts?draft=1"
    WebTarget target = httpClient.target(this.basePath + path);

    if (queryParams != null) {
      for (Pair queryParam : queryParams) {
        if (queryParam.getValue() != null) {
          target = target.queryParam(queryParam.getName(), queryParam.getValue());
        }
      }
    }

    Invocation.Builder invocationBuilder = target.request().accept(accept);

    for (String key : headerParams.keySet()) {
      String value = headerParams.get(key);
      if (value != null) {
        invocationBuilder = invocationBuilder.header(key, value);
      }
    }

    for (String key : defaultHeaderMap.keySet()) {
      if (!headerParams.containsKey(key)) {
        String value = defaultHeaderMap.get(key);
        if (value != null) {
          invocationBuilder = invocationBuilder.header(key, value);
        }
      }
    }

    Entity<?> entity = serialize(body, formParams, contentType);

    Response response = null;

    if ("GET".equals(method)) {
      response = invocationBuilder.get();
    } else if ("POST".equals(method)) {
      response = invocationBuilder.post(entity);
    } else if ("PUT".equals(method)) {
      response = invocationBuilder.put(entity);
    } else if ("DELETE".equals(method)) {
      response = invocationBuilder.delete();
    } else {
      throw new ApiException(500, "unknown method type " + method);
    }

    statusCode = response.getStatusInfo().getStatusCode();
    responseHeaders = buildResponseHeaders(response);

    if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
      return null;
    } else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) {
      if (returnType == null)
        return null;
      else
        return deserialize(response, returnType);
    } else {
      String message = "error";
      String respBody = null;
      if (response.hasEntity()) {
        try {
          respBody = String.valueOf(response.readEntity(String.class));
          message = respBody;
        } catch (RuntimeException e) {
          // e.printStackTrace();
        }
      }
      throw new ApiException(
              response.getStatus(),
              message,
              buildResponseHeaders(response),
              respBody);
    }
  }
public <T> T invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames, GenericType<T> returnType) throws ApiException {
    updateParamsForAuth(new String[]{"token", "apiKey"}/*authNames*/, queryParams, headerParams);

    // Not using `.target(this.basePath).path(path)` below,
    // to support (constant) query string in `path`, e.g. "/posts?draft=1"
    WebTarget target = httpClient.target(this.basePath + path);

    if (queryParams != null) {
      for (Pair queryParam : queryParams) {
        if (queryParam.getValue() != null) {
          target = target.queryParam(queryParam.getName(), queryParam.getValue());
        }
      }
    }

    Invocation.Builder invocationBuilder = target.request().accept(accept);

    for (String key : headerParams.keySet()) {
      String value = headerParams.get(key);
      if (value != null) {
        invocationBuilder = invocationBuilder.header(key, value);
      }
    }

    for (String key : defaultHeaderMap.keySet()) {
      if (!headerParams.containsKey(key)) {
        String value = defaultHeaderMap.get(key);
        if (value != null) {
          invocationBuilder = invocationBuilder.header(key, value);
        }
      }
    }

    Entity<?> entity = serialize(body, formParams, contentType);

    Response response = null;

    if ("GET".equals(method)) {
      response = invocationBuilder.get();
    } else if ("POST".equals(method)) {
      response = invocationBuilder.post(entity);
    } else if ("PUT".equals(method)) {
      response = invocationBuilder.put(entity);
    } else if ("DELETE".equals(method)) {
      response = invocationBuilder.delete();
    } else {
      throw new ApiException(500, "unknown method type " + method);
    }

    statusCode = response.getStatusInfo().getStatusCode();
    responseHeaders = buildResponseHeaders(response);

    if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
      return null;
    } else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) {
      if (returnType == null)
        return null;
      else
        return deserialize(response, returnType);
    } else {
      String message = "error";
      String respBody = null;
      if (response.hasEntity()) {
        try {
          respBody = String.valueOf(response.readEntity(String.class));
          message = respBody;
        } catch (RuntimeException e) {
          // e.printStackTrace();
        }
      }
      throw new ApiException(
              response.getStatus(),
              message,
              buildResponseHeaders(response),
              respBody);
    }
  }
public < T > T invokeAPI ( String path , String method , List < Pair > queryParams , Object body , Map < String , String > headerParams , Map < String , Object > formParams , String accept , String contentType , String [ ] authNames , GenericType < T > returnType ) throws ApiException { updateParamsForAuth ( new String [ ] { "token" , "apiKey" } /*authNames*/ , queryParams , headerParams ) ; // Not using `.target(this.basePath).path(path)` below, // to support (constant) query string in `path`, e.g. "/posts?draft=1" WebTarget target = httpClient . target ( this . basePath + path ) ; if ( queryParams != null ) { for ( Pair queryParam : queryParams ) { if ( queryParam . getValue ( ) != null ) { target = target . queryParam ( queryParam . getName ( ) , queryParam . getValue ( ) ) ; } } } Invocation . Builder invocationBuilder = target . request ( ) . accept ( accept ) ; for ( String key : headerParams . keySet ( ) ) { String value = headerParams . get ( key ) ; if ( value != null ) { invocationBuilder = invocationBuilder . header ( key , value ) ; } } for ( String key : defaultHeaderMap . keySet ( ) ) { if ( ! headerParams . containsKey ( key ) ) { String value = defaultHeaderMap . get ( key ) ; if ( value != null ) { invocationBuilder = invocationBuilder . header ( key , value ) ; } } } Entity < ? > entity = serialize ( body , formParams , contentType ) ; Response response = null ; if ( "GET" . equals ( method ) ) { response = invocationBuilder . get ( ) ; } else if ( "POST" . equals ( method ) ) { response = invocationBuilder . post ( entity ) ; } else if ( "PUT" . equals ( method ) ) { response = invocationBuilder . put ( entity ) ; } else if ( "DELETE" . equals ( method ) ) { response = invocationBuilder . delete ( ) ; } else { throw new ApiException ( 500 , "unknown method type " + method ) ; } statusCode = response . getStatusInfo ( ) . getStatusCode ( ) ; responseHeaders = buildResponseHeaders ( response ) ; if ( response . getStatus ( ) == Status . NO_CONTENT . getStatusCode ( ) ) { return null ; } else if ( response . getStatusInfo ( ) . getFamily ( ) . equals ( Status . Family . SUCCESSFUL ) ) { if ( returnType == null ) return null ; else return deserialize ( response , returnType ) ; } else { String message = "error" ; String respBody = null ; if ( response . hasEntity ( ) ) { try { respBody = String . valueOf ( response . readEntity ( String . class ) ) ; message = respBody ; } catch ( RuntimeException e ) { // e.printStackTrace(); } } throw new ApiException ( response . getStatus ( ) , message , buildResponseHeaders ( response ) , respBody ) ; } }
Invoke API by sending HTTP request with the given options.

@param path The sub-path of the HTTP URL
@param method The request method, one of "GET", "POST", "PUT", and "DELETE"
@param queryParams The query parameters
@param body The request body object
@param headerParams The header parameters
@param formParams The form parameters
@param accept The request's Accept header
@param contentType The request's Content-Type header
@param authNames The authentications to apply
@param returnType The return type into which to deserialize the response
@return The response body in type of string
Invoke API by sending HTTP request with the given options .