Skip to content

Commit

Permalink
Merge pull request #2258 from dakshina99/revert-2114-master
Browse files Browse the repository at this point in the history
Revert "Fix for wso2/api-manager#2226"
  • Loading branch information
tharindu1st authored Dec 10, 2024
2 parents b1a67cd + 1abf90d commit 66c89a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
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

0 comments on commit 66c89a3

Please sign in to comment.