You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/07 12:33:02 UTC

git commit: refactoring org.wso2.carbon.tenant.dispatcher component to org.apache.stratos.tenant.dispatcher

Updated Branches:
  refs/heads/master 3c5a99635 -> 0763d6f91


refactoring org.wso2.carbon.tenant.dispatcher component to org.apache.stratos.tenant.dispatcher

Signed-off-by: Isuru <is...@wso2.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/0763d6f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/0763d6f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/0763d6f9

Branch: refs/heads/master
Commit: 0763d6f91ec11f4fa16029a54935b40f62291344
Parents: 3c5a996
Author: Pradeep Fernando <pr...@gmail.com>
Authored: Sun Jul 7 09:46:22 2013 +0530
Committer: Isuru <is...@wso2.com>
Committed: Sun Jul 7 16:02:14 2013 +0530

----------------------------------------------------------------------
 components/pom.xml                              |   6 +
 .../dispatcher/MultitenantDispatcher.java       |  65 ---------
 .../TenantDispatcherServiceComponent.java       | 143 -------------------
 3 files changed, 6 insertions(+), 208 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0763d6f9/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 379b344..a4fea2d 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -67,6 +67,7 @@
            	<module>autoscaler-service/org.apache.stratos.autoscaler.service/4.1.0</module>
 		<!-- COMMON -->
 		<module>org.apache.stratos.common/2.1.2</module>
+		<module>org.apache.stratos.tenant.dispatcher/2.1.0</module>
 	    </modules>
 	    
 	    <build>
