Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an array to contain API file names for iterating #2274

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -567,35 +567,49 @@ private static void createSynapseImports(SynapseConfiguration synapseConfig, Str
private static void createAPIs(SynapseConfiguration synapseConfig,
String rootDirPath, Properties properties) {

File apiDir = new File(rootDirPath, REST_API_DIR);
if (apiDir.exists()) {
if (log.isDebugEnabled()) {
log.debug("Loading APIs from :" + apiDir.getPath());
}

Iterator apiIterator = FileUtils.iterateFiles(apiDir, extensions, false);
while (apiIterator.hasNext()) {
File file = (File) apiIterator.next();
try {
OMElement document = getOMElement(file);
API api = SynapseXMLConfigurationFactory.defineAPI(synapseConfig, document, properties, false);
if (api != null) {
api.setFileName(file.getName());
synapseConfig.getArtifactDeploymentStore().addArtifact(file.getAbsolutePath(),
api.getName());
try {
File apiDir = new File(rootDirPath, REST_API_DIR);
if (apiDir.exists()) {
if (log.isDebugEnabled()) {
log.debug("Loading APIs from :" + apiDir.getPath());
}
String[] apiFileDirectories = apiDir.list((dir, name) -> {
for (String extension : extensions) {
if (name.endsWith(extension)) {
return true;
}
}
return false;
});
if (apiFileDirectories != null) {
for (String fileName : apiFileDirectories) {
try {
File file = new File(apiDir, fileName);
OMElement document = getOMElement(file);
API api = SynapseXMLConfigurationFactory.defineAPI(synapseConfig, document, properties,
false);
if (api != null) {
api.setFileName(file.getName());
synapseConfig.getArtifactDeploymentStore()
.addArtifact(file.getAbsolutePath(), api.getName());
}
} catch (Exception e) {
String msg = "API configuration cannot be built from: " + fileName;
handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_API, msg, e);
}
}
}
// order the apis based on context descending order
try {
SynapseXMLConfigurationFactory.reOrderAPIs(synapseConfig);
} catch (Exception e) {
String msg = "API configuration cannot be built from : " + file.getName();
String msg = "Error while re-ordering apis";
handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_API, msg, e);
}
}
// order the apis based on context descending order
try {
SynapseXMLConfigurationFactory.reOrderAPIs(synapseConfig);
} catch (Exception e) {
String msg = "Error while re-ordering apis";
handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_API, msg, e);
}
} catch (Exception e) {
String msg = "Error loading APIs";
handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_API, msg, e);
}
}

Expand Down
Loading