2 new revisions:

Revision: aa800298f337
Author:   josemrecio <[email protected]>
Date:     Fri Aug 10 15:13:00 2012
Log:      Update Issue 147...
http://code.google.com/p/sipservlets/source/detail?r=aa800298f337

Revision: bab128ed2961
Author:   Jean Deruelle <[email protected]>
Date:     Sun Aug 12 14:18:09 2012
Log:      Update Issue 147...
http://code.google.com/p/sipservlets/source/detail?r=bab128ed2961

==============================================================================
Revision: aa800298f337
Author:   josemrecio <[email protected]>
Date:     Fri Aug 10 15:13:00 2012
Log:      Update Issue 147

Backport to TelScale branch

Added a new deployer to sip subsystem: SipComponentProcessor (based on WebComponentProcessor)

This deployer builds ComponentConfigurations (based on sip annotations and sip.xml metadata) so they can be picked up afterwards by EEModuleConfigurationProcessor and ModuleJndiBindingProcessor.

Not sure is the treatment of items with not null description is correct, tests have worked fine.
(cherry picked from commit 9432f6159ae91f80eb5ca0c11504279d3f61b10c)

http://code.google.com/p/sipservlets/source/detail?r=aa800298f337

Added:
/containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipComponentProcessor.java
Modified:
/containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/SipMessages.java /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/SipSubsystemAdd.java

