tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r1003855 - /tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
Date Sat, 02 Oct 2010 18:47:49 GMT
Author: lresende
Date: Sat Oct  2 18:47:49 2010
New Revision: 1003855

URL: http://svn.apache.org/viewvc?rev=1003855&view=rev
Log:
TUSCANY-3667 - InetAddress is not allowed in GoogleAppEngine, so try to load it dynamically
and fail gracefully

Modified:
    tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Modified: tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=1003855&r1=1003854&r2=1003855&view=diff
==============================================================================
--- tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
(original)
+++ tuscany/sca-java-2.x/branches/sca-java-2.0-M5/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
Sat Oct  2 18:47:49 2010
@@ -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 implement
     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 implement
         // 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 implement
                 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 implement
         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 implement
     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 implement
      */
     @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 implement
                 servlets.put(ns, servlets.remove(oldURI));
             }
         }
-        
-    }    
-    
+
+    }
+
     void destroy() {
 
         // Destroy the registered Servlets



Mime
View raw message