http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PartiallyRepeatableHttpEntityTest.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PartiallyRepeatableHttpEntityTest.java b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PartiallyRepeatableHttpEntityTest.java index c10a02c..4865d01 100644 --- a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PartiallyRepeatableHttpEntityTest.java +++ b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PartiallyRepeatableHttpEntityTest.java @@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -36,8 +37,6 @@ import static org.junit.Assert.fail; public class PartiallyRepeatableHttpEntityTest { - private static Charset UTF8 = Charset.forName( "UTF-8" ); - // Variables // Consumers: C1, C2 // Reads: FC - Full Content, PC - Partial Content, AC - Any Content @@ -71,7 +70,7 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); String output; @@ -87,12 +86,12 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); String output; - output = blockRead( replay.getContent(), UTF8, -1, 3 ); + output = blockRead( replay.getContent(), StandardCharsets.UTF_8, -1, 3 ); assertThat( output, is( data ) ); } @@ -103,7 +102,7 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); String output; @@ -119,12 +118,12 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); String output; - output = blockRead( replay.getContent(), UTF8, -1, 3 ); + output = blockRead( replay.getContent(), StandardCharsets.UTF_8, -1, 3 ); assertThat( output, is( data ) ); } @@ -135,7 +134,7 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); String output; @@ -154,15 +153,15 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); String output; - output = blockRead( replay.getContent(), UTF8, -1, 3 ); + output = blockRead( replay.getContent(), StandardCharsets.UTF_8, -1, 3 ); assertThat( output, is( data ) ); - output = blockRead( replay.getContent(), UTF8, -1, 3 ); + output = blockRead( replay.getContent(), StandardCharsets.UTF_8, -1, 3 ); assertThat( output, is( data ) ); } @@ -173,7 +172,7 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); String output; @@ -196,12 +195,12 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); String output; - output = blockRead( replay.getContent(), UTF8, -1, 3 ); + output = blockRead( replay.getContent(), StandardCharsets.UTF_8, -1, 3 ); assertThat( output, is( data ) ); try { @@ -222,7 +221,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream = replay.getContent(); text = byteRead( stream, -1 ); @@ -244,16 +243,16 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, -1, 3 ); + text = blockRead( stream, StandardCharsets.UTF_8, -1, 3 ); assertThat( text, is( "0123456789" ) ); stream.close(); stream = replay.getContent(); - text = blockRead( stream, UTF8, -1, 3 ); + text = blockRead( stream, StandardCharsets.UTF_8, -1, 3 ); assertThat( text, is( "0123456789" ) ); } @@ -267,7 +266,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream = replay.getContent(); @@ -293,11 +292,11 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, -1, 3 ); + text = blockRead( stream, StandardCharsets.UTF_8, -1, 3 ); assertThat( text, is( "0123456789" ) ); stream.close(); @@ -319,7 +318,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream = replay.getContent(); @@ -337,11 +336,11 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, 3, 3 ); + text = blockRead( stream, StandardCharsets.UTF_8, 3, 3 ); assertThat( text, is( "012" ) ); } @@ -355,7 +354,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream = replay.getContent(); @@ -374,11 +373,11 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, -1, 4 ); + text = blockRead( stream, StandardCharsets.UTF_8, -1, 4 ); assertThat( text, is( "0123456789" ) ); stream.close(); } @@ -393,7 +392,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream = replay.getContent(); @@ -416,16 +415,16 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, 4, 1 ); + text = blockRead( stream, StandardCharsets.UTF_8, 4, 1 ); assertThat( text, is( "0123" ) ); stream.close(); stream = replay.getContent(); - text = blockRead( stream, UTF8, -1, 7 ); + text = blockRead( stream, StandardCharsets.UTF_8, -1, 7 ); assertThat( text, is( "0123456789" ) ); } @@ -439,7 +438,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream = replay.getContent(); @@ -465,11 +464,11 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, 7, 2 ); + text = blockRead( stream, StandardCharsets.UTF_8, 7, 2 ); assertThat( text, is( "0123456" ) ); stream.close(); @@ -491,7 +490,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream = replay.getContent(); @@ -514,16 +513,16 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, 7, 2 ); + text = blockRead( stream, StandardCharsets.UTF_8, 7, 2 ); assertThat( text, is( "0123456" ) ); stream.close(); stream = replay.getContent(); - text = blockRead( stream, UTF8, -1, 7 ); + text = blockRead( stream, StandardCharsets.UTF_8, -1, 7 ); assertThat( text, is( "0123456789" ) ); } @@ -537,7 +536,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream = replay.getContent(); @@ -563,11 +562,11 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, 7, 2 ); + text = blockRead( stream, StandardCharsets.UTF_8, 7, 2 ); assertThat( text, is( "0123456" ) ); stream.close(); @@ -589,7 +588,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream1 = replay.getContent(); @@ -614,17 +613,17 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 20 ); stream1 = replay.getContent(); - text = blockRead( stream1, UTF8, 3, 2 ); + text = blockRead( stream1, StandardCharsets.UTF_8, 3, 2 ); assertThat( text, is( "012" ) ); stream2 = replay.getContent(); - text = blockRead( stream2, UTF8, 4, 3 ); + text = blockRead( stream2, StandardCharsets.UTF_8, 4, 3 ); assertThat( text, is( "0123" ) ); - text = blockRead( stream1, UTF8, 3, 2 ); + text = blockRead( stream1, StandardCharsets.UTF_8, 3, 2 ); assertThat( text, is( "345" ) ); } @@ -638,7 +637,7 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream1 = replay.getContent(); @@ -667,19 +666,19 @@ public class PartiallyRepeatableHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); stream1 = replay.getContent(); - text = blockRead( stream1, UTF8, 3, 2 ); + text = blockRead( stream1, StandardCharsets.UTF_8, 3, 2 ); assertThat( text, is( "012" ) ); stream2 = replay.getContent(); - text = blockRead( stream2, UTF8, 6, 4 ); + text = blockRead( stream2, StandardCharsets.UTF_8, 6, 4 ); assertThat( text, is( "012345" ) ); try { - blockRead( stream1, UTF8, 6, 4 ); + blockRead( stream1, StandardCharsets.UTF_8, 6, 4 ); fail( "Expected IOException" ); } catch ( IOException e ) { // Expected. @@ -693,12 +692,12 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); replay.writeTo( buffer ); - String output = new String( buffer.toByteArray(), UTF8 ); + String output = new String( buffer.toByteArray(), StandardCharsets.UTF_8 ); assertThat( output, is( input ) ); } @@ -709,12 +708,12 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( text.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( text.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic ); assertThat( replay.isRepeatable(), is( true ) ); basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( text.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( text.getBytes( StandardCharsets.UTF_8 ) ) ); BufferedHttpEntity buffered = new BufferedHttpEntity( basic ); replay = new PartiallyRepeatableHttpEntity( buffered ); assertThat( replay.isRepeatable(), is( true ) ); @@ -727,12 +726,12 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.isChunked(), is( false ) ); basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); basic.setChunked( true ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.isChunked(), is( true ) ); @@ -745,12 +744,12 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.getContentLength(), is( -1L ) ); basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); basic.setContentLength( input.length() ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.getContentLength(), is( 10L ) ); @@ -763,12 +762,12 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.getContentType(), nullValue() ); basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); basic.setContentType( ContentType.APPLICATION_JSON.getMimeType() ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.getContentType().getValue(), is( "application/json" ) ); @@ -781,15 +780,15 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.getContentEncoding(), nullValue() ); basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); - basic.setContentEncoding( "UTF-8" ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); + basic.setContentEncoding( StandardCharsets.UTF_8.name() ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); - assertThat( replay.getContentEncoding().getValue(), is( "UTF-8" ) ); + assertThat( replay.getContentEncoding().getValue(), is( StandardCharsets.UTF_8.name() ) ); } @Test @@ -800,7 +799,7 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.isStreaming(), is( true ) ); @@ -809,7 +808,7 @@ public class PartiallyRepeatableHttpEntityTest { replay = new PartiallyRepeatableHttpEntity( basic, 5 ); assertThat( replay.isStreaming(), is( false ) ); - streaming = new InputStreamEntity( new ByteArrayInputStream( input.getBytes( UTF8 ) ), 10, ContentType.TEXT_PLAIN ); + streaming = new InputStreamEntity( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ), 10, ContentType.TEXT_PLAIN ); replay = new PartiallyRepeatableHttpEntity( streaming, 5 ); assertThat( replay.isStreaming(), is( true ) ); } @@ -821,7 +820,7 @@ public class PartiallyRepeatableHttpEntityTest { PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new PartiallyRepeatableHttpEntity( basic, 5 ); try {
http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java ---------------------------------------------------------------------- diff --git a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java index 7a3e909..f011cbf 100644 --- a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java +++ b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestDriver.java @@ -29,7 +29,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.UnknownHostException; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.FileSystems; import java.nio.file.Path; import java.util.HashMap; @@ -290,8 +290,8 @@ public class GatewayTestDriver { return IOUtils.toByteArray( getResourceStream( resource ) ); } - public String getResourceString( String resource, Charset charset ) throws IOException { - return IOUtils.toString( getResourceBytes( resource ), "UTF-8" ); + public String getResourceString( String resource ) throws IOException { + return IOUtils.toString( getResourceBytes( resource ), StandardCharsets.UTF_8.name() ); } public void assertComplete() { http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test-utils/src/main/java/org/apache/knox/test/Console.java ---------------------------------------------------------------------- diff --git a/gateway-test-utils/src/main/java/org/apache/knox/test/Console.java b/gateway-test-utils/src/main/java/org/apache/knox/test/Console.java index 80ffa65..e29c0d0 100644 --- a/gateway-test-utils/src/main/java/org/apache/knox/test/Console.java +++ b/gateway-test-utils/src/main/java/org/apache/knox/test/Console.java @@ -20,6 +20,7 @@ package org.apache.knox.test; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; public class Console { @@ -30,11 +31,11 @@ public class Console { public void capture() throws UnsupportedEncodingException { oldErr = System.err; newErrBuf = new ByteArrayOutputStream(); - newErr = new PrintStream( newErrBuf, false, "UTF-8" ); + newErr = new PrintStream( newErrBuf, false, StandardCharsets.UTF_8.name() ); oldOut = System.out; // I18N not required. newOutBuf = new ByteArrayOutputStream(); - newOut = new PrintStream( newOutBuf, false, "UTF-8" ); + newOut = new PrintStream( newOutBuf, false, StandardCharsets.UTF_8.name() ); System.setErr( newErr ); System.setOut( newOut ); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java ---------------------------------------------------------------------- diff --git a/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java b/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java index 18ec845..9374b46 100644 --- a/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java +++ b/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java @@ -41,6 +41,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.URL; import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Locale; import java.util.Properties; @@ -89,15 +90,15 @@ public class TestUtils { return stream; } - public static Reader getResourceReader( String name, String charset ) throws IOException { + public static Reader getResourceReader( String name, Charset charset ) throws IOException { return new InputStreamReader( getResourceStream( name ), charset ); } - public static Reader getResourceReader( Class clazz, String name, String charset ) throws IOException { + public static Reader getResourceReader( Class clazz, String name, Charset charset ) throws IOException { return new InputStreamReader( getResourceStream( clazz, name ), charset ); } - public static String getResourceString( Class clazz, String name, String charset ) throws IOException { + public static String getResourceString( Class clazz, String name, Charset charset ) throws IOException { return IOUtils.toString( getResourceReader( clazz, name, charset ) ); } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockRequestMatcher.java ---------------------------------------------------------------------- diff --git a/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockRequestMatcher.java b/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockRequestMatcher.java index ee36e8a..46d3316 100644 --- a/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockRequestMatcher.java +++ b/gateway-test-utils/src/main/java/org/apache/knox/test/mock/MockRequestMatcher.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -50,8 +51,6 @@ import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; public class MockRequestMatcher { - private static final Charset UTF8 = Charset.forName( "UTF-8" ); - private String from; private MockResponseProvider response; private Set<String> methods = null; @@ -292,15 +291,15 @@ public class MockRequestMatcher { if( entity != null ) { if( contentType != null && contentType.endsWith( "/xml" ) ) { String expectEncoding = characterEncoding; - String expect = new String( entity, ( expectEncoding == null ? UTF8.name() : expectEncoding ) ); + String expect = new String( entity, ( expectEncoding == null ? StandardCharsets.UTF_8.name() : expectEncoding ) ); String actualEncoding = request.getCharacterEncoding(); - String actual = IOUtils.toString( request.getInputStream(), actualEncoding == null ? UTF8.name() : actualEncoding ); + String actual = IOUtils.toString( request.getInputStream(), actualEncoding == null ? StandardCharsets.UTF_8.name() : actualEncoding ); assertThat( the( actual ), isEquivalentTo( the( expect ) ) ); } else if ( contentType != null && contentType.endsWith( "/json" ) ) { String expectEncoding = characterEncoding; - String expect = new String( entity, ( expectEncoding == null ? UTF8.name() : expectEncoding ) ); + String expect = new String( entity, ( expectEncoding == null ? StandardCharsets.UTF_8.name() : expectEncoding ) ); String actualEncoding = request.getCharacterEncoding(); - String actual = IOUtils.toString( request.getInputStream(), actualEncoding == null ? UTF8.name() : actualEncoding ); + String actual = IOUtils.toString( request.getInputStream(), actualEncoding == null ? StandardCharsets.UTF_8.name() : actualEncoding ); // System.out.println( "EXPECT=" + expect ); // System.out.println( "ACTUAL=" + actual ); assertThat( actual, sameJSONAs( expect ) ); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java index c2a5acc..40822c3 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAdminTopologyFuncTest.java @@ -1261,7 +1261,7 @@ public class GatewayAdminTopologyFuncTest { given() .auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_XML) - .body(newProviderConfigXML.toBytes("utf-8")) + .body(newProviderConfigXML.toBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_CREATED) .when().put(serviceUrl + "/" + newProviderConfigName); @@ -1320,7 +1320,7 @@ public class GatewayAdminTopologyFuncTest { // Attempt to PUT a provider config given().auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_XML) - .body(newProviderConfigXML.toBytes("utf-8")) + .body(newProviderConfigXML.toBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_BAD_REQUEST) .when().put(serviceUrl + "/" + newProviderConfigName); @@ -1459,7 +1459,7 @@ public class GatewayAdminTopologyFuncTest { given() .auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(newDescriptorJSON.getBytes("utf-8")) + .body(newDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_CREATED) .when().put(descriptorsUrl + "/" + descriptorName); @@ -1485,7 +1485,7 @@ public class GatewayAdminTopologyFuncTest { given() .auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(updatedDescriptorJSON.getBytes("utf-8")) + .body(updatedDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_NO_CONTENT) .when().put(descriptorsUrl + "/" + descriptorName); @@ -1516,7 +1516,7 @@ public class GatewayAdminTopologyFuncTest { given() .auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(updatedDescriptorJSON.getBytes("utf-8")) + .body(updatedDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_NO_CONTENT) .when().put(descriptorsUrl + "/" + descriptorName); @@ -1593,7 +1593,7 @@ public class GatewayAdminTopologyFuncTest { given() .auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(newDescriptorJSON.getBytes("utf-8")) + .body(newDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_CREATED) .when().put(descriptorsUrl + "/" + descriptorName); @@ -1632,7 +1632,7 @@ public class GatewayAdminTopologyFuncTest { given() .auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(updatedDescriptorJSON.getBytes("utf-8")) + .body(updatedDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_NO_CONTENT) .when().put(descriptorsUrl + "/" + descriptorName); @@ -1782,7 +1782,7 @@ public class GatewayAdminTopologyFuncTest { given() .auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_XML) - .body(newDescriptorJSON.getBytes("utf-8")) + .body(newDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE) .when().put(serviceUrl + "/" + newDescriptorName); @@ -1791,7 +1791,7 @@ public class GatewayAdminTopologyFuncTest { given() .auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(newDescriptorJSON.getBytes("utf-8")) + .body(newDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_CREATED) .when().put(serviceUrl + "/" + newDescriptorName); @@ -1835,7 +1835,7 @@ public class GatewayAdminTopologyFuncTest { public void testPutDescriptorWithValidEncodedName() throws Exception { final String encodedName = "new%2Ddescriptor"; - final String newDescriptorName = URLDecoder.decode(encodedName, "UTF-8"); + final String newDescriptorName = URLDecoder.decode(encodedName, StandardCharsets.UTF_8.name()); final String username = "admin"; final String password = "admin-password"; @@ -1849,7 +1849,7 @@ public class GatewayAdminTopologyFuncTest { // Attempt to PUT the descriptor given().auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(newDescriptorJSON.getBytes("utf-8")) + .body(newDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_CREATED) .when().put(serviceUrl + "/" + encodedName); @@ -1897,7 +1897,7 @@ public class GatewayAdminTopologyFuncTest { // Attempt to PUT the descriptor given().auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(newDescriptorJSON.getBytes("utf-8")) + .body(newDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_CREATED) .when().put(serviceUrl + "/" + newDescriptorFileName); @@ -1932,7 +1932,7 @@ public class GatewayAdminTopologyFuncTest { public void testPutDescriptorWithInvalidEncodedName() throws Exception { final String encodedName = "'';!--%22%3CXSS%3E=&%7B()%7D"; - final String newDescriptorName = URLDecoder.decode(encodedName, "UTF-8"); + final String newDescriptorName = URLDecoder.decode(encodedName, StandardCharsets.UTF_8.name()); final String username = "admin"; final String password = "admin-password"; @@ -1946,7 +1946,7 @@ public class GatewayAdminTopologyFuncTest { // Attempt to PUT the descriptor given().auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(newDescriptorJSON.getBytes("utf-8")) + .body(newDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_BAD_REQUEST) .when().put(serviceUrl + "/" + encodedName); @@ -2018,7 +2018,7 @@ public class GatewayAdminTopologyFuncTest { // Attempt to PUT the descriptor given().auth().preemptive().basic(username, password) .header("Content-type", MediaType.APPLICATION_JSON) - .body(newDescriptorJSON.getBytes("utf-8")) + .body(newDescriptorJSON.getBytes(StandardCharsets.UTF_8.name())) .then() .statusCode(HttpStatus.SC_BAD_REQUEST) .when().put(serviceUrl + "/" + newDescriptorName); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java index 12c668e..dd45993 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayAppFuncTest.java @@ -19,7 +19,6 @@ package org.apache.knox.gateway; import java.io.File; import java.net.URL; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; @@ -415,7 +414,7 @@ public class GatewayAppFuncTest { .queryParam( "user.name", "guest" ) .respond() .status( HttpStatus.SC_OK ) - .content( "{\"path\":\"/users/guest\"}", Charset.forName("UTF-8") ) + .content( "{\"path\":\"/users/guest\"}", StandardCharsets.UTF_8 ) .contentType( "application/json" ); given() //.log().all() http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java index 2fe73b6..997cbee 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayBasicFuncTest.java @@ -81,7 +81,6 @@ import java.net.InetSocketAddress; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Locale; @@ -107,9 +106,6 @@ import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs; @Category( { VerifyTest.class, MediumTests.class } ) public class GatewayBasicFuncTest { - - private static final Charset UTF8 = Charset.forName("UTF-8"); - // Uncomment to cause the test to hang after the gateway instance is setup. // This will allow the gateway instance to be hit directly via some external client. // @Test @@ -1082,7 +1078,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/open-session-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/open-session-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1107,7 +1103,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/execute-set-fetch-output-serde-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/execute-set-fetch-output-serde-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1131,7 +1127,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/close-operation-1-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/close-operation-1-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1155,7 +1151,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/execute-set-server2-http-path-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/execute-set-server2-http-path-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1179,7 +1175,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/close-operation-2-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/close-operation-2-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1203,7 +1199,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/execute-set-server2-servermode-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/execute-set-server2-servermode-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1227,7 +1223,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/close-operation-3-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/close-operation-3-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1251,7 +1247,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/execute-set-security-authorization-enabled-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/execute-set-security-authorization-enabled-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1275,7 +1271,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/close-operation-4-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/close-operation-4-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1299,7 +1295,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/execute-create-table-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/execute-create-table-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1323,7 +1319,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/close-operation-5-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/close-operation-5-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1347,7 +1343,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/execute-select-from-table-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/execute-select-from-table-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1371,7 +1367,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/get-result-set-metadata-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/get-result-set-metadata-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1395,7 +1391,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/fetch-results-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/fetch-results-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1419,7 +1415,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/close-operation-6-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/close-operation-6-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1443,7 +1439,7 @@ public class GatewayBasicFuncTest { .content( driver.getResourceBytes( "hive/close-session-request.bin" ) ) .contentType( "application/x-thrift" ) .respond() - .characterEncoding( "UTF-8" ) + .characterEncoding( StandardCharsets.UTF_8.name() ) .status( HttpStatus.SC_OK ) .content( driver.getResourceBytes( "hive/close-session-result.bin" ) ) .contentType( "application/x-thrift" ); @@ -1491,7 +1487,7 @@ public class GatewayBasicFuncTest { MatcherAssert .assertThat( the( response.getBody().asString() ), - isEquivalentTo( the( driver.getResourceString( resourceName + ".xml", UTF8 ) ) ) ); + isEquivalentTo( the( driver.getResourceString( resourceName + ".xml" ) ) ) ); driver.assertComplete(); driver.getMock( "WEBHBASE" ) @@ -1514,7 +1510,7 @@ public class GatewayBasicFuncTest { .when().get( driver.getUrl( "WEBHBASE" ) ); MatcherAssert - .assertThat( response.getBody().asString(), sameJSONAs( driver.getResourceString( resourceName + ".json", UTF8 ) ) ); + .assertThat( response.getBody().asString(), sameJSONAs( driver.getResourceString( resourceName + ".json") ) ); driver.assertComplete(); driver.getMock( "WEBHBASE" ) @@ -1524,7 +1520,7 @@ public class GatewayBasicFuncTest { .header( "Accept", "application/x-protobuf" ) .respond() .status( HttpStatus.SC_OK ) - .content( driver.getResourceString( resourceName + ".protobuf", UTF8 ), UTF8 ) + .content( driver.getResourceString( resourceName + ".protobuf"), StandardCharsets.UTF_8 ) .contentType( "application/x-protobuf" ); given() @@ -1534,7 +1530,7 @@ public class GatewayBasicFuncTest { .then() .statusCode( HttpStatus.SC_OK ) .contentType( "application/x-protobuf" ) - .body( is( driver.getResourceString( resourceName + ".protobuf", UTF8 ) ) ) + .body( is( driver.getResourceString( resourceName + ".protobuf") ) ) .when().get( driver.getUrl( "WEBHBASE" ) ); driver.assertComplete(); LOG_EXIT(); @@ -1641,7 +1637,7 @@ public class GatewayBasicFuncTest { MatcherAssert .assertThat( the(response.getBody().asString()), - isEquivalentTo(the(driver.getResourceString(resourceName + ".xml", UTF8)))); + isEquivalentTo(the(driver.getResourceString(resourceName + ".xml")))); driver.assertComplete(); driver.getMock("WEBHBASE") @@ -1664,7 +1660,7 @@ public class GatewayBasicFuncTest { .when().get( driver.getUrl( "WEBHBASE" ) + path ); MatcherAssert - .assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resourceName + ".json", UTF8))); + .assertThat(response.getBody().asString(), sameJSONAs(driver.getResourceString(resourceName + ".json"))); driver.assertComplete(); driver.getMock( "WEBHBASE" ) @@ -1929,7 +1925,7 @@ public class GatewayBasicFuncTest { MatcherAssert .assertThat( the(response.getBody().asString()), - isEquivalentTo(the(driver.getResourceString(resourceName + ".xml", UTF8)))); + isEquivalentTo(the(driver.getResourceString(resourceName + ".xml")))); driver.assertComplete(); driver.getMock( "WEBHBASE" ) @@ -1954,7 +1950,7 @@ public class GatewayBasicFuncTest { MatcherAssert .assertThat( the(response.getBody().asString()), - isEquivalentTo(the(driver.getResourceString(resourceName + ".xml", UTF8)))); + isEquivalentTo(the(driver.getResourceString(resourceName + ".xml")))); driver.assertComplete(); driver.getMock( "WEBHBASE" ) @@ -1977,7 +1973,7 @@ public class GatewayBasicFuncTest { .when().get( driver.getUrl( "WEBHBASE" ) + rowsWithKeyPath ); MatcherAssert - .assertThat( response.getBody().asString(), sameJSONAs( driver.getResourceString( resourceName + ".json", UTF8 ) ) ); + .assertThat( response.getBody().asString(), sameJSONAs( driver.getResourceString( resourceName + ".json") ) ); driver.assertComplete(); driver.getMock( "WEBHBASE" ) @@ -2000,7 +1996,7 @@ public class GatewayBasicFuncTest { .when().get( driver.getUrl( "WEBHBASE" ) + rowsWithKeyAndColumnPath ); MatcherAssert - .assertThat( response.getBody().asString(), sameJSONAs( driver.getResourceString( resourceName + ".json", UTF8 ) ) ); + .assertThat( response.getBody().asString(), sameJSONAs( driver.getResourceString( resourceName + ".json") ) ); driver.assertComplete(); LOG_EXIT(); } @@ -2059,7 +2055,7 @@ public class GatewayBasicFuncTest { MatcherAssert .assertThat( the(response.getBody().asString()), - isEquivalentTo(the(driver.getResourceString(tableDataResourceName + ".xml", UTF8)))); + isEquivalentTo(the(driver.getResourceString(tableDataResourceName + ".xml")))); driver.assertComplete(); //Delete scanner @@ -2452,12 +2448,12 @@ public class GatewayBasicFuncTest { switch( contentType ) { case JSON: MatcherAssert.assertThat( response.getBody().asString(), - sameJSONAs( driver.getResourceString( resource, UTF8 ) ) ); + sameJSONAs( driver.getResourceString( resource ) ) ); break; case XML: MatcherAssert .assertThat( the( response.getBody().asString() ), - isEquivalentTo( the( driver.getResourceString( resource, UTF8 ) ) ) ); + isEquivalentTo( the( driver.getResourceString( resource ) ) ) ); break; default: break; @@ -2807,12 +2803,12 @@ public class GatewayBasicFuncTest { switch( contentType ) { case JSON: MatcherAssert.assertThat( response.getBody().asString(), - sameJSONAs( driver.getResourceString( resource, UTF8 ) ) ); + sameJSONAs( driver.getResourceString( resource ) ) ); break; case XML: MatcherAssert .assertThat( the( response.getBody().asString() ), - isEquivalentTo(the(driver.getResourceString(resource, UTF8))) ); + isEquivalentTo(the(driver.getResourceString(resource))) ); break; default: break; @@ -2931,7 +2927,7 @@ public class GatewayBasicFuncTest { .statusCode(HttpStatus.SC_OK) .when().get( gatewayPath ); - Assert.assertEquals(response.getBody().asString(), driver.getResourceString( resourceName, UTF8 ) ); + Assert.assertEquals(response.getBody().asString(), driver.getResourceString( resourceName ) ); driver.assertComplete(); LOG_EXIT(); } @@ -3057,7 +3053,7 @@ public class GatewayBasicFuncTest { .when().get( gatewayPath ); MatcherAssert.assertThat(response.getBody().asString(), - sameJSONAs(driver.getResourceString(resourceName, UTF8))); + sameJSONAs(driver.getResourceString(resourceName))); driver.assertComplete(); LOG_EXIT(); } @@ -3119,12 +3115,12 @@ public class GatewayBasicFuncTest { switch( contentType ) { case JSON: MatcherAssert.assertThat( response.getBody().asString(), - sameJSONAs( driver.getResourceString( resourceName, UTF8 ) ) ); + sameJSONAs( driver.getResourceString( resourceName ) ) ); break; case XML: MatcherAssert .assertThat( the( response.getBody().asString() ), - isEquivalentTo( the( driver.getResourceString( resourceName, UTF8 ) ) ) ); + isEquivalentTo( the( driver.getResourceString( resourceName ) ) ) ); break; default: break; @@ -3185,12 +3181,12 @@ public class GatewayBasicFuncTest { switch( contentType ) { case JSON: MatcherAssert.assertThat( response.getBody().asString(), - sameJSONAs( driver.getResourceString( responseResource, UTF8 ) ) ); + sameJSONAs( driver.getResourceString( responseResource ) ) ); break; case XML: MatcherAssert .assertThat( the( response.getBody().asString() ), - isEquivalentTo( the( driver.getResourceString( responseResource, UTF8 ) ) ) ); + isEquivalentTo( the( driver.getResourceString( responseResource ) ) ) ); break; default: break; @@ -3327,7 +3323,7 @@ public class GatewayBasicFuncTest { .when().get( gatewayPath ); MatcherAssert.assertThat(response.getBody().asString(), - sameJSONAs(driver.getResourceString(resourceName, UTF8))); + sameJSONAs(driver.getResourceString(resourceName))); driver.assertComplete(); } @@ -3661,16 +3657,16 @@ public class GatewayBasicFuncTest { PrintStream out = System.out; InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0]; final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - System.setOut(new PrintStream(outContent, false, "UTF-8")); + System.setOut(new PrintStream(outContent, false, StandardCharsets.UTF_8.name())); String[] args = {"service-test", "--master", "knox", "--cluster", driver.clusterName, "--hostname", gatewayAddress.getHostName(), "--port", Integer.toString(gatewayAddress.getPort()), "--u", "kminder","--p", "kminder-password" }; KnoxCLI cli = new KnoxCLI(); cli.run(args); - assertThat(outContent.toString("UTF-8"), not(containsString("\"httpCode\": 401"))); - assertThat( outContent.toString("UTF-8"), not(containsString("404"))); - assertThat(outContent.toString("UTF-8"), not(containsString("403"))); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), not(containsString("\"httpCode\": 401"))); + assertThat( outContent.toString(StandardCharsets.UTF_8.name()), not(containsString("404"))); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), not(containsString("403"))); outContent.reset(); setupResources(); @@ -3681,7 +3677,7 @@ public class GatewayBasicFuncTest { cli = new KnoxCLI(); cli.run(args2); - assertThat(outContent.toString("UTF-8"), (containsString("Username and/or password not supplied. Expect HTTP 401 Unauthorized responses."))); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), (containsString("Username and/or password not supplied. Expect HTTP 401 Unauthorized responses."))); outContent.reset(); @@ -3690,7 +3686,7 @@ public class GatewayBasicFuncTest { cli = new KnoxCLI(); cli.run(args3); - assertThat(outContent.toString("UTF-8").toLowerCase(Locale.ROOT), + assertThat(outContent.toString(StandardCharsets.UTF_8.name()).toLowerCase(Locale.ROOT), either(containsString("nodename nor servname provided")).or(containsString("name or service not known")) .or(containsString("//bad-host:0/"))); outContent.reset(); @@ -3700,7 +3696,7 @@ public class GatewayBasicFuncTest { cli = new KnoxCLI(); cli.run(args4); - assertThat(outContent.toString("UTF-8"), containsString("failed: Connection refused")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("failed: Connection refused")); outContent.reset(); @@ -3709,7 +3705,7 @@ public class GatewayBasicFuncTest { cli = new KnoxCLI(); cli.run(args5); - assertThat(outContent.toString("UTF-8"), containsString("--cluster argument is required")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("--cluster argument is required")); outContent.reset(); // Reset the out content @@ -3782,7 +3778,7 @@ public class GatewayBasicFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); // .content(driver.getResourceBytes(classLoaderResource + "." + type.toString().toLowerCase(Locale.ROOT))) // .contentType(type.toString()); } @@ -3956,7 +3952,7 @@ public class GatewayBasicFuncTest { .when().get( driver.getUrl("WEBHDFS") + "/v1" + file + ( driver.isUseGateway() ? "" : "?user.name=" + user ) ); if( response.getStatusCode() == HttpStatus.SC_OK ) { String actualContent = response.asString(); - String thenedContent = driver.getResourceString( resource, Charset.forName("UTF-8") ); + String thenedContent = driver.getResourceString( resource ); assertThat( actualContent, Matchers.is(thenedContent) ); } driver.assertComplete(); @@ -4394,7 +4390,7 @@ public class GatewayBasicFuncTest { HttpPost post = new HttpPost( url.toURI() ); // post.getParams().setParameter( "action", "start" ); - StringEntity entity = new StringEntity( request, org.apache.http.entity.ContentType.create( "application/xml", "UTF-8" ) ); + StringEntity entity = new StringEntity( request, org.apache.http.entity.ContentType.create( "application/xml", StandardCharsets.UTF_8.name() ) ); post.setEntity( entity ); post.setHeader( "X-XSRF-Header", "ksdjfhdsjkfhds" ); HttpResponse response = client.execute( targetHost, post, context ); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java index 201cea5..f51282a 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/GatewayUIFuncTest.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway; import java.io.IOException; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import com.mycila.xmltool.XMLDoc; import com.mycila.xmltool.XMLTag; @@ -40,9 +40,6 @@ import static org.apache.knox.test.TestUtils.LOG_EXIT; @Category( { VerifyTest.class, MediumTests.class } ) public class GatewayUIFuncTest { - - private static final Charset UTF8 = Charset.forName("UTF-8"); - // Uncomment to cause the test to hang after the gateway instance is setup. // This will allow the gateway instance to be hit directly via some external client. // @Test @@ -172,7 +169,7 @@ public class GatewayUIFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); given() .auth().preemptive().basic( username, password ) .header( "X-XSRF-Header", "test-xsrf-header-value" ) @@ -188,7 +185,7 @@ public class GatewayUIFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); given() .auth().preemptive().basic( username, password ) .header( "X-XSRF-Header", "test-xsrf-header-value" ) @@ -204,7 +201,7 @@ public class GatewayUIFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); given() .auth().preemptive().basic( username, password ) .header( "X-XSRF-Header", "test-xsrf-header-value" ) @@ -220,7 +217,7 @@ public class GatewayUIFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); given() .auth().preemptive().basic( username, password ) .header( "X-XSRF-Header", "test-xsrf-header-value" ) @@ -236,7 +233,7 @@ public class GatewayUIFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); given() .auth().preemptive().basic( username, password ) .header( "X-XSRF-Header", "test-xsrf-header-value" ) @@ -252,7 +249,7 @@ public class GatewayUIFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); given() .auth().preemptive().basic( username, password ) .header( "X-XSRF-Header", "test-xsrf-header-value" ) @@ -268,7 +265,7 @@ public class GatewayUIFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); given() .auth().preemptive().basic( username, password ) .header( "X-XSRF-Header", "test-xsrf-header-value" ) @@ -283,7 +280,7 @@ public class GatewayUIFuncTest { .respond() .status(HttpStatus.SC_OK) .contentType("application/json") - .characterEncoding("utf-8"); + .characterEncoding(StandardCharsets.UTF_8.name()); given() .auth().preemptive().basic( username, password ) .header( "X-XSRF-Header", "test-xsrf-header-value" ) http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java index 8d6c261..1775196 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestNegative.java @@ -33,6 +33,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -60,8 +61,8 @@ public class KnoxCliLdapFuncTestNegative { @BeforeClass public static void setupSuite() throws Exception { LOG_ENTER(); - System.setOut(new PrintStream(outContent, false, "UTF-8")); - System.setErr(new PrintStream(errContent, false, "UTF-8")); + System.setOut(new PrintStream(outContent, false, StandardCharsets.UTF_8.name())); + System.setErr(new PrintStream(errContent, false, StandardCharsets.UTF_8.name())); driver.setupLdap(0); setupGateway(); LOG_EXIT(); @@ -248,10 +249,10 @@ public class KnoxCliLdapFuncTestNegative { "--u", username, "--p", password, "--g" }; cli.run( args1 ); - assertThat(outContent.toString("UTF-8"), containsString("LDAP authentication successful")); - assertThat(outContent.toString("UTF-8"), containsString("Your topology file may be incorrectly configured for group lookup")); - assertThat(outContent.toString("UTF-8"), containsString("Warn: ")); - assertFalse(outContent.toString("UTF-8").contains("analyst")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("LDAP authentication successful")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Your topology file may be incorrectly configured for group lookup")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Warn: ")); + assertFalse(outContent.toString(StandardCharsets.UTF_8.name()).contains("analyst")); outContent.reset(); @@ -269,8 +270,8 @@ public class KnoxCliLdapFuncTestNegative { NoOpAppender.tearDown( before ); } - assertThat(outContent.toString("UTF-8"), containsString("LDAP authentication failed")); - assertThat(outContent.toString("UTF-8"), containsString("INVALID_CREDENTIALS")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("LDAP authentication failed")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("INVALID_CREDENTIALS")); outContent.reset(); username = "sam"; @@ -282,11 +283,11 @@ public class KnoxCliLdapFuncTestNegative { "--u", username, "--p", password, "--g" }; cli.run( args3 ); - assertThat(outContent.toString("UTF-8"), containsString("LDAP authentication successful")); - assertThat(outContent.toString("UTF-8"), containsString("Your topology file may be incorrectly configured for group lookup")); - assertThat(outContent.toString("UTF-8"), containsString("Warn:")); - assertFalse(outContent.toString("UTF-8").contains("analyst")); - assertFalse(outContent.toString("UTF-8").contains("scientist")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("LDAP authentication successful")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Your topology file may be incorrectly configured for group lookup")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Warn:")); + assertFalse(outContent.toString(StandardCharsets.UTF_8.name()).contains("analyst")); + assertFalse(outContent.toString(StandardCharsets.UTF_8.name()).contains("scientist")); LOG_EXIT(); } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java index 1c46d26..e657a52 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliLdapFuncTestPositive.java @@ -33,6 +33,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -60,8 +61,8 @@ public class KnoxCliLdapFuncTestPositive { @BeforeClass public static void setupSuite() throws Exception { LOG_ENTER(); - System.setOut(new PrintStream(outContent, false, "UTF-8")); - System.setErr(new PrintStream(errContent, false, "UTF-8")); + System.setOut(new PrintStream(outContent, false, StandardCharsets.UTF_8.name())); + System.setErr(new PrintStream(errContent, false, StandardCharsets.UTF_8.name())); driver.setupLdap(0); setupGateway(); LOG_EXIT(); @@ -236,9 +237,9 @@ public class KnoxCliLdapFuncTestPositive { KnoxCLI cli = new KnoxCLI(); cli.setConf(config); cli.run(args); - assertThat(outContent.toString("UTF-8"), containsString("success")); - assertThat(outContent.toString("UTF-8"), containsString("analyst")); - assertThat(outContent.toString("UTF-8"), containsString("scientist")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("success")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("analyst")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("scientist")); // Test 2: Give an invalid name and password combinatinon. outContent.reset(); @@ -253,7 +254,7 @@ public class KnoxCliLdapFuncTestPositive { } finally { NoOpAppender.tearDown( before ); } - assertThat(outContent.toString("UTF-8"), containsString("LDAP authentication failed")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("LDAP authentication failed")); // Test 3: Authenticate a user who belongs to no groups, but specify groups with --g outContent.reset(); @@ -264,8 +265,8 @@ public class KnoxCliLdapFuncTestPositive { String[] args3 = {"user-auth-test", "--master", "knox", "--cluster", "test-cluster", "--u", username, "--p", password, "--g" }; cli.run(args3); - assertThat(outContent.toString("UTF-8"), containsString("LDAP authentication success")); - assertThat(outContent.toString("UTF-8"), containsString("does not belong to any groups")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("LDAP authentication success")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("does not belong to any groups")); // Test 4: Pass a non-existent topology outContent.reset(); @@ -276,7 +277,7 @@ public class KnoxCliLdapFuncTestPositive { String[] args4 = {"user-auth-test", "--master", "knox", "--cluster", "cluster-dne", "--u", username, "--p", password }; cli.run(args4); - assertThat(outContent.toString("UTF-8"), containsString("Topology cluster-dne does not exist")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Topology cluster-dne does not exist")); // Test 5: Authenticate a user who belongs to no groups, but specify groups with --g @@ -288,8 +289,8 @@ public class KnoxCliLdapFuncTestPositive { String[] args5 = {"user-auth-test", "--master", "knox", "--cluster", "test-cluster", "--u", username, "--p", password }; cli.run( args5 ); - assertThat(outContent.toString("UTF-8"), containsString("LDAP authentication success")); - assertThat(outContent.toString("UTF-8"), not(containsString("does not belong to any groups"))); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("LDAP authentication success")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), not(containsString("does not belong to any groups"))); LOG_EXIT(); } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java index 0d28a78..107ddbc 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/KnoxCliSysBindTest.java @@ -33,6 +33,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; @@ -59,8 +60,8 @@ public class KnoxCliSysBindTest { @BeforeClass public static void setupSuite() throws Exception { LOG_ENTER(); - System.setOut(new PrintStream(outContent, false, "UTF-8")); - System.setErr(new PrintStream(errContent, false, "UTF-8")); + System.setOut(new PrintStream(outContent, false, StandardCharsets.UTF_8.name())); + System.setErr(new PrintStream(errContent, false, StandardCharsets.UTF_8.name())); driver.setupLdap(0); setupGateway(); LOG_EXIT(); @@ -237,7 +238,7 @@ public class KnoxCliSysBindTest { KnoxCLI cli = new KnoxCLI(); cli.setConf(config); cli.run(args); - assertThat(outContent.toString("UTF-8"), containsString("System LDAP Bind successful")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("System LDAP Bind successful")); // Test 2: Make sure authentication fails outContent.reset(); @@ -245,7 +246,7 @@ public class KnoxCliSysBindTest { cli = new KnoxCLI(); cli.setConf(config); cli.run(args2); - assertThat(outContent.toString("UTF-8"), containsString("System LDAP Bind successful")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("System LDAP Bind successful")); // Test 3: Make sure authentication is successful @@ -259,8 +260,8 @@ public class KnoxCliSysBindTest { } finally { NoOpAppender.tearDown( before ); } - assertThat(outContent.toString("UTF-8"), containsString("LDAP authentication failed")); - assertThat(outContent.toString("UTF-8"), containsString("Unable to successfully bind to LDAP server with topology credentials")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("LDAP authentication failed")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Unable to successfully bind to LDAP server with topology credentials")); // Test 4: Assert that we get a username/password not present error is printed outContent.reset(); @@ -268,8 +269,8 @@ public class KnoxCliSysBindTest { cli = new KnoxCLI(); cli.setConf(config); cli.run(args4); - assertThat(outContent.toString("UTF-8"), containsString("Warn: main.ldapRealm.contextFactory.systemUsername is not present")); - assertThat(outContent.toString("UTF-8"), containsString("Warn: main.ldapRealm.contextFactory.systemPassword is not present")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Warn: main.ldapRealm.contextFactory.systemUsername is not present")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Warn: main.ldapRealm.contextFactory.systemPassword is not present")); // Test 5: Assert that we get a username/password not present error is printed @@ -278,7 +279,7 @@ public class KnoxCliSysBindTest { cli = new KnoxCLI(); cli.setConf(config); cli.run(args5); - assertThat(outContent.toString("UTF-8"), containsString("Topology not-a-cluster does not exist")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Topology not-a-cluster does not exist")); LOG_EXIT(); } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-test/src/test/java/org/apache/knox/gateway/OozieServiceDefinitionTest.java ---------------------------------------------------------------------- diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/OozieServiceDefinitionTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/OozieServiceDefinitionTest.java index 68772c3..07cfa9a 100644 --- a/gateway-test/src/test/java/org/apache/knox/gateway/OozieServiceDefinitionTest.java +++ b/gateway-test/src/test/java/org/apache/knox/gateway/OozieServiceDefinitionTest.java @@ -39,6 +39,7 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import java.io.InputStream; import java.io.Reader; +import java.nio.charset.StandardCharsets; import static org.apache.knox.test.TestUtils.LOG_ENTER; import static org.apache.knox.test.TestUtils.LOG_EXIT; @@ -82,7 +83,7 @@ public class OozieServiceDefinitionTest { UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment( servletContext ); - Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml", "UTF-8" ); + Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml", StandardCharsets.UTF_8 ); UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory .load( "xml", rulesReader ); rulesReader.close(); @@ -136,7 +137,7 @@ public class OozieServiceDefinitionTest { UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment( servletContext ); - Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml", "UTF-8" ); + Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml", StandardCharsets.UTF_8 ); UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load( "xml", rulesReader ); rulesReader.close(); @@ -190,7 +191,7 @@ public class OozieServiceDefinitionTest { UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment( servletContext ); - Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml", "UTF-8" ); + Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml", StandardCharsets.UTF_8 ); UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load( "xml", rulesReader ); rulesReader.close(); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java ---------------------------------------------------------------------- diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java index be5a402..4e2a742 100644 --- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java +++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java @@ -19,6 +19,7 @@ package org.apache.knox.gateway.util; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -30,19 +31,19 @@ public class HttpUtils { public static Map<String, List<String>> splitQuery(String queryString) throws UnsupportedEncodingException { - final Map<String, List<String>> queryPairs = new HashMap<String, List<String>>(); + final Map<String, List<String>> queryPairs = new HashMap<>(); if (queryString == null || queryString.trim().isEmpty()) { return queryPairs; } final String[] pairs = queryString.split("&"); for (String pair : pairs) { - final int idx = pair.indexOf("="); - final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair; + final int idx = pair.indexOf('='); + final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), StandardCharsets.UTF_8.name()) : pair; if (!queryPairs.containsKey(key)) { queryPairs.put(key, new ArrayList<String>()); } final String value = idx > 0 && pair.length() > idx + 1 - ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8") : ""; + ? URLDecoder.decode(pair.substring(idx + 1), StandardCharsets.UTF_8.name()) : ""; queryPairs.get(key).add(value); } return queryPairs; @@ -97,7 +98,7 @@ public class HttpUtils { private static final String urlDecodeUtf8( String s ) { if( s != null ) { try { - s = URLDecoder.decode( s, "UTF-8" ); + s = URLDecoder.decode( s, StandardCharsets.UTF_8.name() ); } catch( UnsupportedEncodingException e ) { // Ignore it. } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-util-common/src/main/java/org/apache/knox/gateway/util/MimeTypes.java ---------------------------------------------------------------------- diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/MimeTypes.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/MimeTypes.java index eeeaf0f..c263c9a 100644 --- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/MimeTypes.java +++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/MimeTypes.java @@ -19,6 +19,7 @@ package org.apache.knox.gateway.util; import javax.activation.MimeType; import javax.activation.MimeTypeParseException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -27,15 +28,13 @@ public class MimeTypes { private static final String CHARSET_PARAMETER_NAME = "charset"; - private static final String UTF8_CHARSET = "UTF-8"; - private static Map<String,String> DEFAULT_CHARSETS; static { DEFAULT_CHARSETS = new HashMap<>(); - DEFAULT_CHARSETS.put( "text/xml", UTF8_CHARSET ); - DEFAULT_CHARSETS.put( "text/json", UTF8_CHARSET ); - DEFAULT_CHARSETS.put( "application/xml", UTF8_CHARSET ); - DEFAULT_CHARSETS.put( "application/json", UTF8_CHARSET ); + DEFAULT_CHARSETS.put( "text/xml", StandardCharsets.UTF_8.name() ); + DEFAULT_CHARSETS.put( "text/json", StandardCharsets.UTF_8.name() ); + DEFAULT_CHARSETS.put( "application/xml", StandardCharsets.UTF_8.name() ); + DEFAULT_CHARSETS.put( "application/json", StandardCharsets.UTF_8.name() ); } public static MimeType create( final String base, final String encoding ) { http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java ---------------------------------------------------------------------- diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java index beb090d..1d066ef 100644 --- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java +++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/Urls.java @@ -20,6 +20,7 @@ package org.apache.knox.gateway.util; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -123,7 +124,7 @@ public class Urls { public static String encode( String str ) { URLCodec codec = new URLCodec(); try { - return codec.encode( str, "UTF-8" ); + return codec.encode( str, StandardCharsets.UTF_8.name() ); } catch( UnsupportedEncodingException e ) { throw new IllegalArgumentException( e ); } @@ -132,7 +133,7 @@ public class Urls { public static String decode( String str ) { URLCodec codec = new URLCodec(); try { - return codec.decode( str, "UTF-8" ); + return codec.decode( str, StandardCharsets.UTF_8.name() ); } catch( UnsupportedEncodingException e ) { throw new IllegalArgumentException( e ); } catch( DecoderException e ) { http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java ---------------------------------------------------------------------- diff --git a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java index 007a0a2..2c26be1 100644 --- a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java +++ b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Launcher.java @@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.Properties; public class Launcher { @@ -108,7 +109,7 @@ public class Launcher { } private static File calcLauncherDir( URL libUrl ) throws UnsupportedEncodingException { - String libPath = URLDecoder.decode(libUrl.getFile(), "UTF-8"); + String libPath = URLDecoder.decode(libUrl.getFile(), StandardCharsets.UTF_8.name()); File libFile = new File( libPath ); File dir; if( libFile.isDirectory() ) { http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java ---------------------------------------------------------------------- diff --git a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java index 45b506b..ad14321 100644 --- a/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java +++ b/gateway-util-urltemplate/src/main/java/org/apache/knox/gateway/util/urltemplate/Expander.java @@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -262,7 +263,7 @@ public class Expander { private static void appendQueryPart(String part, StringBuilder builder) { try { - builder.append(URLEncoder.encode(part, "UTF-8")); + builder.append(URLEncoder.encode(part, StandardCharsets.UTF_8.name())); } catch ( UnsupportedEncodingException e ) { builder.append(part); }
