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/08 08:52:02 UTC

git commit: adding tenant dispatcher module which was omitted by a mistake

Updated Branches:
  refs/heads/master 62dc2f7f8 -> c8d644bc3


adding tenant dispatcher module which was omitted by a mistake


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

Branch: refs/heads/master
Commit: c8d644bc316b3688082eaa6bc390e3c7d085ab18
Parents: 62dc2f7
Author: Isuru <is...@wso2.com>
Authored: Mon Jul 8 12:21:42 2013 +0530
Committer: Isuru <is...@wso2.com>
Committed: Mon Jul 8 12:21:42 2013 +0530

----------------------------------------------------------------------
 .../2.1.0/pom.xml                               |  93 ++++++++++++
 .../dispatcher/MultitenantDispatcher.java       |  68 +++++++++
 .../TenantDispatcherServiceComponent.java       | 146 +++++++++++++++++++
 3 files changed, 307 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c8d644bc/components/org.apache.stratos.tenant.dispatcher/2.1.0/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.dispatcher/2.1.0/pom.xml b/components/org.apache.stratos.tenant.dispatcher/2.1.0/pom.xml
new file mode 100644
index 0000000..bec3079
--- /dev/null
+++ b/components/org.apache.stratos.tenant.dispatcher/2.1.0/pom.xml
@@ -0,0 +1,93 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <parent>
+        <groupId>org.apache.stratos</groupId>
+        <artifactId>stratos-components-parent</artifactId>
+        <version>2.0.0</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>org.apache.stratos.tenant.dispatcher</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Stratos - Tenant Dispatcher</name>
+
+    <build>
+
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Name>${project.artifactId}</Bundle-Name>
+                        <Private-Package>
+                            org.apache.stratos.tenant.dispatcher.*,
+                        </Private-Package>
+                        <Export-Package>
+                            !org.apache.stratos.tenant.dispatcher.internal.*,
+                            org.apache.stratos.tenant.dispatcher.*
+                        </Export-Package>
+                        <Import-Package>
+                            !javax.xml.namespace,
+                            javax.xml.namespace; version=0.0.0,
+                            javax.servlet;version="${imp.pkg.version.javax.servlet}",
+                            javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+                            *;resolution:=optional
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.axis2.wso2</groupId>
+            <artifactId>axis2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.utils</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c8d644bc/components/org.apache.stratos.tenant.dispatcher/2.1.0/src/main/java/org/apache/stratos/tenant/dispatcher/MultitenantDispatcher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.dispatcher/2.1.0/src/main/java/org/apache/stratos/tenant/dispatcher/MultitenantDispatcher.java b/components/org.apache.stratos.tenant.dispatcher/2.1.0/src/main/java/org/apache/stratos/tenant/dispatcher/MultitenantDispatcher.java
new file mode 100644
index 0000000..beed246
--- /dev/null
+++ b/components/org.apache.stratos.tenant.dispatcher/2.1.0/src/main/java/org/apache/stratos/tenant/dispatcher/MultitenantDispatcher.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.stratos.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/c8d644bc/components/org.apache.stratos.tenant.dispatcher/2.1.0/src/main/java/org/apache/stratos/tenant/dispatcher/internal/TenantDispatcherServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.dispatcher/2.1.0/src/main/java/org/apache/stratos/tenant/dispatcher/internal/TenantDispatcherServiceComponent.java b/components/org.apache.stratos.tenant.dispatcher/2.1.0/src/main/java/org/apache/stratos/tenant/dispatcher/internal/TenantDispatcherServiceComponent.java
new file mode 100644
index 0000000..4d4b9cb
--- /dev/null
+++ b/components/org.apache.stratos.tenant.dispatcher/2.1.0/src/main/java/org/apache/stratos/tenant/dispatcher/internal/TenantDispatcherServiceComponent.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.stratos.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.apache.stratos.tenant.dispatcher.internal.TenantDispatcherServiceComponent"
+ *                immediate="true"
+ * @scr.reference name="org.wso2.carbon.configurationContextService"
+ *                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;
+    }
+}