@@ -182,6 +183,11 @@
             <artifactId>org.wso2.carbon.user.mgt</artifactId>
             <version>${carbon.platform.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.utils</artifactId>
+            <version>${carbon.platform.version}</version>
+        </dependency>
 	
 	<!-- Axis2 -->
         <dependency>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0763d6f9/components/stratos/org.wso2.carbon.tenant.dispatcher/2.1.0/src/main/java/org/wso2/carbon/tenant/dispatcher/MultitenantDispatcher.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.tenant.dispatcher/2.1.0/src/main/java/org/wso2/carbon/tenant/dispatcher/MultitenantDispatcher.java b/components/stratos/org.wso2.carbon.tenant.dispatcher/2.1.0/src/main/java/org/wso2/carbon/tenant/dispatcher/MultitenantDispatcher.java
deleted file mode 100644
index 02e8193..0000000
--- a/components/stratos/org.wso2.carbon.tenant.dispatcher/2.1.0/src/main/java/org/wso2/carbon/tenant/dispatcher/MultitenantDispatcher.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*                                                                             
- * Copyright 2004,2005 The Apache Software Foundation.                         
- *                                                                             
- * Licensed under the Apache License, Version 2.0 (the "License");             
- * you may not use this file except in compliance with the License.            
- * You may obtain a copy of the License at                                     
- *                                                                             
- *      http://www.apache.org/licenses/LICENSE-2.0                             
- *                                                                             
- * Unless required by applicable law or agreed to in writing, software         
- * distributed under the License is distributed on an "AS IS" BASIS,           
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
- * See the License for the specific language governing permissions and         
- * limitations under the License.                                              
- */
-package org.wso2.carbon.tenant.dispatcher;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.HandlerDescription;
-import org.apache.axis2.engine.AbstractDispatcher;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-import javax.xml.namespace.QName;
-
-/**
- * If none of the dispatcher were able to find an Axis2 service or operation, this dispatcher will
- * be reached, and it will dispatch to the MultitenantService, which is associated with the
- * {@link org.wso2.carbon.core.multitenancy.MultitenantMessageReceiver}
- */
-public class MultitenantDispatcher extends AbstractDispatcher {
-
-    public static final String NAME = "MultitenantDispatcher";
-
-    public void initDispatcher() {
-        QName qn = new QName("http://wso2.org/projects/carbon", NAME);
-        HandlerDescription hd = new HandlerDescription(qn.getLocalPart());
-        super.init(hd);
-    }
-
-    public AxisService findService(MessageContext mc) throws AxisFault {
-        AxisService service = mc.getAxisService();
-        if (service == null) {
-            String to = mc.getTo().getAddress();
-
-            int tenantDelimiterIndex = to.indexOf("/t/");
-            if (tenantDelimiterIndex != -1) {
-                AxisConfiguration ac = mc.getConfigurationContext().getAxisConfiguration();
-                return ac.getService(MultitenantConstants.MULTITENANT_DISPATCHER_SERVICE);
-            }
-        }
-        return service;
-    }
-
-    public AxisOperation findOperation(AxisService svc, MessageContext mc) throws AxisFault {
-        AxisOperation operation = mc.getAxisOperation();
-        if (operation == null) {
-            return svc.getOperation(MultitenantConstants.MULTITENANT_DISPATCHER_OPERATION);
-        }
-        return operation;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0763d6f9/components/stratos/org.wso2.carbon.tenant.dispatcher/2.1.0/src/main/java/org/wso2/carbon/tenant/dispatcher/internal/TenantDispatcherServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.tenant.dispatcher/2.1.0/src/main/java/org/wso2/carbon/tenant/dispatcher/internal/TenantDispatcherServiceComponent.java b/components/stratos/org.wso2.carbon.tenant.dispatcher/2.1.0/src/main/java/org/wso2/carbon/tenant/dispatcher/internal/TenantDispatcherServiceComponent.java
deleted file mode 100644
index fa81550..0000000
--- a/components/stratos/org.wso2.carbon.tenant.dispatcher/2.1.0/src/main/java/org/wso2/carbon/tenant/dispatcher/internal/TenantDispatcherServiceComponent.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*                                                                             
- * Copyright 2004,2005 The Apache Software Foundation.                         
- *                                                                             
- * Licensed under the Apache License, Version 2.0 (the "License");             
- * you may not use this file except in compliance with the License.            
- * You may obtain a copy of the License at                                     
- *                                                                             
- *      http://www.apache.org/licenses/LICENSE-2.0                             
- *                                                                             
- * Unless required by applicable law or agreed to in writing, software         
- * distributed under the License is distributed on an "AS IS" BASIS,           
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    
- * See the License for the specific language governing permissions and         
- * limitations under the License.                                              
- */
-package org.wso2.carbon.tenant.dispatcher.internal;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.AxisServiceGroup;
-import org.apache.axis2.description.HandlerDescription;
-import org.apache.axis2.description.InOutAxisOperation;
-import org.apache.axis2.description.PhaseRule;
-import org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.axis2.engine.Handler;
-import org.apache.axis2.engine.Phase;
-import org.apache.axis2.phaseresolver.PhaseException;
-import org.apache.axis2.phaseresolver.PhaseMetadata;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.osgi.service.component.ComponentContext;
-import org.wso2.carbon.CarbonConstants;
-import org.wso2.carbon.core.multitenancy.MultitenantDispatcher;
-import org.wso2.carbon.core.multitenancy.MultitenantMessageReceiver;
-import org.wso2.carbon.utils.ConfigurationContextService;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-import java.util.List;
-
-/**
- * @scr.component
- *                name="org.wso2.carbon.tenant.dispatcher.internal.TenantDispatcherServiceComponent"
- *                immediate="true"
- * @scr.reference name="org.wso2.carbon.configCtx"
- *                interface="org.wso2.carbon.utils.ConfigurationContextService"
- *                cardinality="1..1" policy="dynamic"
- *                bind="setConfigurationContext"
- *                unbind="unsetConfigurationContext"
- */
-public class TenantDispatcherServiceComponent {
-    private Log log = LogFactory.getLog(TenantDispatcherServiceComponent.class);
-
-    private ConfigurationContext configCtx;
-
-    protected void activate(ComponentContext ctxt) {
-        try {
-            deployMultitenantService(configCtx.getAxisConfiguration());
-            addDispatchers(configCtx.getAxisConfiguration());
-        } catch (Throwable e) {
-            log.error("Failed to activate the TenantDispatcherServiceComponent", e);
-        }
-    }
-
-
-    private void deployMultitenantService(AxisConfiguration axisCfg) throws AxisFault {
-        AxisService service = new AxisService(MultitenantConstants.MULTITENANT_DISPATCHER_SERVICE);
-        AxisOperation operation =
-                new InOutAxisOperation(MultitenantConstants.MULTITENANT_DISPATCHER_OPERATION);
-        operation.setMessageReceiver(new MultitenantMessageReceiver());
-        service.addOperation(operation);
-        AxisServiceGroup multitenantSvcGroup = new AxisServiceGroup(axisCfg);
-        multitenantSvcGroup.setServiceGroupName(MultitenantConstants.MULTITENANT_DISPATCHER_SERVICE);
-        multitenantSvcGroup.addParameter(CarbonConstants.HIDDEN_SERVICE_PARAM_NAME, "true");
-        multitenantSvcGroup.addService(service);
-        axisCfg.addServiceGroup(multitenantSvcGroup);
-		if(log.isDebugEnabled()){
-			log.debug("Deployed " + MultitenantConstants.MULTITENANT_DISPATCHER_SERVICE);
-		}
-    }
-
-    /**
-     * Add the MultitenantDispatcher to the inFlow phase.
-     *
-     * @param mainAxisConfig super-tenant AxisConfiguration
-     * @throws org.apache.axis2.AxisFault if an error occurs while adding the dispatcher
-     */
-    private void addDispatchers(AxisConfiguration mainAxisConfig) throws AxisFault {
-        HandlerDescription handlerDescription = new HandlerDescription(MultitenantDispatcher.NAME);
-        PhaseRule rule = new PhaseRule(PhaseMetadata.PHASE_DISPATCH);
-        rule.setAfter(HTTPLocationBasedDispatcher.NAME);
-        rule.setBefore("SynapseDispatcher");
-        handlerDescription.setRules(rule);
-
-        MultitenantDispatcher multitenantDispatcher = new MultitenantDispatcher();
-        multitenantDispatcher.initDispatcher();
-        handlerDescription.setHandler(multitenantDispatcher);
-
-        List<Phase> inflowPhases
-                = mainAxisConfig.getInFlowPhases();
-        for (Phase inPhase : inflowPhases) {
-            // we are interested about the Dispatch phase in the inflow
-            if (PhaseMetadata.PHASE_DISPATCH.equals(inPhase.getPhaseName())) {
-                boolean handlerFound = false;
-                for (Handler handler : inPhase.getHandlers()) {
-                    if (handler.getHandlerDesc().getName() != null &&
-                            handler.getHandlerDesc().getName().equals(MultitenantDispatcher.NAME)) {
-                        handlerFound = true;
-                    }
-                }
-                if (!handlerFound) {
-                    try {
-                        inPhase.addHandler(handlerDescription);
-                    } catch (PhaseException e) {
-                        String msg = "Couldn't start Carbon, Cannot add " +
-                                "the required Carbon handlers";
-                        log.fatal(msg, e);
-                        throw new AxisFault(msg);
-                    }
-                }
-            }
-        }
-		if (log.isDebugEnabled()) {
-			log.info("Added multitenant dispatchers");
-		}
-    }
-
-    protected void deactivate(ComponentContext ctxt) {
-        if (log.isDebugEnabled()) {
-            log.debug("Deactivated TenantDispatcherServiceComponent");
-        }
-    }
-
-    protected void setConfigurationContext(ConfigurationContextService configCtx) {
-        this.configCtx = configCtx.getServerConfigContext();
-    }
-
-    protected void unsetConfigurationContext(ConfigurationContextService configCtx) {
-        this.configCtx = null;
-    }
-}