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

Revert "Fix for https://github.com/wso2/api-manager/issues/2226" #2258

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
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
44 changes: 17 additions & 27 deletions modules/core/src/main/java/org/apache/synapse/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,22 @@ public void process(MessageContext synCtx) {
if (resource != null) {
if (synCtx.getEnvironment().isDebuggerEnabled()) {
if (!synCtx.isResponse()) {
initWirelogHolder(synCtx, resource);
SynapseWireLogHolder wireLogHolder = (SynapseWireLogHolder) ((Axis2MessageContext) synCtx).getAxis2MessageContext()
.getProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY);
if (wireLogHolder == null) {
wireLogHolder = new SynapseWireLogHolder();
}
if (synCtx.getProperty(RESTConstants.SYNAPSE_REST_API) != null && !synCtx.getProperty(RESTConstants.SYNAPSE_REST_API).toString().isEmpty()) {
wireLogHolder.setApiName(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API).toString());
if (resource.getDispatcherHelper() != null) {
if (resource.getDispatcherHelper().getString() != null && !resource.getDispatcherHelper().getString().isEmpty()) {
wireLogHolder.setResourceUrlString(resource.getDispatcherHelper().getString());
}
}
}
((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY, wireLogHolder);
}

}
resource.process(synCtx);
return;
Expand All @@ -468,9 +482,8 @@ public void process(MessageContext synCtx) {
//This will get executed only in unhappy path. So ok to have the iterator.
boolean resourceFound = false;
boolean matchingMethodFound = false;
Resource resource = null;
for (RESTDispatcher dispatcher : ApiUtils.getDispatchers()) {
resource = dispatcher.findResource(synCtx, resources.values());
Resource resource = dispatcher.findResource(synCtx, resources.values());
if (resource != null) {
resourceFound = true;
String method = (String) msgCtx.getProperty(Constants.Configuration.HTTP_METHOD);
Expand All @@ -481,13 +494,7 @@ public void process(MessageContext synCtx) {
if (!resourceFound) {
handleResourceNotFound(synCtx);
} else if (!matchingMethodFound) {
String method = (String) synCtx.getProperty(RESTConstants.REST_METHOD);
if (RESTConstants.METHOD_OPTIONS.equals(method)) {
initWirelogHolder(synCtx, resource);
resource.process(synCtx);
} else {
handleMethodNotAllowed(synCtx);
}
handleMethodNotAllowed(synCtx);
} else {
//Resource found, and matching method also found, which means request is BAD_REQUEST(400)
msgCtx.setProperty(SynapseConstants.HTTP_SC, HttpStatus.SC_BAD_REQUEST);
Expand All @@ -496,23 +503,6 @@ public void process(MessageContext synCtx) {
}
}

private static void initWirelogHolder(MessageContext synCtx, Resource resource) {
SynapseWireLogHolder wireLogHolder = (SynapseWireLogHolder) ((Axis2MessageContext) synCtx).getAxis2MessageContext()
.getProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY);
if (wireLogHolder == null) {
wireLogHolder = new SynapseWireLogHolder();
}
if (synCtx.getProperty(RESTConstants.SYNAPSE_REST_API) != null && !synCtx.getProperty(RESTConstants.SYNAPSE_REST_API).toString().isEmpty()) {
wireLogHolder.setApiName(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API).toString());
if (resource.getDispatcherHelper() != null) {
if (resource.getDispatcherHelper().getString() != null && !resource.getDispatcherHelper().getString().isEmpty()) {
wireLogHolder.setResourceUrlString(resource.getDispatcherHelper().getString());
}
}
}
((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY, wireLogHolder);
}

private void handleMethodNotAllowed(MessageContext synCtx) {

auditDebug("Method not allowed for the request: " + synCtx.getMessageID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ public String[] getMethods() {
* @return true if support false otherwise.
*/
public boolean hasMatchingMethod(String method) {
if (!methods.isEmpty()) {
if (RESTConstants.METHOD_OPTIONS.equals(method)) {
return true; // OPTIONS requests are always welcome
} else if (!methods.isEmpty()) {
if (!methods.contains(method)) {
if (log.isDebugEnabled()) {
log.debug("HTTP method does not match");
Expand Down Expand Up @@ -249,7 +251,9 @@ boolean canProcess(MessageContext synCtx) {
String method = (String) msgCtx.getProperty(Constants.Configuration.HTTP_METHOD);
synCtx.setProperty(RESTConstants.REST_METHOD, method);

if (!methods.isEmpty()) {
if (RESTConstants.METHOD_OPTIONS.equals(method)) {
return true; // OPTIONS requests are always welcome
} else if (!methods.isEmpty()) {
if (!methods.contains(method)) {
if (log.isDebugEnabled()) {
log.debug("HTTP method does not match");
Expand Down
Loading