Revision: 1dfee92f83a9
Author:   josemrecio <[email protected]>
Date:     Sun Jul 29 18:57:32 2012
Log:      Update Issue 135

Backport to master branch

1. Objects in JAR (e.g. EJB) or non-SIP WAR do not have access to comp/env bindings setup by a SIP WAR. Bindings in "java:app/sip" can be used for that.

2. Clear, unified, definition of which deployment unit will have attached the sip context (also required by issue-136)
(cherry picked from commit d5e952323530a74cb27bb81ce0a4e89963d75415)

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

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

=======================================
--- /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SIPWebContext.java Sat Jul 21 10:32:01 2012 +++ /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SIPWebContext.java Sun Jul 29 18:57:32 2012
@@ -69,19 +69,27 @@
         deploymentUnit = du;
         sipJBossContextConfig = createContextConfig(this, deploymentUnit);
// attach context to top-level deploymentUnit so it can be used to get context resources (SipFactory, etc.)
-        DeploymentUnit parentDu = deploymentUnit.getParent();
-        if (parentDu == null) {
-               // this is a war only deployment
- if (logger.isDebugEnabled()) logger.debug("Attaching SIPWebContext " + this + " to " + deploymentUnit.getName());
-               deploymentUnit.putAttachment(SIPWebContext.ATTACHMENT, this);
-        }
- else if (DeploymentTypeMarker.isType(DeploymentType.EAR, parentDu)) { - if (logger.isDebugEnabled()) logger.debug("Attaching SIPWebContext " + this + " to " + parentDu.getName());
-               parentDu.putAttachment(SIPWebContext.ATTACHMENT, this);
+        final DeploymentUnit anchorDu = getSipContextAnchorDu(du);
+        if (anchorDu != null) {
+ if (logger.isDebugEnabled()) logger.debug("Attaching SIPWebContext " + this + " to " + anchorDu.getName());
+               anchorDu.putAttachment(SIPWebContext.ATTACHMENT, this);
         }
         else {
- logger.error("Cowardly refusing to attach SIPWebContext " + this + " to " + deploymentUnit.getName() + " - This is probably a bug");
-        }
+ logger.error("Can't attach SIPWebContext " + this + " to " + deploymentUnit.getName() + " - This is probably a bug");
+        }
+//        DeploymentUnit parentDu = deploymentUnit.getParent();
+//        if (parentDu == null) {
+//             // this is a war only deployment
+// if (logger.isDebugEnabled()) logger.debug("Attaching SIPWebContext " + this + " to " + deploymentUnit.getName());
+//             deploymentUnit.putAttachment(SIPWebContext.ATTACHMENT, this);
+//        }
+// else if (DeploymentTypeMarker.isType(DeploymentType.EAR, parentDu)) { +// if (logger.isDebugEnabled()) logger.debug("Attaching SIPWebContext " + this + " to " + parentDu.getName());
+//             parentDu.putAttachment(SIPWebContext.ATTACHMENT, this);
+//        }
+//        else {
+// logger.error("Cowardly refusing to attach SIPWebContext " + this + " to " + deploymentUnit.getName() + " - This is probably a bug");
+//        }
     }

     public void postProcessContext(DeploymentUnit deploymentUnit) {
@@ -270,5 +278,22 @@
         sipContext.addLifecycleListener(config);
         return config;
     }
+
+ // returns the anchor deployment unit that will have attached a SIPWebContext + public static DeploymentUnit getSipContextAnchorDu(final DeploymentUnit du) { + // attach context to top-level deploymentUnit so it can be used to get context resources (SipFactory, etc.)
+        DeploymentUnit parentDu = du.getParent();
+        if (parentDu == null) {
+               // this is a war only deployment
+               return du;
+        }
+ else if (DeploymentTypeMarker.isType(DeploymentType.EAR, parentDu)) {
+               return parentDu;
+        }
+        else {
+ logger.error("Can't find proper anchor deployment unit for " + du.getName() + " - This is probably a bug");
+               return null;
+        }
+    }

 }
=======================================
--- /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipJndiBindingProcessor.java Tue Jul 24 11:47:03 2012 +++ /containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipJndiBindingProcessor.java Sun Jul 29 18:57:32 2012
@@ -39,8 +39,7 @@
  */
 public class SipJndiBindingProcessor implements DeploymentUnitProcessor {

-// static final String[] JNDI_BASE_FOR_SIP = {"java:", "java:app/", "java:comp/env/"};
-    static final String[] JNDI_BASE_FOR_SIP = {"java:comp/env/"};
+ static final String[] JNDI_BASE_FOR_SIP = {"java:comp/env/", "java:app/"};
     static final String SIP_PREFIX_JNDI = "sip/";
     static final String SIP_FACTORY_JNDI = "SipFactory";
     static final String SIP_SESSIONS_UTIL_JNDI = "SipSessionsUtil";
@@ -73,7 +72,7 @@
                return;
         }
// anchorDU will have a SIPWebContext.ATTACHMENT so jndi lookups can be resolved to context resources - final DeploymentUnit anchorDU = (parentDU == null)? deploymentUnit : parentDU; + final DeploymentUnit anchorDU = SIPWebContext.getSipContextAnchorDu(deploymentUnit); setupSipJndiBindingsPerDeploymentUnit(anchorDU, deploymentUnit, sipApplicationName);
     }

Reply via email to