ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/utils NetworkUtils.java
Date Fri, 14 May 2004 12:56:48 GMT
stevel      2004/05/14 05:56:48

  Modified:    java/src/org/apache/axis/transport/http
                        SimpleAxisWorker.java
  Added:       java/src/org/apache/axis/utils NetworkUtils.java
  Log:
  And here is the factoring out of hostname lookup.
  
  Revision  Changes    Path
  1.41      +2 -24     ws-axis/java/src/org/apache/axis/transport/http/SimpleAxisWorker.java
  
  Index: SimpleAxisWorker.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/transport/http/SimpleAxisWorker.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- SimpleAxisWorker.java	3 May 2004 20:04:10 -0000	1.40
  +++ SimpleAxisWorker.java	14 May 2004 12:56:48 -0000	1.41
  @@ -29,6 +29,7 @@
   import org.apache.axis.server.AxisServer;
   import org.apache.axis.utils.Messages;
   import org.apache.axis.utils.XMLUtils;
  +import org.apache.axis.utils.NetworkUtils;
   import org.apache.commons.logging.Log;
   import org.w3c.dom.Document;
   
  @@ -788,29 +789,6 @@
        * One method for all host name lookups.
        */
       public static String getLocalHost() {
  -        // This doesn't return anything but 0.0.0.0
  -        //  String hostname = serverSocket.getInetAddress().getHostAddress();
  -        // And this returns the hostname of the host on the other
  -        // end of the socket:
  -        //  String hostname = socket.getInetAddress().getHostName();
  -        // This works for 99% of the uses of SimpleAxisServer,
  -        // but is very stupid. One challenge is that a machine may
  -        // have >1 network card, as on each attached network it will have a different
  -        // hostname.
  -        // The other challenge is that unmanaged networks lack reverse DNS. 
  -        InetAddress address;
  -        String hostname;
  -        try {
  -            address = InetAddress.getLocalHost();
  -            //force a best effort reverse DNS lookup
  -            hostname = address.getHostName();
  -            if (hostname == null || hostname.length() == 0) {
  -                hostname = address.toString();
  -            }
  -        } catch (UnknownHostException noIpAddrException) {
  -            //bail out here
  -            hostname = "127.0.0.1";
  -        }
  -        return hostname;
  +        return NetworkUtils.getLocalHostname();
       }
   }
  
  
  
  1.1                  ws-axis/java/src/org/apache/axis/utils/NetworkUtils.java
  
  Index: NetworkUtils.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed 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.
   */
  
  package org.apache.axis.utils;
  
  import org.apache.commons.logging.Log;
  import org.apache.axis.components.logger.LogFactory;
  
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  
  /**
   * Utility classes for networking
   * created 13-May-2004 16:17:51
   */
  
  public class NetworkUtils {
      /**
       * what we return when we cannot determine our hostname.
       * We use this rather than 'localhost' as if DNS is very confused,
       * localhost can map to different machines than "self".
       */
      public static final String LOCALHOST = "127.0.0.1";
  
      /**
       * keep this uninstantiable.
       */
      private NetworkUtils() {
      }
  
      protected static Log log =
              LogFactory.getLog(NetworkUtils.class.getName());
  
      /**
       * Get the string defining the hostname of the system, as taken from
       * the default network adapter of the system. There is no guarantee that
       * this will be fully qualified, or that it is the hostname used by external
       * machines to access the server.
       * If we cannot determine the name, then we return the default hostname,
       * which is defined by {@link #LOCALHOST}
       * @return a string name of the host.
       */
      public static String getLocalHostname() {
          InetAddress address;
          String hostname;
          try {
              address = InetAddress.getLocalHost();
              //force a best effort reverse DNS lookup
              hostname = address.getHostName();
              if (hostname == null || hostname.length() == 0) {
                  hostname = address.toString();
              }
          } catch (UnknownHostException noIpAddrException) {
  
              //this machine is not on a LAN, or DNS is unhappy
              //return the default hostname
              if(log.isDebugEnabled()) {
                  log.debug("Failed to lookup local IP address",noIpAddrException);
              }
              hostname = LOCALHOST;
          }
          return hostname;
      }
  }
  
  
  

Mime
View raw message