Skip to content

Commit

Permalink
Update the API list generation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhashinee committed Nov 11, 2024
1 parent 5dde35a commit 3ea3869
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ private void incrementInboundEndpointErrorCount(String name) {
*/
private String getApiName(String contextPath, MessageContext synCtx) {
Collection<API> apiList = synCtx.getEnvironment().getSynapseConfiguration().getAPIs();
Collection<API> withVersionsApiList = getVersionsApiList(apiList);
Collection<API> defaultApiList = getDefaultApiList(apiList);
Collection<API> withVersionsApiList = new ArrayList<>();
Collection<API> defaultApiList = new ArrayList<>();
updateApiLists(apiList, withVersionsApiList, defaultApiList);
if (!withVersionsApiList.isEmpty()) {
String apiName = getResolvedApiName(contextPath, synCtx, withVersionsApiList);
if (apiName != null) {
Expand All @@ -340,24 +341,15 @@ private static String getResolvedApiName(String contextPath, MessageContext synC
return apiName;
}

private Collection<API> getVersionsApiList(Collection<API> apiList) {
Collection<API> withVersionsApiList = new ArrayList<>();
private void updateApiLists(Collection<API> apiList, Collection<API> withVersionsApiList,
Collection<API> defaultApiList) {
for (API api : apiList) {
if (StringUtils.isNotBlank(api.getVersionStrategy().getVersion())) {
withVersionsApiList.add(api);
}
}
return withVersionsApiList;
}

private Collection<API> getDefaultApiList(Collection<API> apiList) {
Collection<API> defaultApiList = new ArrayList<>();
for (API api : apiList) {
if (!StringUtils.isNotBlank(api.getVersionStrategy().getVersion())) {
} else {
defaultApiList.add(api);
}
}
return defaultApiList;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ protected void activate(ComponentContext ctxt) {
}
SynapseEnvironment synapseEnvironment = contextInfo.getSynapseEnvironment();
List handlers = synapseEnvironment.getSynapseHandlers();
if (System.getProperty(ServiceBusConstants.ENABLE_PROMETHEUS_API_PROPERTY) != null
&& System.getProperty(ServiceBusConstants.ENABLE_PROMETHEUS_API_PROPERTY).equals("false")) {
String prometheusApiEnabled = System.getProperty(ServiceBusConstants.ENABLE_PROMETHEUS_API_PROPERTY);
if ("false".equals(prometheusApiEnabled)) {
handlers.remove(handlers.stream().filter(c -> c instanceof MetricHandler).findFirst().orElse(null));
} else {
} else if ("true".equals(prometheusApiEnabled)) {
if (!handlers.stream().anyMatch(c -> c instanceof MetricHandler)) {
handlers.add(new MetricHandler());
}
Expand Down

0 comments on commit 3ea3869

Please sign in to comment.