Revision: 66966cf43f87
Author: josemrecio <[email protected]>
Date: Sat Jul 21 10:32:01 2012
Log: Change in two areas:
1) Refactor SipJndiBindingProcessor so now JNDI bindings are setup as each
deployment unit is processed (previously only at ear level)
2) AS7 web container relies on a JNDI selector to properly setup a web
context specific JNDI context before any servlet invocation or interaction.
The selector is bound and unbound to the thread every time through
getThreadBindingListener() interface in catalina context.
This must also be performed for sip servlets. Two new methods has been
added to SipContext/SipStandardContext to allow sip container objects
access to that interface.
MessageDispatcher and ServletTimerImpl have been modified to bind and
unbind the jndi selector before any servlet interaction. This is done
everytime the class loader is also changed.
Next steps before closing the issue:
- In MessageDispatcher check whether routeSipMessageToRubyApp(),
makeAppSessionKey() and other methods also need jndi selector setup.
- Any other class that needs jndi selector setup?
- Currently the following jndi paths are setup:
java:sip/<app-name>/SipFactory
java:app/sip/<app-name>/SipFactory
java:comp/env/sip/<app-name>/SipFactory
these can probably be reduced to just comp/env
Additionally: AS7 will not setup jndi context before the context is totally
started.
http://code.google.com/p/sipservlets/source/detail?r=66966cf43f87
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/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java
/sip-servlets-core-api/src/main/java/org/mobicents/servlet/sip/core/SipContext.java
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/dispatchers/MessageDispatcher.java
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/timers/ServletTimerImpl.java
=======================================
---
/containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SIPWebContext.java
Tue Mar 27 08:02:55 2012
+++
/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
@@ -68,15 +68,19 @@
super();
deploymentUnit = du;
sipJBossContextConfig = createContextConfig(this, deploymentUnit);
- // if this an ear deployment, attach this to the parent
deploymentUnit so it can be used to inject context resources (SipFactory,
etc.)
+ // 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
- return;
- }
- if (DeploymentTypeMarker.isType(DeploymentType.EAR, parentDu)) {
- if (logger.isDebugEnabled()) logger.debug("Attaching
SIPWebContext " + this + " to " + parentDu.getName());
- parentDu.putAttachment(SIPWebContext.ATTACHMENT, this);
+ // 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");
}
}
=======================================
---
/containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipJndiBindingProcessor.java
Tue Mar 27 08:02:55 2012
+++
/containers/sip-servlets-as7-drop-in/jboss-as-mobicents/src/main/java/org/mobicents/as7/deployment/SipJndiBindingProcessor.java
Sat Jul 21 10:32:01 2012
@@ -26,8 +26,7 @@
import org.jboss.as.ee.component.BindingConfiguration;
import org.jboss.as.ee.component.EEModuleDescription;
import
org.jboss.as.ee.component.deployers.EEResourceReferenceProcessorRegistry;
-import org.jboss.as.ee.structure.DeploymentType;
-import org.jboss.as.ee.structure.DeploymentTypeMarker;
+import org.jboss.as.server.deployment.AttachmentList;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
@@ -46,51 +45,61 @@
static final String SIP_SESSIONS_UTIL_JNDI = "SipSessionsUtil";
static final String SIP_TIMER_SERVICE_JNDI = "TimerService";
-
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws
DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit =
phaseContext.getDeploymentUnit();
- if (!DeploymentTypeMarker.isType(DeploymentType.EAR,
deploymentUnit)) {
- return;
- }
+ final DeploymentUnit parentDU = deploymentUnit.getParent();
+
// look for the sip application name to properly build the jndi
name
String sipApplicationName = null;
- for (final DeploymentUnit subDeployment :
deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS))
{
- SipMetaData sipMetaData =
subDeployment.getAttachment(SipMetaData.ATTACHMENT_KEY);
- if (sipMetaData != null) {
- sipApplicationName = sipMetaData.getApplicationName();
- break;
- }
+ SipMetaData sipMetaData =
deploymentUnit.getAttachment(SipMetaData.ATTACHMENT_KEY);
+ if (sipMetaData != null) {
+ sipApplicationName = sipMetaData.getApplicationName();
+ }
+ else if (parentDU != null){
+ AttachmentList<DeploymentUnit> subDeploymentList =
parentDU.getAttachment(org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS);
+ for (final DeploymentUnit subDeployment : subDeploymentList) {
+ sipMetaData =
subDeployment.getAttachment(SipMetaData.ATTACHMENT_KEY);
+ if (sipMetaData != null) {
+ sipApplicationName = sipMetaData.getApplicationName();
+ break;
+ }
+ }
}
if (sipApplicationName == null) {
- // not a sip deployment
- return;
- }
- for (final DeploymentUnit subDeployment :
deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS))
{
- final EEResourceReferenceProcessorRegistry registry =
subDeployment.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
- // Add a EEResourceReferenceProcessor which handles @Resource
references with no mappedName
- registry.registerResourceReferenceProcessor(new
SipFactoryResourceProcessor(deploymentUnit));
- registry.registerResourceReferenceProcessor(new
SipSessionsUtilResourceProcessor(deploymentUnit));
- registry.registerResourceReferenceProcessor(new
SipTimerServiceResourceProcessor(deploymentUnit));
-
- // Create binding between jndi path and injection source
- final EEModuleDescription description =
subDeployment.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
- if (description == null) {
- continue;
- }
- for (String jndiBaseSip: JNDI_BASE_FOR_SIP) {
- final String jndiBaseMapped = jndiBaseSip +
SIP_PREFIX_JNDI + sipApplicationName + "/";
- description.getBindingConfigurations().add(new
BindingConfiguration(jndiBaseMapped + SIP_FACTORY_JNDI, new
SipFactoryInjectionSource(deploymentUnit)));
- description.getBindingConfigurations().add(new
BindingConfiguration(jndiBaseMapped + SIP_SESSIONS_UTIL_JNDI, new
SipSessionsUtilInjectionSource(deploymentUnit)));
- description.getBindingConfigurations().add(new
BindingConfiguration(jndiBaseMapped + SIP_TIMER_SERVICE_JNDI, new
SipTimerServiceInjectionSource(deploymentUnit)));
- }
- }
+ // not a sip deployment
+ return;
+ }
+ // anchorDU will have a SIPWebContext.ATTACHMENT so jndi lookups
can be resolved to context resources
+ final DeploymentUnit anchorDU = (parentDU == null)?
deploymentUnit : parentDU;
+ setupSipJndiBindingsPerDeploymentUnit(anchorDU, deploymentUnit,
sipApplicationName);
}
@Override
public void undeploy(final DeploymentUnit context) {
+ // TODO: do we need to explictly remove jndi bindings?
}
-}
+ private static void setupSipJndiBindingsPerDeploymentUnit(final
DeploymentUnit anchorDU, final DeploymentUnit subDU, final String
sipApplicationName) {
+ final EEResourceReferenceProcessorRegistry registry =
subDU.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
+ // Add a EEResourceReferenceProcessor which handles @Resource references
with no mappedName
+ registry.registerResourceReferenceProcessor(new
SipFactoryResourceProcessor(anchorDU));
+ registry.registerResourceReferenceProcessor(new
SipSessionsUtilResourceProcessor(anchorDU));
+ registry.registerResourceReferenceProcessor(new
SipTimerServiceResourceProcessor(anchorDU));
+
+ // Create binding between jndi path and injection source
+ final EEModuleDescription description =
subDU.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
+ if (description == null) {
+ return;
+ }
+ // Add bindings proper
+ for (String jndiBaseSip: JNDI_BASE_FOR_SIP) {
+ final String jndiBaseMapped = jndiBaseSip + SIP_PREFIX_JNDI +
sipApplicationName + "/";
+ description.getBindingConfigurations().add(new
BindingConfiguration(jndiBaseMapped + SIP_FACTORY_JNDI, new
SipFactoryInjectionSource(anchorDU)));
+ description.getBindingConfigurations().add(new
BindingConfiguration(jndiBaseMapped + SIP_SESSIONS_UTIL_JNDI, new
SipSessionsUtilInjectionSource(anchorDU)));
+ description.getBindingConfigurations().add(new
BindingConfiguration(jndiBaseMapped + SIP_TIMER_SERVICE_JNDI, new
SipTimerServiceInjectionSource(anchorDU)));
+ }
+ }
+}
=======================================
---
/containers/sip-servlets-as7/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java
Fri May 25 05:43:04 2012
+++
/containers/sip-servlets-as7/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java
Sat Jul 21 10:32:01 2012
@@ -1519,5 +1519,15 @@
public void setInstanceManager(InstanceManager instanceManager) {
super.setInstanceManager(instanceManager);
}
+
+ // http://code.google.com/p/sipservlets/issues/detail?id=135
+ @Override
+ public void bindThreadBindingListener() {
+ super.getThreadBindingListener().bind();
+ }
+ @Override
+ public void unbindThreadBindingListener() {
+ super.getThreadBindingListener().unbind();
+ }
}
=======================================
---
/sip-servlets-core-api/src/main/java/org/mobicents/servlet/sip/core/SipContext.java
Thu Sep 8 06:23:02 2011
+++
/sip-servlets-core-api/src/main/java/org/mobicents/servlet/sip/core/SipContext.java
Sat Jul 21 10:32:01 2012
@@ -179,4 +179,8 @@
boolean authorize(MobicentsSipServletRequest request);
SipDigestAuthenticator getDigestAuthenticator();
-}
+
+ // http://code.google.com/p/sipservlets/issues/detail?id=135
+ void bindThreadBindingListener();
+ void unbindThreadBindingListener();
+}
=======================================
---
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/dispatchers/MessageDispatcher.java
Wed Nov 16 13:44:45 2011
+++
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/dispatchers/MessageDispatcher.java
Sat Jul 21 10:32:01 2012
@@ -269,6 +269,8 @@
try {
final ClassLoader cl =
sipContext.getSipContextClassLoader();
Thread.currentThread().setContextClassLoader(cl);
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.bindThreadBindingListener();
try {
if(logger.isDebugEnabled()) {
logger.debug("Invoking instance
" + servlet);
@@ -278,6 +280,8 @@
sipServletImpl.deallocate(servlet);
}
} finally {
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.unbindThreadBindingListener();
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
@@ -319,6 +323,8 @@
try {
final ClassLoader cl =
sipContext.getSipContextClassLoader();
Thread.currentThread().setContextClassLoader(cl);
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.bindThreadBindingListener();
try {
if(logger.isDebugEnabled()) {
logger.debug("Invoking instance
" + servlet);
@@ -331,6 +337,8 @@
sipServletImpl.deallocate(servlet);
}
} finally {
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.unbindThreadBindingListener();
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
@@ -362,6 +370,9 @@
if(!securityCheck(request)) return;
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.bindThreadBindingListener();
+
if(logger.isDebugEnabled()) {
logger.debug("Invoking instance " +
servlet);
}
@@ -372,6 +383,8 @@
sipServletImpl.deallocate(servlet);
}
} finally {
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.unbindThreadBindingListener();
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
} else if(sipContext.getSipRubyController() != null) {
@@ -456,6 +469,8 @@
try {
final ClassLoader cl =
sipContext.getSipContextClassLoader();
Thread.currentThread().setContextClassLoader(cl);
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.bindThreadBindingListener();
try {
servlet.service(null, response);
@@ -463,6 +478,8 @@
sipServletImpl.deallocate(servlet);
}
} finally {
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.unbindThreadBindingListener();
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
=======================================
---
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/timers/ServletTimerImpl.java
Thu Sep 8 02:18:19 2011
+++
/sip-servlets-impl/src/main/java/org/mobicents/servlet/sip/core/timers/ServletTimerImpl.java
Sat Jul 21 10:32:01 2012
@@ -296,6 +296,8 @@
try {
ClassLoader cl = sipContext.getSipContextClassLoader();
Thread.currentThread().setContextClassLoader(cl);
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.bindThreadBindingListener();
sipContext.enterSipApp(sipApplicationSession, null,
false);
batchStarted = sipContext.enterSipAppHa(true);
listener.timeout(this);
@@ -303,6 +305,8 @@
logger.error("An unexpected exception happened in the timer
callback!",t);
} finally {
try {
+ //
http://code.google.com/p/sipservlets/issues/detail?id=135
+ sipContext.unbindThreadBindingListener();
Thread.currentThread().setContextClassLoader(oldClassLoader);
if (isRepeatingTimer) {
estimateNextExecution();