Skip to content

Commit

Permalink
Merge pull request #2259 from dakshina99/options-resource-backend-route
Browse files Browse the repository at this point in the history
[APIM] Bring the OPTIONS Resource to the 0th Index of the acceptableResourcesList
  • Loading branch information
tharindu1st authored Dec 10, 2024
2 parents b956cd9 + daaa049 commit b1a67cd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions modules/core/src/main/java/org/apache/synapse/api/ApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -184,13 +186,17 @@ public static boolean isBound(Resource resource, MessageContext synCtx) {
}

public static Set<Resource> getAcceptableResources(Map<String, Resource> resources, MessageContext synCtx) {
Set<Resource> acceptableResources = new LinkedHashSet<Resource>();
List<Resource> acceptableResourcesList = new LinkedList<>();
for (Resource r : resources.values()) {
if (isBound(r, synCtx) && r.canProcess(synCtx)) {
acceptableResources.add(r);
if (Arrays.asList(r.getMethods()).contains(RESTConstants.METHOD_OPTIONS)) {
acceptableResourcesList.add(0, r);
} else {
acceptableResourcesList.add(r);
}
}
}
return acceptableResources;
return new LinkedHashSet<Resource>(acceptableResourcesList);
}

/**
Expand Down

0 comments on commit b1a67cd

Please sign in to comment.