This commit is contained in:
Radek Davidek 2025-10-01 14:44:19 +02:00
parent 84c3511435
commit 2209854f92
3 changed files with 39 additions and 37 deletions

View File

@ -21,6 +21,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import cz.trask.apioperator.config.ConfigManager;
import cz.trask.apioperator.model.APIList;
import cz.trask.apioperator.model.HttpResponse;
import cz.trask.apioperator.model.RegisterResponse;
import cz.trask.apioperator.model.TokenResponse;
@ -263,4 +264,39 @@ public abstract class AbstractProcess {
return resp;
}
/**
* Retrieve the list of APIs by name.
*
* @param tokenResponse - WSO2 APIM access token
* @throws Exception
*/
protected APIList getList(String publisherurl, TokenResponse tokenResponse) throws Exception {
APIList listOfApis = null;
try {
String url = publisherurl.concat(String.format("/apis?limit=9999&offset=0"));
log.debug("Getting APIs with token: '" + tokenResponse.getAccess_token() + "' URL: " + url);
Map<String, String> httpHeaders = new HashMap<>();
Map<String, String> params = new HashMap<>();
httpHeaders.put("Authorization", "Bearer ".concat(tokenResponse.getAccess_token()));
HttpResponse response = makeRequest("GET", url, httpHeaders, params);
log.debug("Listing APIs: HTTP Code " + response.getResponseCode() + " Data: " + response.getResponse());
listOfApis = gson.fromJson(response.getResponse(), APIList.class);
if (response.getResponseCode() != 200)
log.error("Cannot list API. Something bad happened.");
} catch (Exception e) {
log.error("Cannot list API:" + e);
throw new Exception("Cannot list API:" + e.getMessage());
}
return listOfApis;
}
}

View File

@ -3,6 +3,7 @@ package cz.trask.apioperator;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import cz.trask.apioperator.impl.Import;
import cz.trask.apioperator.model.StartParameters;
public class ApiSync {

View File

@ -1,4 +1,4 @@
package cz.trask.apioperator;
package cz.trask.apioperator.impl;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
@ -16,6 +16,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import cz.trask.apioperator.AbstractProcess;
import cz.trask.apioperator.config.ConfigManager;
import cz.trask.apioperator.model.APIInfo;
import cz.trask.apioperator.model.APIList;
@ -365,40 +366,4 @@ public class Import extends AbstractProcess {
}
}
}
/**
* Retrieve the list of APIs by name.
*
* @param tokenResponse - WSO2 APIM access token
* @throws Exception
*/
protected APIList getList(String publisherurl, TokenResponse tokenResponse) throws Exception {
APIList listOfApis = null;
try {
String url = publisherurl.concat(String.format("/apis?limit=9999&offset=0"));
log.debug("Getting APIs with token: '" + tokenResponse.getAccess_token() + "' URL: " + url);
Map<String, String> httpHeaders = new HashMap<>();
Map<String, String> params = new HashMap<>();
httpHeaders.put("Authorization", "Bearer ".concat(tokenResponse.getAccess_token()));
HttpResponse response = makeRequest("GET", url, httpHeaders, params);
log.debug("Listing APIs: HTTP Code " + response.getResponseCode() + " Data: " + response.getResponse());
listOfApis = gson.fromJson(response.getResponse(), APIList.class);
if (response.getResponseCode() != 200)
log.error("Cannot list API. Something bad happened.");
} catch (Exception e) {
log.error("Cannot list API:" + e);
throw new Exception("Cannot list API:" + e.getMessage());
}
return listOfApis;
}
}