Skip to content

Commit

Permalink
Fix the 404 error when dispatching
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhashinee committed Nov 11, 2024
1 parent 1a481af commit dcadbe4
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.wso2.micro.integrator.observability.metric.handler;

import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -309,8 +311,22 @@ private void incrementInboundEndpointErrorCount(String name) {
* @return String The api 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);
if (!withVersionsApiList.isEmpty()) {
String apiName = getResolvedApiName(contextPath, synCtx, withVersionsApiList);
if (apiName != null) {
return apiName;
}
}
return getResolvedApiName(contextPath, synCtx, defaultApiList);
}

private static String getResolvedApiName(String contextPath, MessageContext synCtx,
Collection<API> apiList) {
String apiName = null;
for (API api : synCtx.getEnvironment().getSynapseConfiguration().getAPIs()) {
for (API api : apiList) {
String apiContextPath = api.getContext();
if (StringUtils.isNotBlank(api.getVersionStrategy().getVersion())) {
apiContextPath = apiContextPath + "/" + api.getVersionStrategy().getVersion();
Expand All @@ -327,6 +343,26 @@ private String getApiName(String contextPath, MessageContext synCtx) {
return apiName;
}

private Collection<API> getVersionsApiList(Collection<API> apiList) {
Collection<API> withVersionsApiList = new ArrayList<>();
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())) {
defaultApiList.add(api);
}
}
return defaultApiList;
}

/**
* Return the port the service was invoked.
*
Expand Down

0 comments on commit dcadbe4

Please sign in to comment.