You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/12/28 06:43:22 UTC

svn commit: r359403 - in /directory/trunk/mina-core: ./ src/main/java/org/apache/mina/filter/ src/main/java/org/apache/mina/filter/codec/textline/ src/main/java/org/apache/mina/util/ src/test/java/org/apache/mina/util/

Author: akarasulu
Date: Tue Dec 27 21:43:10 2005
New Revision: 359403

URL: http://svn.apache.org/viewcvs?rev=359403&view=rev
Log:
changes ...

 o Added CharsetUtils and weak test case for it
 o Removed dependencies on JDK 1.5 API's:
   - Charset.defaultCharset();
   - IllegalArgumentException( String, Throwable ) (used logger with exception)
 o Added excludes to tests for DatagramBindTest and VmPipeTrafficControlTest.
   These tests are prone to a timing related bug in JDK 1.5 which is due to 
   file descriptor cleanup issues which need garbage collection. Until a work
   around is implemented we will ignore these tests.


Added:
    directory/trunk/mina-core/src/main/java/org/apache/mina/util/CharsetUtil.java
    directory/trunk/mina-core/src/test/java/org/apache/mina/util/CharsetUtilTest.java
Modified:
    directory/trunk/mina-core/pom.xml
    directory/trunk/mina-core/src/main/java/org/apache/mina/filter/BlacklistFilter.java
    directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java
    directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java
    directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java

Modified: directory/trunk/mina-core/pom.xml
URL: http://svn.apache.org/viewcvs/directory/trunk/mina-core/pom.xml?rev=359403&r1=359402&r2=359403&view=diff
==============================================================================
--- directory/trunk/mina-core/pom.xml (original)
+++ directory/trunk/mina-core/pom.xml Tue Dec 27 21:43:10 2005
@@ -102,6 +102,11 @@
         <configuration>
           <excludes>
             <exclude>**/Abstract*</exclude>
