[Carbon-commits] [Carbon] svn commit r109023 - branches/carbon/3.2.0/components/stratos/throttling/org.wso2.carbon.throttling.agent/3.2.1/src/main/java/org/wso2/carbon/throttling/agent/listeners
milinda at wso2.com
milinda at wso2.com
Tue Jul 5 01:15:53 EDT 2011
Author: milinda
Date: Mon Jul 4 22:15:53 2011
New Revision: 109023
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=109023
Log:
fix some issues in code.
Modified:
branches/carbon/3.2.0/components/stratos/throttling/org.wso2.carbon.throttling.agent/3.2.1/src/main/java/org/wso2/carbon/throttling/agent/listeners/WebAppRequestListener.java
Modified: branches/carbon/3.2.0/components/stratos/throttling/org.wso2.carbon.throttling.agent/3.2.1/src/main/java/org/wso2/carbon/throttling/agent/listeners/WebAppRequestListener.java
URL: http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/components/stratos/throttling/org.wso2.carbon.throttling.agent/3.2.1/src/main/java/org/wso2/carbon/throttling/agent/listeners/WebAppRequestListener.java?rev=109023&r1=109022&r2=109023&view=diff
==============================================================================
--- branches/carbon/3.2.0/components/stratos/throttling/org.wso2.carbon.throttling.agent/3.2.1/src/main/java/org/wso2/carbon/throttling/agent/listeners/WebAppRequestListener.java (original)
+++ branches/carbon/3.2.0/components/stratos/throttling/org.wso2.carbon.throttling.agent/3.2.1/src/main/java/org/wso2/carbon/throttling/agent/listeners/WebAppRequestListener.java Mon Jul 4 22:15:53 2011
@@ -36,12 +36,17 @@
public class WebAppRequestListener implements CarbonTomcatValve {
private static final Log log = LogFactory.getLog(WebAppRequestListener.class);
- private static final Pattern urlPattern = Pattern.compile("\\/t\\/(.*?)\\/(.*?)\\/");
+
+ private static final Pattern servicesURLPattern = Pattern.compile("\\/services\\/t\\/(.*?)\\/");
+ private static final Pattern webAppsURLPattern = Pattern.compile("\\/webapps\\/t\\/(.*?)\\/");
+
+ private static final String CONTEXT_SERVICES = "services";
+ private static final String CONTEXT_WEBAPPS = "webapps";
public void invoke(HttpServletRequest request, HttpServletResponse response) {
String requestURI = request.getRequestURI();
String tenantDomainName = getTenantName(requestURI);
- String serviceContext = getContext(requestURI);
+ String urlContext = getContext(requestURI);
try {
int tenantId = Util.getRealmService().getTenantManager().getTenantId(tenantDomainName);
if (tenantId <= 0) {
@@ -59,9 +64,9 @@
" tenant Domain: " + tenantDomainName;
log.error(message, e);
}
- } else {
+ } else if(urlContext != null) {
//check weather request come to webapps
- if ("webapps".equals(serviceContext)) {
+ if (CONTEXT_WEBAPPS.equals(urlContext)) {
//if tenant is active we will throttle other parameters such as bandwidth in/out
ValidationInfoRetriever validationInfoRetriever = Util.getValidationInfoRetriever();
String[] actions = new String[]{StratosConstants.THROTTLING_WEBAPP_IN_BANDWIDTH_ACTION,
@@ -97,14 +102,18 @@
}
- /**
+ /**
* Extract tenant domain from request url
- *
* @return tenant domain
*/
- public String getTenantName(String requestUrl) {
- Matcher matcher = urlPattern.matcher(requestUrl);
- if (matcher.find()) {
+ public String getTenantName(String requestUrl){
+ Matcher matcher = servicesURLPattern.matcher(requestUrl);
+ if(matcher.find()){
+ return matcher.group(1);
+ }
+
+ matcher = webAppsURLPattern.matcher(requestUrl);
+ if(matcher.find()){
return matcher.group(1);
}
@@ -113,14 +122,19 @@
/**
* Extract context from the request url
- *
* @return context string
*/
- public String getContext(String requestUrl) {
- Matcher matcher = urlPattern.matcher(requestUrl);
- if (matcher.find()) {
- return matcher.group(2);
+ public String getContext(String requestUrl){
+ Matcher matcher = servicesURLPattern.matcher(requestUrl);
+ if(matcher.find()){
+ return CONTEXT_SERVICES;
+ }
+
+ matcher = webAppsURLPattern.matcher(requestUrl);
+ if(matcher.find()){
+ return CONTEXT_WEBAPPS;
}
+
return null;
}
}
\ No newline at end of file
More information about the Carbon-commits
mailing list