vmassol 2003/06/22 02:29:22
Modified: framework/src/java/share/org/apache/cactus
AbstractWebServerTestCase.java
Added: framework/src/java/share/org/apache/cactus/util NetUtil.java
Log:
Moved out the generic getIp() method to a standalone NetUtil class
Revision Changes Path
1.1
jakarta-cactus/framework/src/java/share/org/apache/cactus/util/NetUtil.java
Index: NetUtil.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Cactus" and "Apache Software
* Foundation" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.cactus.util;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* Various network related utility methods.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
* @version $Id: NetUtil.java,v 1.1 2003/06/22 09:29:22 vmassol Exp $
*/
public class NetUtil
{
/**
* @return the client machine's IP.
*/
public static final String getIp()
{
InetAddress ip;
try
{
ip = InetAddress.getLocalHost();
}
catch (UnknownHostException e)
{
throw new ChainedRuntimeException(e);
}
return ip.getHostAddress();
}
}
1.10 +7 -28
jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebServerTestCase.java
Index: AbstractWebServerTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebServerTestCase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AbstractWebServerTestCase.java 22 Jun 2003 03:39:14 -0000 1.9
+++ AbstractWebServerTestCase.java 22 Jun 2003 09:29:22 -0000 1.10
@@ -60,14 +60,12 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.HttpURLConnection;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import junit.framework.Test;
import org.apache.cactus.client.connector.http.DefaultHttpClient;
import org.apache.cactus.configuration.WebConfiguration;
-import org.apache.cactus.util.ChainedRuntimeException;
+import org.apache.cactus.util.NetUtil;
import org.apache.commons.logging.LogFactory;
/**
@@ -76,7 +74,7 @@
* on the server side.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
- * <a href="mailto:[EMAIL PROTECTED]>Nicholas Lesiecki</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]>Nicholas Lesiecki</a>
*
* @version $Id$
*/
@@ -313,35 +311,16 @@
}
id += "thread:" + Thread.currentThread().toString() + "_";
id += "runtime_hash:" + Runtime.getRuntime().hashCode() + "_";
- id += "client_ip:" + getIp() + "_";
+ id += "client_ip:" + NetUtil.getIp() + "_";
id += "time:" + System.currentTimeMillis() + "_";
return id;
}
/**
- * Obtains the client machine's IP.
+ * Shortcut to [EMAIL PROTECTED] WebRequest#addCactusCommand}.
*/
- private String getIp()
- {
- InetAddress thisIp;
- try
- {
- thisIp = InetAddress.getLocalHost();
- }
- catch (UnknownHostException e)
- {
- throw new ChainedRuntimeException(e);
- }
- return thisIp.getHostAddress();
- }
-
- /**
- * Shortcut to addCactusCommand.
- */
- private void addCactusCommand(
- String theCommandName,
- String theCommandValue,
- WebRequest theRequest)
+ private void addCactusCommand(String theCommandName,
+ String theCommandValue, WebRequest theRequest)
{
theRequest.addCactusCommand(theCommandName, theCommandValue);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]