=======================================
--- /dev/null
+++ /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipComponentProcessor.java Fri Aug 10 15:13:00 2012
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.mobicents.as7.deployment;
+
+import static org.mobicents.as7.SipMessages.MESSAGES;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.as.ee.component.Attachments;
+import org.jboss.as.ee.component.ComponentDescription;
+import org.jboss.as.ee.component.EEApplicationClasses;
+import org.jboss.as.ee.component.EEModuleDescription;
+import org.jboss.as.ee.structure.DeploymentType;
+import org.jboss.as.ee.structure.DeploymentTypeMarker;
+import org.jboss.as.server.deployment.DeploymentPhaseContext;
+import org.jboss.as.server.deployment.DeploymentUnit;
+import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
+import org.jboss.as.server.deployment.DeploymentUnitProcessor;
+import org.jboss.as.server.deployment.annotation.CompositeIndex;
+//import org.jboss.as.web.deployment.WebAttachments;
+import org.jboss.as.web.deployment.WebAttachments;
+import org.jboss.as.web.deployment.component.ComponentInstantiator;
+import org.jboss.as.web.deployment.component.ManagedBeanComponentInstantiator;
+import org.jboss.as.web.deployment.component.WebComponentDescription;
+import org.jboss.as.web.deployment.component.WebComponentInstantiator;
+import org.jboss.metadata.web.spec.ListenerMetaData;
+import org.jboss.metadata.web.spec.ServletMetaData;
+import org.mobicents.metadata.sip.spec.SipAnnotationMetaData;
+import org.mobicents.metadata.sip.spec.SipMetaData;
+
+/**
+ * Processor that figures out what type of component a servlet/listener is, and registers the appropriate metadata.
+ * The different types are:
+ * <ul>
+ * <li>Managed Bean - If the servlet is annotated with the <code>ManagedBean</code> annotation</li>
+ * <li>CDI Bean - If the servlet is deployed in a bean archive</li>
+ * <li>EE Component - If this is an EE deployment and the servlet is not one of the above</li>
+ * <li>Normal Servlet - If the EE subsystem is disabled</li>
+ * </ul>
+ * <p/>
+ * For ManagedBean Servlets no action is necessary at this stage, as the servlet is already registered as a component. + * For CDI and EE components a component definition is added to the deployment.
+ * <p/>
+ * For now we are just using managed bean components as servlets. We may need a custom component type in future.
+ */
+public class SipComponentProcessor implements DeploymentUnitProcessor {
+
+//    /**
+//     * Tags in these packages do not need to be computerized
+//     */
+// private static final String[] BUILTIN_TAGLIBS = {"org.apache.taglibs.standard", "com.sun.faces.taglib.jsf_core", "com.sun.faces.ext.taglib", "com.sun.faces.taglib.html_basic",};
+
+//    /**
+//     * Dotname for AsyncListener, which can be injected dynamically.
+//     */
+// private static final DotName ASYNC_LISTENER_INTERFACE = DotName.createSimple(AsyncListener.class.getName());
+
+    @Override
+ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { + final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
+
+ if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
+            return;
+        }
+
+ final Map<String, ComponentDescription> componentByClass = new HashMap<String, ComponentDescription>(); + //final Map<String, ComponentInstantiator> webComponents = new HashMap<String, ComponentInstantiator>(); + Map<String, ComponentInstantiator> webComponents = deploymentUnit.getAttachment(WebAttachments.WEB_COMPONENT_INSTANTIATORS);
+        if (webComponents == null) {
+               webComponents = new HashMap<String, ComponentInstantiator>();
+ deploymentUnit.putAttachment(WebAttachments.WEB_COMPONENT_INSTANTIATORS, webComponents);
+        }
+ final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); + final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION); + final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
+        if (moduleDescription == null) {
+            return; //not an ee deployment
+        }
+ for (ComponentDescription component : moduleDescription.getComponentDescriptions()) { + componentByClass.put(component.getComponentClassName(), component);
+        }
+
+ final SipMetaData sipMetaData = deploymentUnit.getAttachment(SipMetaData.ATTACHMENT_KEY); + final SipAnnotationMetaData sipAnnotationMetaData = deploymentUnit.getAttachment(SipAnnotationMetaData.ATTACHMENT_KEY);
+        if (sipMetaData == null && sipAnnotationMetaData == null) {
+               // not a sip deployment
+               return;
+        }
+ final Set<String> classes = getAllComponentClasses(deploymentUnit, compositeIndex, sipMetaData, sipAnnotationMetaData);
+        for (String clazz : classes) {
+            if (clazz == null || clazz.trim().isEmpty()) {
+                continue;
+            }
+            ComponentDescription description = componentByClass.get(clazz);
+            if (description != null) {
+//                //for now just make sure it has a single view
+// //this will generally be a managed bean, but it could also be an EJB
+//                //TODO: make sure the component is a managed bean
+//                if (!(description.getViews().size() == 1)) {
+//                    throw MESSAGES.wrongComponentType(clazz);
+//                }
+// ManagedBeanComponentInstantiator instantiator = new ManagedBeanComponentInstantiator(deploymentUnit, description);
+//                webComponents.put(clazz, instantiator);
+            } else {
+ description = new WebComponentDescription(clazz, clazz, moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
+                moduleDescription.addComponent(description);
+ webComponents.put(clazz, new WebComponentInstantiator(deploymentUnit, description));
+            }
+        }
+ //deploymentUnit.putAttachment(WebAttachments.WEB_COMPONENT_INSTANTIATORS, webComponents);
+    }
+
+    @Override
+    public void undeploy(DeploymentUnit context) {
+    }
+
+    /**
+     * Gets all classes that are eligible for injection etc
+     *
+     * @param metaData
+     * @return
+     */
+ private Set<String> getAllComponentClasses(DeploymentUnit deploymentUnit, CompositeIndex index, SipMetaData sipMetaData, SipAnnotationMetaData sipAnnotationMetaData) {
+        final Set<String> classes = new HashSet<String>();
+        if (sipAnnotationMetaData != null)  {
+ for (Map.Entry<String, SipMetaData> metaData : sipAnnotationMetaData.entrySet()) {
+                getAllComponentClasses(metaData.getValue(), classes);
+            }
+        }
+//        if (metaData.getAnnotationsMetaData() != null)
+// for (Map.Entry<String, WebMetaData> webMetaData : metaData.getAnnotationsMetaData().entrySet()) {
+//                getAllComponentClasses(webMetaData.getValue(), classes);
+//            }
+//        if (metaData.getSharedWebMetaData() != null)
+// getAllComponentClasses(metaData.getSharedWebMetaData(), classes);
+//        if (metaData.getWebFragmentsMetaData() != null)
+// for (Map.Entry<String, WebFragmentMetaData> webMetaData : metaData.getWebFragmentsMetaData().entrySet()) {
+//                getAllComponentClasses(webMetaData.getValue(), classes);
+//            }
+        if (sipMetaData != null) {
+          getAllComponentClasses(sipMetaData, classes);
+        }
+//        if (metaData.getWebMetaData() != null)
+//            getAllComponentClasses(metaData.getWebMetaData(), classes);
+//        if (tldsMetaData == null)
+//            return classes;
+//        if (tldsMetaData.getSharedTlds(deploymentUnit) != null)
+// for (TldMetaData tldMetaData : tldsMetaData.getSharedTlds(deploymentUnit)) {
+//                getAllComponentClasses(tldMetaData, classes);
+//            }
+//        if (tldsMetaData.getTlds() != null)
+// for (Map.Entry<String, TldMetaData> tldMetaData : tldsMetaData.getTlds().entrySet()) {
+//                getAllComponentClasses(tldMetaData.getValue(), classes);
+//            }
+//        getAllAsyncListenerClasses(index, classes);
+        return classes;
+    }
+
+ private void getAllComponentClasses(SipMetaData sipMetaData, Set<String> classes) {
+        if (sipMetaData.getSipServlets() != null) {
+            for (ServletMetaData servlet : sipMetaData.getSipServlets()) {
+                if (servlet.getServletClass() != null) {
+                    classes.add(servlet.getServletClass());
+                }
+            }
+        }
+        if (sipMetaData.getListeners() != null) {
+            for (ListenerMetaData listener : sipMetaData.getListeners()) {
+                classes.add(listener.getListenerClass());
+            }
+        }
+    }
+}
=======================================
--- /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/SipMessages.java Fri Aug 10 09:37:28 2012 +++ /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/SipMessages.java Fri Aug 10 15:13:00 2012
@@ -60,6 +60,9 @@
@Message(id = 18027, value = "Failed to add Mobicents SIP deployment service")
     String failedToAddSipDeployment();

