summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/host-webapp/src/main/java
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-09-06 16:50:00 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-09-06 16:50:00 +0000
commitd9fcf681be04c6e9158120d32f8392abd402113a (patch)
tree09da6957cd7ea80c44cfeaa4b4ae55b342bc9330 /sca-java-2.x/trunk/modules/host-webapp/src/main/java
parentc9452469253d0892e72acad5c03e0b42a6a181e4 (diff)
TUSCANY-3667 - InetAddress is not allowed in GoogleAppEngine, so try to load it dynamically and fail gracefully
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@993093 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/host-webapp/src/main/java')
-rw-r--r--sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java52
1 files changed, 29 insertions, 23 deletions
diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
index b927ecaf4c..65ea14fbf0 100644
--- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
+++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
@@ -6,30 +6,29 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
package org.apache.tuscany.sca.host.webapp;
import java.lang.reflect.Method;
-import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
-import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
@@ -45,12 +44,14 @@ import org.apache.tuscany.sca.node.Node;
/**
* ServletHost implementation for use in a webapp environment.
- *
+ *
* @version $Rev$ $Date$
*/
public class WebAppServletHost implements ServletHost {
private static final Logger logger = Logger.getLogger(WebAppServletHost.class.getName());
+ private static final String INETADDRESS = "java.net.InetAddress";
+
public static final String SCA_NODE_ATTRIBUTE = Node.class.getName();
private Map<String, Servlet> servlets;
@@ -73,14 +74,14 @@ public class WebAppServletHost implements ServletHost {
public int getDefaultPort() {
return defaultPortNumber;
}
-
+
public String getName() {
return "webapp";
}
-
+
public String addServletMapping(String suri, Servlet servlet) throws ServletMappingException {
return addServletMapping(suri, servlet, null);
- }
+ }
public String addServletMapping(String suri, Servlet servlet, SecurityContext securityContext) throws ServletMappingException {
URI pathURI = URI.create(suri);
@@ -94,7 +95,7 @@ public class WebAppServletHost implements ServletHost {
// String relativeURI = suri;
if (!suri.startsWith(contextPath + "/")) {
suri = contextPath + suri;
- }
+ }
if (!servlets.values().contains(servlet)) {
// The same servlet can be registred more than once
@@ -104,7 +105,7 @@ public class WebAppServletHost implements ServletHost {
throw new ServletMappingException(e);
}
}
-
+
// In a webapp just use the given path and ignore the host and port
// as they are fixed by the Web container
servlets.put(suri, servlet);
@@ -169,8 +170,13 @@ public class WebAppServletHost implements ServletHost {
String host = uri.getHost();
if (host == null) {
try {
- host = InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException e) {
+ //TUSCANY-3667 - InetAddress is not allowed in GoogleAppEngine
+ //host = InetAddress.getLocalHost().getHostName();
+ Class<?> clazz = Class.forName(INETADDRESS);
+ Object inetAddress = clazz.getMethod("getLocalHost").invoke(null);
+ host = (String) clazz.getMethod("getHostName").invoke(inetAddress);
+ } catch (Throwable t) {
+ logger.log(Level.WARNING, "Error retrieving host information : " + t.getMessage());
host = "localhost";
}
}
@@ -233,22 +239,22 @@ public class WebAppServletHost implements ServletHost {
public void init(ServletConfig config) throws ServletException {
this.servletConfig = config;
servletContext = config.getServletContext();
-
+
for (String name : tempAttributes.keySet()) {
servletContext.setAttribute(name, tempAttributes.get(name));
}
-
+
// WebAppHelper.init(servletContext);
-
+
initContextPath(config);
// Initialize the registered Servlets
for (Servlet servlet : servlets.values()) {
servlet.init(config);
}
-
+
}
-
+
/**
* Initializes the contextPath
* The 2.5 Servlet API has a getter for this, for pre 2.5 Servlet
@@ -256,9 +262,9 @@ public class WebAppServletHost implements ServletHost {
*/
@SuppressWarnings("unchecked")
public void initContextPath(ServletConfig config) {
-
+
String oldContextPath = contextPath;
-
+
if (Collections.list(config.getInitParameterNames()).contains("contextPath")) {
contextPath = config.getInitParameter("contextPath");
} else {
@@ -292,9 +298,9 @@ public class WebAppServletHost implements ServletHost {
servlets.put(ns, servlets.remove(oldURI));
}
}
-
- }
-
+
+ }
+
void destroy() {
// Destroy the registered Servlets