summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/host-http/src/main
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-03-14 00:50:38 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-03-14 00:50:38 +0000
commitb4f48f407a8fefba16395eceb34de6bd48e74d12 (patch)
tree7e1bcf4456ef1dfd3b4d337ed7ea262f1259ffef /sca-java-2.x/trunk/modules/host-http/src/main
parent014971ccb5b2041147cf9d84d498cce64ea0493e (diff)
Improve the IP address binding to be based on the host from the uri
Having servlet host to return deployed uri git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@922701 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/host-http/src/main')
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java18
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java77
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java6
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java11
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java28
5 files changed, 66 insertions, 74 deletions
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
index 6cee3142ca..4c868f73e4 100644
--- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
@@ -32,7 +32,6 @@ import javax.servlet.Servlet;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.LifeCycleListener;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
-import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
/**
* Default implementation of a Servlet host extension point.
@@ -43,6 +42,7 @@ public class DefaultServletHostExtensionPoint implements ServletHostExtensionPoi
private List<ServletHost> servletHosts = new ArrayList<ServletHost>();
private boolean loaded;
+ private boolean webApp;
private ExtensionPointRegistry registry;
@@ -129,12 +129,12 @@ public class DefaultServletHostExtensionPoint implements ServletHostExtensionPoi
return host;
}
- public void addServletMapping(String uri, Servlet servlet) throws ServletMappingException {
- getServletHost().addServletMapping(uri, servlet);
+ public String addServletMapping(String uri, Servlet servlet) throws ServletMappingException {
+ return getServletHost().addServletMapping(uri, servlet);
}
- public void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException {
- getServletHost().addServletMapping(uri, servlet, securityContext);
+ public String addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException {
+ return getServletHost().addServletMapping(uri, servlet, securityContext);
}
public String getContextPath() {
@@ -199,4 +199,12 @@ public class DefaultServletHostExtensionPoint implements ServletHostExtensionPoi
servletHosts.clear();
registry = null;
}
+
+ public boolean isWebApp() {
+ return webApp;
+ }
+
+ public void setWebApp(boolean webApp) {
+ this.webApp = webApp;
+ }
}
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java
index 776de4a361..1b639041f7 100644
--- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java
@@ -20,10 +20,14 @@
package org.apache.tuscany.sca.host.http;
import java.net.URL;
+import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+
/**
* Default implementation of an extensible Servlet host.
*
@@ -32,98 +36,87 @@ import javax.servlet.Servlet;
public class ExtensibleServletHost implements ServletHost {
private ServletHostExtensionPoint servletHosts;
+
+ public ExtensibleServletHost(ExtensionPointRegistry registry) {
+ this.servletHosts = registry.getExtensionPoint(ServletHostExtensionPoint.class);
+ }
+ public static ExtensibleServletHost getInstance(ExtensionPointRegistry registry) {
+ UtilityExtensionPoint utilityExtensionPoint = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ return utilityExtensionPoint.getUtility(ExtensibleServletHost.class);
+ }
+
public ExtensibleServletHost(ServletHostExtensionPoint servletHosts) {
this.servletHosts = servletHosts;
}
public void setDefaultPort(int port) {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
for (ServletHost servletHost: servletHosts.getServletHosts()) {
servletHost.setDefaultPort(port);
}
}
- private ServletHost getDefaultServletHost() {
- return servletHosts.getServletHosts().get(0);
+ public ServletHost getDefaultServletHost() {
+ List<ServletHost> hosts = servletHosts.getServletHosts();
+ if (hosts.isEmpty()) {
+ throw new ServletMappingException("No servlet host is available.");
+ }
+ if (servletHosts.isWebApp()) {
+ for (ServletHost servletHost : hosts) {
+ if (!"webapp".equals(servletHost.getName())) {
+ continue;
+ }
+ if (servletHost instanceof DefaultServletHostExtensionPoint.LazyServletHost) {
+ return ((DefaultServletHostExtensionPoint.LazyServletHost)servletHost).getServletHost();
+ } else {
+ return servletHost;
+ }
+ }
+ }
+ return hosts.get(0);
}
public int getDefaultPort() {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
return getDefaultServletHost().getDefaultPort();
}
- public void addServletMapping(String uri, Servlet servlet) throws ServletMappingException {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
+ public String addServletMapping(String uri, Servlet servlet) throws ServletMappingException {
// TODO implement selection of the correct Servlet host based on the mapping
// For now just select the first one
- getDefaultServletHost().addServletMapping(uri, servlet);
+ return getDefaultServletHost().addServletMapping(uri, servlet);
}
- public void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
+ public String addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException {
// TODO implement selection of the correct Servlet host based on the mapping
// For now just select the first one
- getDefaultServletHost().addServletMapping(uri, servlet, securityContext);
+ return getDefaultServletHost().addServletMapping(uri, servlet, securityContext);
}
public Servlet getServletMapping(String uri) throws ServletMappingException {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
// TODO implement selection of the correct Servlet host based on the mapping
// For now just select the first one
return getDefaultServletHost().getServletMapping(uri);
}
public Servlet removeServletMapping(String uri) throws ServletMappingException {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
// TODO implement selection of the correct Servlet host based on the mapping
// For now just select the first one
return getDefaultServletHost().removeServletMapping(uri);
}
public RequestDispatcher getRequestDispatcher(String uri) throws ServletMappingException {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
// TODO implement selection of the correct Servlet host based on the mapping
// For now just select the first one
return getDefaultServletHost().getRequestDispatcher(uri);
}
public String getContextPath() {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
// TODO implement selection of the correct Servlet host based on the mapping
// For now just select the first one
return getDefaultServletHost().getContextPath();
}
public URL getURLMapping(String uri, SecurityContext securityContext) {
- if (servletHosts.getServletHosts().isEmpty()) {
- throw new ServletMappingException("No servlet host available");
- }
-
return getDefaultServletHost().getURLMapping(uri, securityContext);
}
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java
index f5e375a2ed..eee223e9a9 100644
--- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java
@@ -55,9 +55,10 @@ public interface ServletHost {
*
* @param uri the URI-mapping for the Servlet
* @param servlet the Servlet that should be invoked
+ * @return The deployed URI
* @throws ServletMappingException
*/
- void addServletMapping(String uri, Servlet servlet) throws ServletMappingException;
+ String addServletMapping(String uri, Servlet servlet) throws ServletMappingException;
/**
* Add a mapping for an instance of a Servlet. This requests that the
@@ -68,9 +69,10 @@ public interface ServletHost {
* @param uri the URI-mapping for the Servlet
* @param servlet the Servlet that should be invoked
* @param securityContext the SecurityContext to enable QoS services
+ * @return The deployed URI
* @throws ServletMappingException
*/
- void addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException;
+ String addServletMapping(String uri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException;
/**
* Remove a Servlet mapping. This directs the Servlet container not to direct
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java
index fbd085ba2b..8ef48e4949 100644
--- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java
@@ -26,6 +26,17 @@ import java.util.List;
* @version $Rev$ $Date$
*/
public interface ServletHostExtensionPoint {
+ /**
+ * Test if it's inside a web application
+ * @return
+ */
+ boolean isWebApp();
+
+ /**
+ * Set the flag to indicate it's inside a web application
+ * @param webApp
+ */
+ void setWebApp(boolean webApp);
/**
* Adds a Servlet host extension.
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java
index 946eb54ed6..84caa29237 100644
--- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostHelper.java
@@ -19,34 +19,12 @@
package org.apache.tuscany.sca.host.http;
-import java.util.List;
-
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
public class ServletHostHelper {
-
- private static boolean webappHost;
-
+
public static ServletHost getServletHost(ExtensionPointRegistry extensionPoints) {
- ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class);
- List<ServletHost> hosts = servletHosts.getServletHosts();
- for (ServletHost servletHost : hosts) {
- if (webappHost && !"webapp".equals(servletHost.getName())) {
- continue;
- }
- if (!webappHost && "webapp".equals(servletHost.getName())) {
- continue;
- }
- if(servletHost instanceof DefaultServletHostExtensionPoint.LazyServletHost) {
- return ((DefaultServletHostExtensionPoint.LazyServletHost) servletHost).getServletHost();
- } else {
- return servletHost;
- }
- }
- throw new IllegalStateException("No ServletHost found");
- }
-
- public static void setWebappHost(boolean b) {
- ServletHostHelper.webappHost = b;
+ ExtensibleServletHost host = ExtensibleServletHost.getInstance(extensionPoints);
+ return host.getDefaultServletHost();
}
}