/* (non-Javadoc)
@see com.att.authz.facade.AuthzFacade#getAPIExample(com.att.authz.env.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String)
510186
@Override
	public Result<Void> getAPIExample(AuthzTrans trans, HttpServletResponse resp, String nameOrContentType, boolean optional) {
		TimeTaken tt = trans.start(API_EXAMPLE, Env.SUB);
		try {
			String content =Examples.print(apiDF.getEnv(), nameOrContentType, optional); 
			resp.getOutputStream().print(content);
			setContentType(resp,content.contains("<?xml")?TYPE.XML:TYPE.JSON);
			return Result.ok();
		} catch (Exception e) {
			trans.error().log(e,IN,API_EXAMPLE);
			return Result.err(Result.ERR_NotImplemented,e.getMessage());
		} finally {
			tt.done();
		}
	}
1325528
public ApiResponse<DynconfigGetConfigResponse> dynconfigGetConfigWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = dynconfigGetConfigValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<DynconfigGetConfigResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
481508
@Override
  public AppResponse getApp(WebResource resource, ResourcePath<App> appResourcePath) {
    return resource.path(appResourcePath.getPath()).get(AppResponse.class);
  }
1202338
public function getAPI()
    {
        if (empty($this->api)) {
            if (!empty($this->config(static::TOOL_CANVAS_API)['token'])) {
                $this->setAPI(new CanvasPest(
                    'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain'] . '/api/v1',
                    $this->config(static::TOOL_CANVAS_API)['token']
                ));
            } else {
                throw new ConfigurationException(
                    'Canvas URL and Token required',
                    ConfigurationException::CANVAS_API_INCORRECT
                );
            }
        }
        return $this->api;
    }
814499
private String getApiIdx(String orgId, String apiId, String version) {
        return "API::" + orgId + "|" + apiId + "|" + version; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }
585658
private <TResponse> TResponse callServiceOwnerPostApi(
            String path, Object requestBody, Class<TResponse> responseClass) throws AuthleteApiException
    {
        return callServiceOwnerPostApi(path, (Map<String, String>)null, requestBody, responseClass);
    }
583896
static SwiftApi swiftApi( Map<String,String> targetProperties ) throws TargetException {

		validate( targetProperties );
		return ContextBuilder
				.newBuilder( PROVIDER_SWIFT )
				.endpoint( targetProperties.get( API_URL ))
				.credentials( identity( targetProperties ), targetProperties.get( PASSWORD ))
				.buildApi( SwiftApi.class );
	}
1349988
private <T extends Object> T getResponse(HttpResponse httpResponse, Class<T> clazz) throws IOException, HttpRosetteAPIException {
        int status = httpResponse.getStatusLine().getStatusCode();
        String encoding = headerValueOrNull(httpResponse.getFirstHeader(HttpHeaders.CONTENT_ENCODING));

        try (
                InputStream stream = httpResponse.getEntity().getContent();
                InputStream inputStream = "gzip".equalsIgnoreCase(encoding) ? new GZIPInputStream(stream) : stream) {
            String ridHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-DocumentRequest-Id"));
            if (HTTP_OK != status) {
                String ecHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-Status-Code"));
                String emHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-Status-Message"));
                String responseContentType = headerValueOrNull(httpResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE));
                if ("application/json".equals(responseContentType)) {
                    ErrorResponse errorResponse = mapper.readValue(inputStream, ErrorResponse.class);
                    if (ridHeader != null) {
                        LOG.debug("DocumentRequest ID " + ridHeader);
                    }
                    if (ecHeader != null) {
                        errorResponse.setCode(ecHeader);
                    }
                    if (429 == status) {
                        String concurrencyMessage = "You have exceeded your plan's limit on concurrent calls. "
                                + "This could be caused by multiple processes or threads making Rosette API calls in parallel, "
                                + "or if your httpClient is configured with higher concurrency than your plan allows.";
                        if (emHeader == null) {
                            emHeader = concurrencyMessage;
                        } else {
                            emHeader = concurrencyMessage + System.lineSeparator() + emHeader;
                        }
                    }
                    if (emHeader != null) {
                        errorResponse.setMessage(emHeader);
                    }
                    throw new HttpRosetteAPIException(errorResponse, status);
                } else {
                    String errorContent;
                    if (inputStream != null) {
                        byte[] content = getBytes(inputStream);
                        errorContent = new String(content, "utf-8");
                    } else {
                        errorContent = "(no body)";
                    }
                    // something not from us at all
                    throw new HttpRosetteAPIException("Invalid error response (not json)",
                            ErrorResponse.builder().code("invalidErrorResponse").message(errorContent).build(), status);
                }
            } else {
                return mapper.readValue(inputStream, clazz);
            }
        }
    }
518047
public CommandOutput<?, ?> getResponse(List<Command> cmds) throws RestApiProcessingException {
    String url = cmds.get(0).getParams().get(0);

    log.info("URL: " + url);
    String jsonStr = null;
    HttpRequestBase httpRequest = new HttpGet(url);
    addHeaders(httpRequest);
    HttpEntity httpEntity = null;
    HttpResponse httpResponse = null;
    try {
      httpResponse = this.httpClient.execute(httpRequest);
      StatusLine status = httpResponse.getStatusLine();
      httpEntity = httpResponse.getEntity();

      if (httpEntity != null) {
        jsonStr = EntityUtils.toString(httpEntity);
      }

      if (status.getStatusCode() >= 400) {
        log.info("Unable to get response using: " + url);
        JsonElement jsonRet = GSON.fromJson(jsonStr, JsonArray.class);
        throw new RestApiProcessingException(getFirstErrorMessage("Failed to retrieve response from", jsonRet));
      }
    } catch (Exception e) {
      throw new RestApiProcessingException("Failed to process rest api request; error - " + e.getMessage(), e);
    } finally {
      try {
        if (httpEntity != null) {
          EntityUtils.consume(httpEntity);
        }
        // httpResponse.close();
      } catch (Exception e) {
        throw new RestApiProcessingException("Failed to consume httpEntity; error - " + e.getMessage(), e);
      }
    }
    CommandOutput<RestApiCommand, String> output = new RestApiCommandOutput();
    output.put((RestApiCommand) cmds.get(0), jsonStr);
    return output;
  }
535425
protected Api getApiInternal(String organizationId, String apiId, String apiVersion) throws SQLException {
        QueryRunner run = new QueryRunner(ds);
        return run.query("SELECT bean FROM gw_apis WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$
                Handlers.API_HANDLER, organizationId, apiId, apiVersion);
    }
1005131
public ApiResponse<GetArgsResponse> argsWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = argsValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<GetArgsResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
568063
protected List<UserApiKey> fetchApiKeysInternal() {
    final StitchAuthRequest.Builder reqBuilder = new StitchAuthRequest.Builder();
    reqBuilder
            .withMethod(Method.GET)
            .withPath(this.getBaseRoute())
            .withRefreshToken();
    return (List<UserApiKey>) getRequestClient().doAuthenticatedRequest(
            reqBuilder.build(),
            new CollectionDecoder<>(new UserApiKeyDecoder()));
  }
312099
public ApiResponse<UserEnvelope> getSelfWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = getSelfValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<UserEnvelope>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
77258
protected UserApiKey fetchApiKeyInternal(final ObjectId id) {
    final StitchAuthRequest.Builder reqBuilder = new StitchAuthRequest.Builder();
    reqBuilder
            .withMethod(Method.GET)
            .withPath(routes.getApiKeyRouteForId(id.toHexString()))
            .withRefreshToken();
    return getRequestClient().doAuthenticatedRequest(
            reqBuilder.build(),
            new UserApiKeyDecoder()
    );
  }
431302
private <TResponse> TResponse callServiceOwnerPostApi(
            String path, Map<String, String> queryParams,
            Object requestBody, Class<TResponse> responseClass) throws AuthleteApiException
    {
        return callPostApi(mServiceOwnerCredentials, path, queryParams, requestBody, responseClass);
    }
783300
public ApiAppList getApiApps() throws HelloSignException {
        return new ApiAppList(httpClient.withAuth(auth).get(BASE_URI + API_APP_LIST_URI).asJson());
    }
524280
public <T> T getAuthenticationAttribute(final String name, final Class<T> clazz)
    {
        final Object attribute = getAuthenticationAttribute(name);
        return getAttributeByType(name, clazz, attribute);
    }