+
+            <!-- Timing issues with these tests due to VM bug for releasing file descriptors -->
+            <exclude>**/DatagramBindTest.java</exclude>
+            <exclude>**/VmPipeTrafficControlTest.java</exclude>
+
             <exclude>**/*RegressionTest*</exclude>
           </excludes>
         </configuration>

Modified: directory/trunk/mina-core/src/main/java/org/apache/mina/filter/BlacklistFilter.java
URL: http://svn.apache.org/viewcvs/directory/trunk/mina-core/src/main/java/org/apache/mina/filter/BlacklistFilter.java?rev=359403&r1=359402&r2=359403&view=diff
==============================================================================
--- directory/trunk/mina-core/src/main/java/org/apache/mina/filter/BlacklistFilter.java (original)
+++ directory/trunk/mina-core/src/main/java/org/apache/mina/filter/BlacklistFilter.java Tue Dec 27 21:43:10 2005
@@ -30,6 +30,8 @@
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.util.SessionLog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A {@link IoFilter} which blocks connections from blacklisted remote
@@ -40,6 +42,8 @@
  */
 public class BlacklistFilter extends IoFilterAdapter
 {
+    private static final Logger log = LoggerFactory.getLogger( BlacklistFilter.class );
+    
     private final Set blacklist = new HashSet();
 
     /**
@@ -87,9 +91,9 @@
         }
         catch ( ArrayStoreException ase )
         {
-            throw new IllegalArgumentException(
-                    "Collection of addresses must contain only " +
-                    "InetAddress instances", ase );
+            String msg = "Collection of addresses must contain only InetAddress instances";
+            log.error( msg, ase );
+            throw new IllegalArgumentException( msg );
         }
     }
     

Modified: directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java?rev=359403&r1=359402&r2=359403&view=diff
==============================================================================
--- directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java (original)
+++ directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java Tue Dec 27 21:43:10 2005
@@ -24,6 +24,7 @@
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.apache.mina.filter.codec.ProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.util.CharsetUtil;
 
 /**
  * A {@link ProtocolCodecFactory} that performs encoding and decoding between
@@ -43,7 +44,7 @@
      */
     public TextLineCodecFactory()
     {
-        this( Charset.defaultCharset() );
+        this( Charset.forName( CharsetUtil.getDefaultEncoding() ) );
     }
     
     /**

Modified: directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java
URL: http://svn.apache.org/viewcvs/directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java?rev=359403&r1=359402&r2=359403&view=diff
==============================================================================
--- directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java (original)
+++ directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineDecoder.java Tue Dec 27 21:43:10 2005
@@ -27,6 +27,7 @@
 import org.apache.mina.common.IoSession;
 import org.apache.mina.filter.codec.ProtocolDecoder;
 import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.util.CharsetUtil;
 
 /**
  * A {@link ProtocolDecoder} which decodes a text line into a string.
@@ -49,7 +50,7 @@
      */
     public TextLineDecoder()
     {
-        this( Charset.defaultCharset(), LineDelimiter.AUTO );
+        this( CharsetUtil.getDefaultCharset(), LineDelimiter.AUTO );
     }
     
     /**

Modified: directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java
URL: http://svn.apache.org/viewcvs/directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java?rev=359403&r1=359402&r2=359403&view=diff
==============================================================================
--- directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java (original)
+++ directory/trunk/mina-core/src/main/java/org/apache/mina/filter/codec/textline/TextLineEncoder.java Tue Dec 27 21:43:10 2005
@@ -26,6 +26,7 @@
 import org.apache.mina.filter.codec.ProtocolEncoder;
 import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
 import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.util.CharsetUtil;
 
 /**
  * A {@link ProtocolEncoder} which encodes a string into a text line
@@ -44,12 +45,12 @@
 
     public TextLineEncoder()
     {
-        this( Charset.defaultCharset(), LineDelimiter.UNIX );
+        this( CharsetUtil.getDefaultCharset(), LineDelimiter.UNIX );
     }
     
     public TextLineEncoder( LineDelimiter delimiter )
     {
-        this( Charset.defaultCharset(), delimiter );
+        this( CharsetUtil.getDefaultCharset(), delimiter );
     }
     
     public TextLineEncoder( Charset charset )

Added: directory/trunk/mina-core/src/main/java/org/apache/mina/util/CharsetUtil.java
URL: http://svn.apache.org/viewcvs/directory/trunk/mina-core/src/main/java/org/apache/mina/util/CharsetUtil.java?rev=359403&view=auto
==============================================================================
--- directory/trunk/mina-core/src/main/java/org/apache/mina/util/CharsetUtil.java (added)
+++ directory/trunk/mina-core/src/main/java/org/apache/mina/util/CharsetUtil.java Tue Dec 27 21:43:10 2005
@@ -0,0 +1,83 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Utilities for dealing with Charsets.
+ *
+ * @author MINA Project Team (mina-dev@directory.apache.org)
+ * @version $Rev$
+ */
+public class CharsetUtil
+{
+    public static final Logger log = LoggerFactory.getLogger( CharsetUtil.class );
+    
+    
+    public static final String getDefaultEncoding()
+    {
+        String encoding = null;
+        String version = System.getProperty( "java.version" );
+        
+        if ( version.startsWith( "1.5" ) || version.startsWith( "5.0" ) )
+        {
+            // Use reflection here to be able to compile mina with jdk 1.4
+            try
+            {
+                Class charsetClass = Class.forName( "java.nio.charset.Charset" );
+                Object charSet = charsetClass.getMethod( "defaultCharset", null ).invoke( null, null );
+                encoding = ( String ) charsetClass.getMethod( "name", null ).invoke( charSet, null );
+            }
+            catch ( Exception e )
+            {
+                log.error( "Failed to call java.nio.charset.Charset.defaultCharset().name() on JDK 1.5" );
+                throw new RuntimeException( e );
+            }
+        }
+        else if ( version.startsWith( "1.4" ) )
+        {
+            OutputStreamWriter writer = new OutputStreamWriter( new ByteArrayOutputStream() );
+            encoding = writer.getEncoding();
+        }
+        else if ( version.startsWith( "1.3" ) )
+        {
+            log.warn( "Character encoding determined in non-standard manner for JDK 1.3" );
+            encoding = System.getProperty( "file.encoding" );
+        }
+        else
+        {
+            throw new IllegalStateException( "JDK version is not compatible." );
+        }
+        
+        return encoding;
+    }
+
+
+    public static Charset getDefaultCharset()
+    {
+        return Charset.forName( getDefaultEncoding() );
+    }
+}

Added: directory/trunk/mina-core/src/test/java/org/apache/mina/util/CharsetUtilTest.java
URL: http://svn.apache.org/viewcvs/directory/trunk/mina-core/src/test/java/org/apache/mina/util/CharsetUtilTest.java?rev=359403&view=auto
==============================================================================
--- directory/trunk/mina-core/src/test/java/org/apache/mina/util/CharsetUtilTest.java (added)
+++ directory/trunk/mina-core/src/test/java/org/apache/mina/util/CharsetUtilTest.java Tue Dec 27 21:43:10 2005
@@ -0,0 +1,37 @@
+/*
+ *   @(#) $Id$
+ *
+ *   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.mina.util;
+
+import junit.framework.TestCase;
+
+/**
+ * A test case for CharsetUtil.
+ * 
+ * @author MINA Project Team (mina-dev@directory.apache.org)
+ * @version $Rev$
+ */
+public class CharsetUtilTest extends TestCase
+{
+    public void testGetDefaultEncoding()
+    {
+        // @todo How the heck do I test this so it works on all machines running test?
+        String encoding = CharsetUtil.getDefaultEncoding();
+        assertNotNull( encoding );
+    }
+}



Re: svn commit: r359403 - in /directory/trunk/mina-core: ./ src/main/java/org/apache/mina/filter/ src/main/java/org/apache/mina/filter/codec/textline/ src/main/java/org/apache/mina/util/ src/test/java/org/apache/mina/util/

Posted by Alex Karasulu <ao...@bellsouth.net>.
Trustin Lee wrote:

> 2005/12/28, akarasulu@apache.org <ma...@apache.org> 
> <akarasulu@apache.org <ma...@apache.org>>:
>
>     -            throw new IllegalArgumentException(
>     -                    "Collection of addresses must contain only " +
>     -                    "InetAddress instances", ase );
>     +            String msg = "Collection of addresses must contain
>     only InetAddress instances";
>     +            log.error( msg, ase );
>     +            throw new IllegalArgumentException( msg );
>
>
> What about this?
>
> throw ( IllegalArgumentException ) new IllegalArgumentException( ... 
> ).initCause( ase );


Much better ... did not know it existed and was available in 1.3.  Will 
add it. 

Thanks,
Alex


Re: svn commit: r359403 - in /directory/trunk/mina-core: ./ src/main/java/org/apache/mina/filter/ src/main/java/org/apache/mina/filter/codec/textline/ src/main/java/org/apache/mina/util/ src/test/java/org/apache/mina/util/

Posted by Trustin Lee <tr...@gmail.com>.
2005/12/28, akarasulu@apache.org <ak...@apache.org>:
>
> -            throw new IllegalArgumentException(
> -                    "Collection of addresses must contain only " +
> -                    "InetAddress instances", ase );
> +            String msg = "Collection of addresses must contain only
> InetAddress instances";
> +            log.error( msg, ase );
> +            throw new IllegalArgumentException( msg );


What about this?

throw ( IllegalArgumentException ) new IllegalArgumentException( ...
).initCause( ase );

Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
PGP Key ID: 0x854B996C