in modules/core/src/main/java/org/apache/synapse/rest/API.java [165:245]
boolean canProcess(MessageContext synCtx) {
if (synCtx.isResponse()) {
String apiName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_REST_API);
Object versionObj = synCtx.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
String version = "";
if (versionObj != null) {
version = (String) versionObj;
}
if (!name.equals(apiName) || !versionStrategy.getVersion().equals(version)) {
return false;
}
} else {
String path = RESTUtils.getFullRequestPath(synCtx);
if (!path.startsWith(context + "/") && !path.startsWith(context + "?") &&
!context.equals(path) && !"/".equals(context)) {
if (log.isDebugEnabled()) {
log.debug("API context: " + context + " does not match request URI: " + path);
}
return false;
}
if(!versionStrategy.isMatchingVersion(synCtx)){
return false;
}
org.apache.axis2.context.MessageContext msgCtx =
((Axis2MessageContext) synCtx).getAxis2MessageContext();
if (host != null || port != -1) {
String hostHeader = getHostHeader(msgCtx);
if (hostHeader != null) {
if (host != null && !host.equals(extractHostName(hostHeader))) {
if (log.isDebugEnabled()) {
log.debug("API host: " + host + " does not match host information " +
"in the request: " + hostHeader);
}
return false;
}
if (port != -1 && port != extractPortNumber(hostHeader,
msgCtx.getIncomingTransportName())) {
if (log.isDebugEnabled()) {
log.debug("API port: " + port + " does not match port information " +
"in the request: " + hostHeader);
}
return false;
}
} else {
if (log.isDebugEnabled()) {
log.debug("Host information not available on the message");
}
return false;
}
}
if (protocol == RESTConstants.PROTOCOL_HTTP_ONLY &&
!Constants.TRANSPORT_HTTP.equals(msgCtx.getIncomingTransportName())) {
if (log.isDebugEnabled()) {
log.debug("Protocol information does not match - Expected HTTP");
}
synCtx.setProperty(RESTConstants.REST_API_TRANSPORT_DENIED, true);
synCtx.setProperty(RESTConstants.REST_API_IN_TRANSPORT,
msgCtx.getIncomingTransportName());
log.warn("Trying to access API : " + name + " on restricted transport chanel [" +
msgCtx.getIncomingTransportName() + "]");
return false;
} else if (protocol == RESTConstants.PROTOCOL_HTTPS_ONLY &&
!Constants.TRANSPORT_HTTPS.equals(msgCtx.getIncomingTransportName())) {
if (log.isDebugEnabled()) {
log.debug("Protocol information does not match - Expected HTTPS");
}
synCtx.setProperty(RESTConstants.REST_API_TRANSPORT_DENIED, true);
synCtx.setProperty(RESTConstants.REST_API_IN_TRANSPORT,
msgCtx.getIncomingTransportName());
log.warn("Trying to access API : " + name + " on restricted transport chanel [" +
msgCtx.getIncomingTransportName() + "]");
return false;
}
}
return true;
}