Revision: 15380
Author: [email protected]
Date: Thu Nov 18 07:10:37 2010
Log: [No log message]
http://code.google.com/p/mobicents/source/detail?r=15380
Modified:
/branches/servers/sip-servlets/2.0/tomcat-7/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java
=======================================
---
/branches/servers/sip-servlets/2.0/tomcat-7/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java
Wed Nov 17 15:24:52 2010
+++
/branches/servers/sip-servlets/2.0/tomcat-7/src/main/java/org/mobicents/servlet/sip/startup/SipStandardContext.java
Thu Nov 18 07:10:37 2010
@@ -17,6 +17,7 @@
package org.mobicents.servlet.sip.startup;
import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@@ -54,8 +55,10 @@
import org.apache.catalina.Manager;
import org.apache.catalina.Service;
import org.apache.catalina.Wrapper;
+import org.apache.catalina.core.ApplicationContext;
import org.apache.catalina.core.NamingContextListener;
import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardHost;
import org.apache.catalina.deploy.Injectable;
import org.apache.catalina.deploy.InjectionTarget;
import org.apache.catalina.deploy.LoginConfig;
@@ -210,6 +213,9 @@
// setState(LifecycleState.INITIALIZING);
super.initInternal();
+ // Post work directory
+ postWorkDirectory();
+
prepareServletContext();
if(logger.isInfoEnabled()) {
@@ -280,8 +286,7 @@
logger.info("Starting the sip context");
logger.info("LifecycleState: "+this.getState());
}
- if( !this.getState().equals(LifecycleState.INITIALIZED)) {
- logger.info("calling prepareServletContext");
+ if( this.getState().equals(LifecycleState.INITIALIZED)) {
prepareServletContext();
}
// Add missing components as necessary
@@ -305,7 +310,6 @@
webappLoader.setDelegate(getDelegate());
setLoader(webappLoader);
}
-
// Configure default manager if none was specified
if (manager == null) {
@@ -344,15 +348,11 @@
if ((loader != null) && (loader instanceof Lifecycle))
((Lifecycle) loader).start();
- if ((cluster != null) && (cluster instanceof Lifecycle))
- ((Lifecycle) cluster).start();
- if ((realm != null) && (realm instanceof Lifecycle))
- ((Lifecycle) realm).start();
if ((resources != null) && (resources instanceof Lifecycle))
((Lifecycle) resources).start();
- fireLifecycleEvent(Lifecycle.CONFIGURE_START_EVENT, null);
+// fireLifecycleEvent(Lifecycle.CONFIGURE_START_EVENT, null);
// Replace the default annotation processor. This is needed to
handle resource injection
// for SipFactory, Session utils and other objects residing in the
servlet context space.
@@ -360,32 +360,26 @@
// normal lookup method - in the default naming context.
//tomcat naming
- Map<String, Map<String, String>> injectionMap =
buildInjectionMap(
- getIgnoreAnnotations() ? new NamingResources():
getNamingResources());
-// if
(getNamingContextListener().getEnvContext()==null){fireLifecycleEvent(START_EVENT,
getNamingContextName());}
-// if
(getNamingContextListener().getEnvContext()==null){logger.info("getNamingContextListener().getEnvContext()
is null");}
-// if (injectionMap==null){logger.info("injectionMap is
null");}
-// if (super.context==null){logger.info("super.context is
null");}
-// if
(this.getClass().getClassLoader()==null){logger.info("this.getClass().getClassLoader()
is null");}
-// if (this==null){logger.info("this sipContext is null");}
- setInstanceManager(
- new DefaultSipInstanceManager(
-
getNamingContextListener().getEnvContext(),
- injectionMap, this,
this.getClass().getClassLoader(),this));
- } else {
- // jboss or other kind of naming
- try {
- Map<String, Map<String, String>> injectionMap =
buildInjectionMap(
- getIgnoreAnnotations() ? new NamingResources():
getNamingResources());
- InitialContext iniCtx = new InitialContext();
- Context envCtx = (Context)
iniCtx.lookup("java:comp/env");
- this.setInstanceManager(
- new DefaultSipInstanceManager(
- envCtx,
- injectionMap,
this, this.getClass().getClassLoader(),this));
- } catch (NamingException e) {
- logger.error("Impossible to get the naming context
", e);
- }
+// Map<String, Map<String, String>> injectionMap =
buildInjectionMap(
+// getIgnoreAnnotations() ? new NamingResources():
getNamingResources());
+// setInstanceManager(
+// new DefaultSipInstanceManager(
+//
getNamingContextListener().getEnvContext(),
+// injectionMap, this,
this.getClass().getClassLoader(),this));
+// } else {
+// // jboss or other kind of naming
+// try {
+// Map<String, Map<String, String>> injectionMap =
buildInjectionMap(
+// getIgnoreAnnotations() ? new NamingResources():
getNamingResources());
+// InitialContext iniCtx = new InitialContext();
+// Context envCtx = (Context)
iniCtx.lookup("java:comp/env");
+// this.setInstanceManager(
+// new DefaultSipInstanceManager(
+// envCtx,
+// injectionMap,
this, this.getClass().getClassLoader(),this));
+// } catch (NamingException e) {
+// logger.error("Impossible to get the naming context
", e);
+// }
}
//JSR 289 Section 2.1.1 Step 1.Deploy the application.
//This will make start the sip context config, which will in turn parse
the sip descriptor deployment
@@ -1461,18 +1455,19 @@
@Override
public void enterSipAppHa(boolean startCacheActivity) {
// TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+// throw new UnsupportedOperationException();
}
@Override
public void exitSipAppHa(SipServletRequestImpl request,
SipServletResponseImpl response) {
// TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+// throw new UnsupportedOperationException();
}
/**
- * Copied from Tomcat 7 StandardContext
+ * from Tomcat 7 StandardContext
+ * Used to create the injectionMap
*
* @param namingResources
* @return injectionMap
@@ -1524,6 +1519,74 @@
}
}
}
+
+ /**
+ * Set the appropriate context attribute for our work directory.
+ */
+ private void postWorkDirectory() {
+
+ // Acquire (or calculate) the work directory path
+ String workDir = getWorkDir();
+ if (workDir == null || workDir.length() == 0) {
+
+ // Retrieve our parent (normally a host) name
+ String hostName = null;
+ String engineName = null;
+ String hostWorkDir = null;
+ Container parentHost = getParent();
+ if (parentHost != null) {
+ hostName = parentHost.getName();
+ if (parentHost instanceof StandardHost) {
+ hostWorkDir = ((StandardHost)parentHost).getWorkDir();
+ }
+ Container parentEngine = parentHost.getParent();
+ if (parentEngine != null) {
+ engineName = parentEngine.getName();
+ }
+ }
+ if ((hostName == null) || (hostName.length() < 1))
+ hostName = "_";
+ if ((engineName == null) || (engineName.length() < 1))
+ engineName = "_";
+
+ String temp = getPath();
+ if (temp.startsWith("/"))
+ temp = temp.substring(1);
+ temp = temp.replace('/', '_');
+ temp = temp.replace('\\', '_');
+ if (temp.length() < 1)
+ temp = "_";
+ if (hostWorkDir != null ) {
+ workDir = hostWorkDir + File.separator + temp;
+ } else {
+ workDir = "work" + File.separator + engineName +
+ File.separator + hostName + File.separator + temp;
+ }
+ setWorkDir(workDir);
+ }
+
+ // Create this directory if necessary
+ File dir = new File(workDir);
+ if (!dir.isAbsolute()) {
+ File catalinaHome = engineBase();
+ String catalinaHomePath = null;
+ try {
+ catalinaHomePath = catalinaHome.getCanonicalPath();
+ dir = new File(catalinaHomePath, workDir);
+ } catch (IOException e) {
+ }
+ }
+ dir.mkdirs();
+
+ // Set the appropriate servlet context attribute
+ getServletContext().setAttribute(ServletContext.TEMPDIR, dir);
+// if (getServletContext() instanceof ConvergedApplicationContext){
+// ((ConvergedApplicationContext)
getServletContext()).setAttributeReadOnly
+// (ServletContext.TEMPDIR);
+// }
+ }
+
+
// public void setInstanceManager(SipInstanceManager instanceManager) {
// this.instanceManager = instanceManager;