+ @Message(id = 18043, value = "%s has the wrong component type, it cannot be used as a SIP component")
+    RuntimeException wrongComponentType(String clazz);
+
     /**
      * A message indicating the metric is unknown.
      *
=======================================
--- /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/SipSubsystemAdd.java Fri Aug 10 07:50:10 2012 +++ /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/SipSubsystemAdd.java Fri Aug 10 15:13:00 2012
@@ -47,19 +47,22 @@
import org.mobicents.as7.clustering.sip.MockDistributedCacheManagerFactoryService;
 import org.mobicents.as7.deployment.AttachSipServerServiceProcessor;
 import org.mobicents.as7.deployment.SipAnnotationDeploymentProcessor;
+import org.mobicents.as7.deployment.SipComponentProcessor;
 import org.mobicents.as7.deployment.SipContextFactoryDeploymentProcessor;
 import org.mobicents.as7.deployment.SipJndiBindingProcessor;
 import org.mobicents.as7.deployment.SipParsingDeploymentProcessor;
 import org.mobicents.as7.deployment.SipWarDeploymentProcessor;

 /**
- * Adds the web subsystem.
+ * Adds the sip subsystem.
  *
  * @author Emanuel Muckenhuber
  * @author [email protected]
  */
 class SipSubsystemAdd extends AbstractBoottimeAddStepHandler {

+ // FIXME: these priorities should be substituted by values from with org.jboss.as.server.deployment.Phase
+       //   aligned with those used by web subsystem
     static int PARSE_SIP_DEPLOYMENT_PRIORITY = 0x4000;
     static int SIP_ANNOTATION_DEPLOYMENT_PRIORITY = 0x5000;
     static int SIP_CONTEXT_FACTORY_DEPLOYMENT_PRIORITY = 0x6000;
@@ -200,6 +203,9 @@
processorTarget.addDeploymentProcessor(SipExtension.SUBSYSTEM_NAME, Phase.PARSE, PARSE_SIP_DEPLOYMENT_PRIORITY, new SipParsingDeploymentProcessor());
                 // handles annotations
processorTarget.addDeploymentProcessor(SipExtension.SUBSYSTEM_NAME, Phase.PARSE, SIP_ANNOTATION_DEPLOYMENT_PRIORITY, new SipAnnotationDeploymentProcessor()); + // creates component's configurations (mainly for resolving reference annotations) + // FIXME: should this priority be Phase.PARSE_WEB_COMPONENTS + 1? + processorTarget.addDeploymentProcessor(SipExtension.SUBSYSTEM_NAME, Phase.PARSE, SIP_ANNOTATION_DEPLOYMENT_PRIORITY + 1, new SipComponentProcessor()); // attach SipServer to deployment unit (so we can recover it from the sip context) processorTarget.addDeploymentProcessor(SipExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, SIP_CONTEXT_FACTORY_DEPLOYMENT_PRIORITY -1 , new AttachSipServerServiceProcessor(service));
                 // plugs our context factory into web subsystem deployers

==============================================================================
Revision: bab128ed2961
Author:   Jean Deruelle <[email protected]>
Date:     Sun Aug 12 14:18:09 2012
Log:      Update Issue 147

Backport to Telscale branch

fixing license header
(cherry picked from commit 03665b7466a63526ccdf2f7a01f0f77c0563112a)

http://code.google.com/p/sipservlets/source/detail?r=bab128ed2961

Modified:
/containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipComponentProcessor.java

=======================================
--- /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipComponentProcessor.java Fri Aug 10 15:13:00 2012 +++ /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipComponentProcessor.java Sun Aug 12 14:18:09 2012
@@ -1,8 +1,8 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2011, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * TeleStax, Open Source Cloud Communications  Copyright 2012.
+ * and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
@@ -22,8 +22,6 @@

 package org.mobicents.as7.deployment;

-import static org.mobicents.as7.SipMessages.MESSAGES;
-
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -40,10 +38,8 @@
 import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
 import org.jboss.as.server.deployment.DeploymentUnitProcessor;
 import org.jboss.as.server.deployment.annotation.CompositeIndex;
-//import org.jboss.as.web.deployment.WebAttachments;
 import org.jboss.as.web.deployment.WebAttachments;
 import org.jboss.as.web.deployment.component.ComponentInstantiator;
-import org.jboss.as.web.deployment.component.ManagedBeanComponentInstantiator;
 import org.jboss.as.web.deployment.component.WebComponentDescription;
 import org.jboss.as.web.deployment.component.WebComponentInstantiator;
 import org.jboss.metadata.web.spec.ListenerMetaData;

Reply via email to