Author: antelder
Date: Tue Feb 12 04:47:32 2008
New Revision: 620785
URL: http://svn.apache.org/viewvc?rev=620785&view=rev
Log:
Get TuscanyContextListener working again and update so WebAppServletHost works
if the TuscanyContextListener is used by the webapp
Modified:
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
incubator/tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyServlet.java
Modified:
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java?rev=620785&r1=620784&r2=620785&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
(original)
+++
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java
Tue Feb 12 04:47:32 2008
@@ -19,27 +19,44 @@
package org.apache.tuscany.sca.host.webapp;
+import java.util.Enumeration;
+
+import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import javax.servlet.ServletException;
import org.apache.tuscany.sca.host.embedded.SCADomain;
/**
* A ServletContextListener to create and close the SCADomain
* when the webapp is initialized or destroyed.
- *
- * @deprecated Not needed anymore, TuscanyServletFilter is sufficient
*/
[EMAIL PROTECTED]
public class TuscanyContextListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
- ServletContext servletContext = event.getServletContext();
+ final ServletContext servletContext = event.getServletContext();
try {
- SCADomainHelper.initSCADomain(servletContext);
- } catch (Throwable e) {
- servletContext.log("exception initializing SCADomain", e);
+ WebAppServletHost.getInstance().init(new ServletConfig() {
+ public String getInitParameter(String name) {
+ return servletContext.getInitParameter(name);
+ }
+
+ public Enumeration getInitParameterNames() {
+ return servletContext.getInitParameterNames();
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public String getServletName() {
+ return null;
+ }
+ });
+ } catch (ServletException e) {
+ throw new RuntimeException(e);
}
}
Modified:
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=620785&r1=620784&r2=620785&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
(original)
+++
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
Tue Feb 12 04:47:32 2008
@@ -30,6 +30,8 @@
import java.util.Map;
import java.util.logging.Logger;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
@@ -149,7 +151,7 @@
path = '/' + path;
}
- if (!path.startsWith(contextPath)) {
+ if (contextPath != null && !path.startsWith(contextPath)) {
path = contextPath + path;
}
@@ -199,31 +201,17 @@
return instance;
}
- void init(ServletConfig config) throws ServletException {
+ public void init(ServletConfig config) throws ServletException {
+ ServletContext servletContext = config.getServletContext();
- initContextPath(config);
+ initContextPath(servletContext);
- // Create an SCA domain object
- ServletContext servletContext = config.getServletContext();
- String domainURI = "http://localhost/" + contextPath;
- String contributionRoot = null;
- try {
- URL rootURL = servletContext.getResource("/");
- if (rootURL.getProtocol().equals("jndi")) {
- //this is tomcat case, we should use getRealPath
- File warRootFile = new File(servletContext.getRealPath("/"));
- contributionRoot = warRootFile.toURL().toString();
- } else {
- //this is jetty case
- contributionRoot = rootURL.toString();
- }
- } catch (MalformedURLException mf) {
- //ignore, pass null
+ if (servletContext.getAttribute(SCA_DOMAIN_ATTRIBUTE) == null) {
+ String domainURI = "http://localhost/" + contextPath;
+ String contributionRoot = getContributionLocation(servletContext);
+ this.scaDomain = SCADomain.newInstance(domainURI,
contributionRoot);
+ servletContext.setAttribute(SCA_DOMAIN_ATTRIBUTE, scaDomain);
}
- scaDomain = SCADomain.newInstance(domainURI, contributionRoot);
-
- // Store the SCA domain in the servlet context
- servletContext.setAttribute(SCA_DOMAIN_ATTRIBUTE, scaDomain);
// Initialize the registered servlets
for (Servlet servlet : servlets.values()) {
@@ -231,14 +219,44 @@
}
}
+ protected String getContributionLocation(ServletContext servletContext) {
+ String contributionRoot = null;
+ try {
+
+ InitialContext ic = new InitialContext();
+ URL repoURL = (URL) ic.lookup("java:comp/env/url/contributions");
+
+ contributionRoot = repoURL.toString();
+
+ } catch (NamingException e) {
+
+ // ignore exception and use default location
+
+ try {
+ URL rootURL = servletContext.getResource("/");
+ if (rootURL.getProtocol().equals("jndi")) {
+ //this is tomcat case, we should use getRealPath
+ File warRootFile = new
File(servletContext.getRealPath("/"));
+ contributionRoot = warRootFile.toURL().toString();
+ } else {
+ //this is jetty case
+ contributionRoot = rootURL.toString();
+ }
+ } catch (MalformedURLException mf) {
+ //ignore, pass null
+ }
+ }
+
+ return contributionRoot;
+ }
+
/**
* Initializes the contextPath
* The 2.5 Servlet API has a getter for this, for pre 2.5 servlet
* containers use an init parameter.
*/
@SuppressWarnings("unchecked")
- public void initContextPath(ServletConfig config) {
- ServletContext context = config.getServletContext();
+ public void initContextPath(ServletContext context) {
// The getContextPath() is introduced since Servlet 2.5
Method m;
try {
@@ -286,6 +304,8 @@
* can't use setContextPath as NodeImpl calls that later
*/
public void setContextPath2(String path) {
- this.contextPath = path;
+ if (path != null && path.length() > 0) {
+ this.contextPath = path;
+ }
}
}
Modified:
incubator/tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyServlet.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyServlet.java?rev=620785&r1=620784&r2=620785&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyServlet.java
(original)
+++
incubator/tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyServlet.java
Tue Feb 12 04:47:32 2008
@@ -44,9 +44,9 @@
private transient WebAppServletHost servletHost;
@Override
- public void init(ServletConfig config) {
+ public void init(ServletConfig config) throws ServletException {
servletHost = WebAppServletHost.getInstance();
- servletHost.initContextPath(config);
+ servletHost.init(config);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]