http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java b/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java index e64adb2..c4b47e7 100644 --- a/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java +++ b/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java @@ -61,8 +61,8 @@ public class KnoxCLITest { @Before public void setup() throws Exception { - 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())); } @Test @@ -100,7 +100,7 @@ public class KnoxCLITest { // Test with no registry clients configured int rc = cli.run(args); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").isEmpty()); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).isEmpty()); // Test with a single client configured // Configure a client for the test local filesystem registry implementation @@ -109,7 +109,7 @@ public class KnoxCLITest { outContent.reset(); rc = cli.run(args); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("test_client")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("test_client")); // Configure another client for the test local filesystem registry implementation config.set("gateway.remote.config.registry.another_client", "type=LocalFileSystem;address=/test2"); @@ -117,8 +117,8 @@ public class KnoxCLITest { outContent.reset(); rc = cli.run(args); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("test_client")); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("another_client")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("test_client")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("another_client")); } @Test @@ -157,7 +157,7 @@ public class KnoxCLITest { // Validate the result assertEquals(0, rc); - String result = outContent.toString("UTF-8"); + String result = outContent.toString(StandardCharsets.UTF_8.name()); assertEquals(result, 3, result.split("\n").length); } finally { FileUtils.forceDelete(testRoot); @@ -198,7 +198,7 @@ public class KnoxCLITest { outContent.reset(); final String[] listArgs = {"list-provider-configs", "--registry-client", "test_client"}; cli.run(listArgs); - String outStr = outContent.toString("UTF-8").trim(); + String outStr = outContent.toString(StandardCharsets.UTF_8.name()).trim(); assertTrue(outStr.startsWith("Provider Configurations")); assertTrue(outStr.endsWith(")\n"+providerConfigName)); @@ -285,7 +285,7 @@ public class KnoxCLITest { outContent.reset(); final String[] listArgs = {"list-descriptors", "--registry-client", "test_client"}; cli.run(listArgs); - String outStr = outContent.toString("UTF-8").trim(); + String outStr = outContent.toString(StandardCharsets.UTF_8.name()).trim(); assertTrue(outStr.startsWith("Descriptors")); assertTrue(outStr.endsWith(")\n"+descriptorName)); @@ -451,7 +451,7 @@ public class KnoxCLITest { cli.setConf(new GatewayConfigImpl()); rc = cli.run(args1); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1 has been successfully " + + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1 has been successfully " + "created.")); outContent.reset(); @@ -459,20 +459,20 @@ public class KnoxCLITest { "master"}; rc = cli.run(args2); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1")); outContent.reset(); String[] args4 = {"delete-alias", "alias1", "--master", "master"}; rc = cli.run(args4); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1 has been successfully " + + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1 has been successfully " + "deleted.")); outContent.reset(); rc = cli.run(args2); assertEquals(0, rc); - assertFalse(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1")); + assertFalse(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1")); } @Test @@ -486,24 +486,24 @@ public class KnoxCLITest { cli.setConf(new GatewayConfigImpl()); rc = cli.run(args1); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains( + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains( "alias1 has been successfully " + "created.")); outContent.reset(); String[] args2 = { "list-alias", "--cluster", "Invalidcluster1", "--master", "master" }; rc = cli.run(args2); assertEquals(0, rc); - System.out.println(outContent.toString("UTF-8")); - assertTrue(outContent.toString("UTF-8"), - outContent.toString("UTF-8").contains("Invalid cluster name provided: Invalidcluster1")); + System.out.println(outContent.toString(StandardCharsets.UTF_8.name())); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), + outContent.toString(StandardCharsets.UTF_8.name()).contains("Invalid cluster name provided: Invalidcluster1")); outContent.reset(); String[] args4 = { "delete-alias", "alias1", "--cluster", "Invalidcluster1", "--master", "master" }; rc = cli.run(args4); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), - outContent.toString("UTF-8").contains("Invalid cluster name provided: Invalidcluster1")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), + outContent.toString(StandardCharsets.UTF_8.name()).contains("Invalid cluster name provided: Invalidcluster1")); } @@ -524,7 +524,7 @@ public class KnoxCLITest { String[] args2 = { "delete-alias", "alias2", "--cluster", "cluster1", "--master", "master" }; rc = cli.run(args2); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8").contains("No such alias exists in the cluster.")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()).contains("No such alias exists in the cluster.")); } finally { outContent.reset(); String[] args1 = { "delete-alias", "alias1", "--cluster", "cluster1", "--master", "master" }; @@ -547,7 +547,7 @@ public class KnoxCLITest { String[] args2 = { "delete-alias", "alias2", "--master", "master" }; rc = cli.run(args2); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8").contains("No such alias exists in the cluster.")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()).contains("No such alias exists in the cluster.")); } finally { outContent.reset(); String[] args1 = { "delete-alias", "alias1", "--master", "master" }; @@ -563,7 +563,7 @@ public class KnoxCLITest { cli.setConf(new GatewayConfigImpl()); int rc = cli.run(args1); assertEquals(-2, rc); - assertTrue(outContent.toString("UTF-8").contains("ERROR: Invalid Command")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()).contains("ERROR: Invalid Command")); } @Test @@ -577,28 +577,28 @@ public class KnoxCLITest { cli.setConf(new GatewayConfigImpl()); rc = cli.run(args1); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains( + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains( "alias1 has been successfully " + "created.")); outContent.reset(); String[] args2 = { "list-alias", "--cluster", "cluster1", "--master", "master" }; rc = cli.run(args2); assertEquals(0, rc); - System.out.println(outContent.toString("UTF-8")); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1")); + System.out.println(outContent.toString(StandardCharsets.UTF_8.name())); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1")); outContent.reset(); String[] args4 = { "delete-alias", "alias1", "--cluster", "cluster1", "--master", "master" }; rc = cli.run(args4); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains( + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains( "alias1 has been successfully " + "deleted.")); outContent.reset(); rc = cli.run(args2); assertEquals(0, rc); - assertFalse(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1")); + assertFalse(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1")); } @@ -614,7 +614,7 @@ public class KnoxCLITest { cli.setConf( config ); rc = cli.run(gwCreateArgs); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1 has been successfully " + + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1 has been successfully " + "created.")); AliasService as = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE); @@ -626,7 +626,7 @@ public class KnoxCLITest { cli.setConf( config ); rc = cli.run(clusterCreateArgs); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias2 has been successfully " + + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias2 has been successfully " + "created.")); outContent.reset(); @@ -634,8 +634,8 @@ public class KnoxCLITest { cli = new KnoxCLI(); rc = cli.run(args2); assertEquals(0, rc); - assertFalse(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias2")); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1")); + assertFalse(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias2")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1")); char[] passwordChars = as.getPasswordFromAliasForCluster("test", "alias2"); assertNotNull(passwordChars); @@ -646,15 +646,15 @@ public class KnoxCLITest { cli = new KnoxCLI(); rc = cli.run(args1); assertEquals(0, rc); - assertFalse(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1")); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias2")); + assertFalse(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias2")); outContent.reset(); String[] args4 = {"delete-alias", "alias1", "--master", "master"}; cli = new KnoxCLI(); rc = cli.run(args4); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias1 has been successfully " + + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias1 has been successfully " + "deleted.")); outContent.reset(); @@ -662,7 +662,7 @@ public class KnoxCLITest { cli = new KnoxCLI(); rc = cli.run(args5); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("alias2 has been successfully " + + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("alias2 has been successfully " + "deleted.")); } @@ -675,7 +675,7 @@ public class KnoxCLITest { MasterService ms = cli.getGatewayServices().getService("MasterService"); String master = String.copyValueOf( ms.getMasterSecret() ); assertThat( master, is( "master" ) ); - assertThat( outContent.toString("UTF-8"), containsString( "Master secret has been persisted to disk." ) ); + assertThat( outContent.toString(StandardCharsets.UTF_8.name()), containsString( "Master secret has been persisted to disk." ) ); } @Test @@ -690,7 +690,7 @@ public class KnoxCLITest { int rc = 0; rc = cli.run(gwCreateArgs); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("gateway-identity has been successfully " + + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("gateway-identity has been successfully " + "created.")); } @@ -706,7 +706,7 @@ public class KnoxCLITest { int rc = 0; rc = cli.run(gwCreateArgs); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("gateway-identity has been successfully " + + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("gateway-identity has been successfully " + "created.")); outContent.reset(); @@ -714,31 +714,31 @@ public class KnoxCLITest { rc = 0; rc = cli.run(gwCreateArgs2); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("Certificate gateway-identity has been successfully exported to")); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("gateway-identity.pem")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("Certificate gateway-identity has been successfully exported to")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("gateway-identity.pem")); outContent.reset(); String[] gwCreateArgs2_5 = {"export-cert"}; rc = 0; rc = cli.run(gwCreateArgs2_5); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("Certificate gateway-identity has been successfully exported to")); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("gateway-identity.pem")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("Certificate gateway-identity has been successfully exported to")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("gateway-identity.pem")); outContent.reset(); String[] gwCreateArgs3 = {"export-cert", "--type", "JKS"}; rc = 0; rc = cli.run(gwCreateArgs3); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("Certificate gateway-identity has been successfully exported to")); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("gateway-client-trust.jks")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("Certificate gateway-identity has been successfully exported to")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("gateway-client-trust.jks")); outContent.reset(); String[] gwCreateArgs4 = {"export-cert", "--type", "invalid"}; rc = 0; rc = cli.run(gwCreateArgs4); assertEquals(0, rc); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("Invalid type for export file provided.")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("Invalid type for export file provided.")); } @Test @@ -755,7 +755,7 @@ public class KnoxCLITest { MasterService ms = cli.getGatewayServices().getService("MasterService"); // assertTrue(ms.getClass().getName(), ms.getClass().getName().equals("kjdfhgjkhfdgjkh")); assertTrue( new String( ms.getMasterSecret() ), "master".equals( new String( ms.getMasterSecret() ) ) ); - assertTrue(outContent.toString("UTF-8"), outContent.toString("UTF-8").contains("Master secret has been persisted to disk.")); + assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("Master secret has been persisted to disk.")); } @Test @@ -782,7 +782,7 @@ public class KnoxCLITest { assertThat( master.indexOf( '-', 14 ), is( 18 ) ); assertThat( master.indexOf( '-', 19 ), is( 23 ) ); assertThat( UUID.fromString( master ), notNullValue() ); - assertThat( outContent.toString("UTF-8"), containsString( "Master secret has been persisted to disk." ) ); + assertThat( outContent.toString(StandardCharsets.UTF_8.name()), containsString( "Master secret has been persisted to disk." ) ); // Need to delete the master file so that the change isn't ignored. if( masterFile.exists() ) { @@ -797,7 +797,7 @@ public class KnoxCLITest { assertThat( UUID.fromString( master2 ), notNullValue() ); assertThat( master2, not( is( master ) ) ); assertThat( rc, is( 0 ) ); - assertThat(outContent.toString("UTF-8"), containsString("Master secret has been persisted to disk.")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Master secret has been persisted to disk.")); } @Test @@ -823,12 +823,12 @@ public class KnoxCLITest { ms = cli.getGatewayServices().getService("MasterService"); String master = String.copyValueOf( ms.getMasterSecret() ); assertThat( master, is( "test-master-1" ) ); - assertThat( outContent.toString("UTF-8"), containsString( "Master secret has been persisted to disk." ) ); + assertThat( outContent.toString(StandardCharsets.UTF_8.name()), containsString( "Master secret has been persisted to disk." ) ); outContent.reset(); rc = cli.run(args); assertThat( rc, is(0 ) ); - assertThat( outContent.toString("UTF-8"), containsString( "Master secret is already present on disk." ) ); + assertThat( outContent.toString(StandardCharsets.UTF_8.name()), containsString( "Master secret is already present on disk." ) ); outContent.reset(); args = new String[]{ "create-master", "--master", "test-master-2", "--force" }; @@ -837,7 +837,7 @@ public class KnoxCLITest { ms = cli.getGatewayServices().getService("MasterService"); master = String.copyValueOf( ms.getMasterSecret() ); assertThat( master, is( "test-master-2" ) ); - assertThat( outContent.toString("UTF-8"), containsString( "Master secret has been persisted to disk." ) ); + assertThat( outContent.toString(StandardCharsets.UTF_8.name()), containsString( "Master secret has been persisted to disk." ) ); } @Test @@ -852,8 +852,8 @@ public class KnoxCLITest { cli.setConf( config ); cli.run( args ); - assertThat(outContent.toString("UTF-8"), containsString("sandbox")); - assertThat(outContent.toString("UTF-8"), containsString("admin")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("sandbox")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("admin")); } private class GatewayConfigMock extends GatewayConfigImpl{ @@ -968,30 +968,30 @@ public class KnoxCLITest { cli.setConf( config ); cli.run( args ); - assertThat(outContent.toString("UTF-8"), containsString(config.getGatewayTopologyDir())); - assertThat(outContent.toString("UTF-8"), containsString("sandbox")); - assertThat(outContent.toString("UTF-8"), containsString("success")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString(config.getGatewayTopologyDir())); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("sandbox")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("success")); outContent.reset(); String[] args2 = {"validate-topology", "--master", "knox", "--cluster", "NotATopology"}; cli.run(args2); - assertThat(outContent.toString("UTF-8"), containsString("NotATopology")); - assertThat(outContent.toString("UTF-8"), containsString("does not exist")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("NotATopology")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("does not exist")); outContent.reset(); String[] args3 = {"validate-topology", "--master", "knox", "--path", config.getGatewayTopologyDir() + "/admin.xml"}; cli.run(args3); - assertThat(outContent.toString("UTF-8"), containsString("admin")); - assertThat(outContent.toString("UTF-8"), containsString("success")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("admin")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("success")); outContent.reset(); String[] args4 = {"validate-topology", "--master", "knox", "--path", "not/a/path"}; cli.run(args4); - assertThat(outContent.toString("UTF-8"), containsString("does not exist")); - assertThat(outContent.toString("UTF-8"), containsString("not/a/path")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("does not exist")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("not/a/path")); } @Test @@ -1009,11 +1009,11 @@ public class KnoxCLITest { cli.setConf( config ); cli.run( args ); - assertThat(outContent.toString("UTF-8"), containsString(config.getGatewayTopologyDir())); - assertThat(outContent.toString("UTF-8"), containsString("test-cluster-bad")); - assertThat(outContent.toString("UTF-8"), containsString("unsuccessful")); - assertThat(outContent.toString("UTF-8"), containsString("Invalid content")); - assertThat(outContent.toString("UTF-8"), containsString("Line")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString(config.getGatewayTopologyDir())); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("test-cluster-bad")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("unsuccessful")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Invalid content")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("Line")); outContent.reset(); @@ -1022,9 +1022,9 @@ public class KnoxCLITest { cli.run(args2); - assertThat(outContent.toString("UTF-8"), containsString(config.getGatewayTopologyDir())); - assertThat(outContent.toString("UTF-8"), containsString("success")); - assertThat(outContent.toString("UTF-8"), containsString("test-cluster-good")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString(config.getGatewayTopologyDir())); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("success")); + assertThat(outContent.toString(StandardCharsets.UTF_8.name()), containsString("test-cluster-good")); }
http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java ---------------------------------------------------------------------- diff --git a/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java b/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java index 328adaf..0d67788 100644 --- a/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java +++ b/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java @@ -51,6 +51,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; @@ -161,7 +162,7 @@ public class TopologiesResource { Topology result = null; try { - id = URLDecoder.decode(id, "UTF-8"); + id = URLDecoder.decode(id, StandardCharsets.UTF_8.name()); } catch (Exception e) { // Ignore } @@ -328,7 +329,7 @@ public class TopologiesResource { Response response = null; try { - name = URLDecoder.decode(name, "UTF-8"); + name = URLDecoder.decode(name, StandardCharsets.UTF_8.name()); } catch (Exception e) { // Ignore } @@ -375,7 +376,7 @@ public class TopologiesResource { Response response = null; try { - name = URLDecoder.decode(name, "UTF-8"); + name = URLDecoder.decode(name, StandardCharsets.UTF_8.name()); } catch (Exception e) { // Ignore } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-service-hbase/src/main/java/org/apache/knox/gateway/hbase/HBaseDispatch.java ---------------------------------------------------------------------- diff --git a/gateway-service-hbase/src/main/java/org/apache/knox/gateway/hbase/HBaseDispatch.java b/gateway-service-hbase/src/main/java/org/apache/knox/gateway/hbase/HBaseDispatch.java index 419a17d..833dea1 100644 --- a/gateway-service-hbase/src/main/java/org/apache/knox/gateway/hbase/HBaseDispatch.java +++ b/gateway-service-hbase/src/main/java/org/apache/knox/gateway/hbase/HBaseDispatch.java @@ -20,6 +20,7 @@ package org.apache.knox.gateway.hbase; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import javax.servlet.http.HttpServletRequest; import org.apache.knox.gateway.dispatch.DefaultDispatch; @@ -34,9 +35,9 @@ public class HBaseDispatch extends DefaultDispatch { // KNOX-709: HBase can't handle URL encoded paths. public URI getDispatchUrl( HttpServletRequest request) { String base = request.getRequestURI(); - StringBuffer str = new StringBuffer(); + StringBuilder str = new StringBuilder(); try { - str.append( URLDecoder.decode( base, "UTF-8" ) ); + str.append( URLDecoder.decode( base, StandardCharsets.UTF_8.name() ) ); } catch( UnsupportedEncodingException e ) { str.append( base ); } String query = request.getQueryString(); @@ -44,8 +45,7 @@ public class HBaseDispatch extends DefaultDispatch { str.append( '?' ); str.append( query ); } - URI uri = URI.create( str.toString() ); - return uri; + return URI.create( str.toString() ); } } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-service-knoxsso/src/main/java/org/apache/knox/gateway/service/knoxsso/WebSSOResource.java ---------------------------------------------------------------------- diff --git a/gateway-service-knoxsso/src/main/java/org/apache/knox/gateway/service/knoxsso/WebSSOResource.java b/gateway-service-knoxsso/src/main/java/org/apache/knox/gateway/service/knoxsso/WebSSOResource.java index 6a96f59..8f8002d 100644 --- a/gateway-service-knoxsso/src/main/java/org/apache/knox/gateway/service/knoxsso/WebSSOResource.java +++ b/gateway-service-knoxsso/src/main/java/org/apache/knox/gateway/service/knoxsso/WebSSOResource.java @@ -22,6 +22,7 @@ import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; @@ -202,7 +203,7 @@ public class WebSSOResource { if (whitelist != null) { String decodedOriginal = null; try { - decodedOriginal = URLDecoder.decode(original, "UTF-8"); + decodedOriginal = URLDecoder.decode(original, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { // } @@ -218,7 +219,7 @@ public class WebSSOResource { } JWTokenAuthority ts = services.getService(GatewayServices.TOKEN_SERVICE); - Principal p = ((HttpServletRequest)request).getUserPrincipal(); + Principal p = request.getUserPrincipal(); try { JWT token = null; http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java ---------------------------------------------------------------------- diff --git a/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java b/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java index 48d69d4..d719404 100644 --- a/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java +++ b/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; @@ -597,8 +598,8 @@ public class WebSSOResourceTest { EasyMock.expect(context.getInitParameter("knoxsso.enable.session")).andReturn(null); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); - EasyMock.expect(request.getParameter("originalUrl")).andReturn(URLEncoder.encode("http://disallowedhost:9080/service", - "UTF-8")); + EasyMock.expect(request.getParameter("originalUrl")).andReturn( + URLEncoder.encode("http://disallowedhost:9080/service", StandardCharsets.UTF_8.name())); EasyMock.expect(request.getAttribute("targetServiceRole")).andReturn("KNOXSSO").anyTimes(); EasyMock.expect(request.getParameterMap()).andReturn(Collections.<String,String[]>emptyMap()); EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes(); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java ---------------------------------------------------------------------- diff --git a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java index da10e93..5662e64 100644 --- a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java +++ b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java @@ -44,6 +44,7 @@ import org.apache.zookeeper.data.Id; import org.apache.zookeeper.data.Stat; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -150,8 +151,6 @@ class CuratorClientService implements ZooKeeperClientService { private static final class ClientAdapter implements RemoteConfigurationRegistryClient { - private static final String DEFAULT_ENCODING = "UTF-8"; - private CuratorFramework delegate; private RemoteConfigurationRegistryConfig config; @@ -261,7 +260,7 @@ class CuratorClientService implements ZooKeeperClientService { @Override public String getEntryData(String path) { - return getEntryData(path, DEFAULT_ENCODING); + return getEntryData(path, StandardCharsets.UTF_8.name()); } @Override @@ -291,7 +290,7 @@ class CuratorClientService implements ZooKeeperClientService { @Override public void createEntry(String path, String data) { - createEntry(path, data, DEFAULT_ENCODING); + createEntry(path, data, StandardCharsets.UTF_8.name()); } @Override @@ -306,7 +305,7 @@ class CuratorClientService implements ZooKeeperClientService { @Override public int setEntryData(String path, String data) { - return setEntryData(path, data, DEFAULT_ENCODING); + return setEntryData(path, data, StandardCharsets.UTF_8.name()); } @Override http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractCredentialCollector.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractCredentialCollector.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractCredentialCollector.java index 3dacd98..9146c12 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractCredentialCollector.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/AbstractCredentialCollector.java @@ -17,7 +17,7 @@ */ package org.apache.knox.gateway.shell; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; public abstract class AbstractCredentialCollector implements CredentialCollector { @@ -48,12 +48,7 @@ public abstract class AbstractCredentialCollector implements CredentialCollector @Override public byte[] bytes() { - try { - return value.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - System.out.println("Unsupported encoding."); - } - return null; + return value.getBytes(StandardCharsets.UTF_8); } @Override http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java index 507edc4..9f44412 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSh.java @@ -190,15 +190,14 @@ public class KnoxSh { File tokenfile = new File(System.getProperty("user.home"), ".knoxtokencache"); try( FileOutputStream fos = new FileOutputStream(tokenfile) ) { - fos.write(text.getBytes("UTF-8")); + fos.write(text.getBytes(StandardCharsets.UTF_8)); Set<PosixFilePermission> perms = new HashSet<>(); //add owners permission only perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); Files.setPosixFilePermissions(Paths.get(System.getProperty("user.home") + "/.knoxtokencache"), perms); } - } - catch(HadoopException he) { + } catch(HadoopException he) { System.out.println("Failure to acquire token. Please verify your credentials and Knox URL and try again."); } if ( session != null ) { http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java index 8d00b10..8be5bd6 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/CreateTable.java @@ -31,6 +31,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -99,7 +100,7 @@ public class CreateTable { URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/schema" ); HttpPut request = new HttpPut( uri.build() ); - HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", "UTF-8" ) ); + HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", StandardCharsets.UTF_8 ) ); request.setEntity( entity ); return new Response( execute( request ) ); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java index 49a6c1d..8e8c948 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/TruncateTable.java @@ -31,6 +31,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.util.concurrent.Callable; public class TruncateTable { @@ -63,7 +64,7 @@ public class TruncateTable { } HttpPut put = new HttpPut(uri); - HttpEntity entity = new StringEntity(schema, ContentType.create("text/xml", "UTF-8")); + HttpEntity entity = new StringEntity(schema, ContentType.create("text/xml", StandardCharsets.UTF_8)); put.setEntity(entity); return new TruncateTable.Response(execute(put)); } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java index 7271d73..1498b02 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/UpdateTable.java @@ -31,6 +31,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -89,7 +90,7 @@ public class UpdateTable { URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/schema" ); HttpPost request = new HttpPost( uri.build() ); - HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", "UTF-8" ) ); + HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", StandardCharsets.UTF_8 ) ); request.setEntity( entity ); return new Response( execute( request ) ); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/InsertableColumn.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/InsertableColumn.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/InsertableColumn.java index 44702c3..c8674ca 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/InsertableColumn.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/InsertableColumn.java @@ -18,7 +18,7 @@ package org.apache.knox.gateway.shell.hbase.table.row; import org.apache.commons.codec.binary.Base64; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; public class InsertableColumn extends Column { @@ -39,12 +39,12 @@ public class InsertableColumn extends Column { return time; } - public String encodedName() throws UnsupportedEncodingException { - return Base64.encodeBase64String( toURIPart().getBytes( "UTF-8" ) ); + public String encodedName() { + return Base64.encodeBase64String( toURIPart().getBytes( StandardCharsets.UTF_8 ) ); } - public String encodedValue() throws UnsupportedEncodingException { + public String encodedValue() { String stringValue = value.toString(); - return Base64.encodeBase64String( stringValue.getBytes( "UTF-8" ) ); + return Base64.encodeBase64String( stringValue.getBytes( StandardCharsets.UTF_8 ) ); } } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java index 1c30485..caa222c 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/row/StoreRow.java @@ -32,6 +32,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -79,7 +80,7 @@ public class StoreRow { document.appendChild( root ); Element row = document.createElement( ELEMENT_ROW ); - row.setAttribute( ATTRIBUTE_KEY, Base64.encodeBase64String( rowId.getBytes( "UTF-8" ) ) ); + row.setAttribute( ATTRIBUTE_KEY, Base64.encodeBase64String( rowId.getBytes( StandardCharsets.UTF_8 ) ) ); root.appendChild( row ); for( InsertableColumn column : columns ) { @@ -98,7 +99,7 @@ public class StoreRow { URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/false-row-key" ); HttpPost request = new HttpPost( uri.build() ); - HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", "UTF-8" ) ); + HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", StandardCharsets.UTF_8 ) ); request.setEntity( entity ); return new Response( execute( request ) ); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java index a183f3d..acb424d 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/hbase/table/scanner/CreateScanner.java @@ -34,6 +34,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -134,10 +135,10 @@ public class CreateScanner { Element root = document.createElement( ELEMENT_SCANNER ); if( startRow != null ) { - root.setAttribute( ATTRIBUTE_START_ROW, Base64.encodeBase64String( startRow.getBytes( "UTF-8" ) ) ); + root.setAttribute( ATTRIBUTE_START_ROW, Base64.encodeBase64String( startRow.getBytes( StandardCharsets.UTF_8 ) ) ); } if( endRow != null ) { - root.setAttribute( ATTRIBUTE_END_ROW, Base64.encodeBase64String( endRow.getBytes( "UTF-8" ) ) ); + root.setAttribute( ATTRIBUTE_END_ROW, Base64.encodeBase64String( endRow.getBytes( StandardCharsets.UTF_8 ) ) ); } if( batch != null ) { root.setAttribute( ATTRIBUTE_BATCH, batch.toString() ); @@ -155,7 +156,7 @@ public class CreateScanner { for( Column column : columns ) { Element columnElement = document.createElement( ELEMENT_COLUMN ); - columnElement.setTextContent( Base64.encodeBase64String( column.toURIPart().getBytes( "UTF-8" ) ) ); + columnElement.setTextContent( Base64.encodeBase64String( column.toURIPart().getBytes( StandardCharsets.UTF_8 ) ) ); root.appendChild( columnElement ); } @@ -171,7 +172,7 @@ public class CreateScanner { URIBuilder uri = uri( HBase.SERVICE_PATH, "/", tableName, "/scanner" ); HttpPut request = new HttpPut( uri.build() ); - HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", "UTF-8" ) ); + HttpEntity entity = new StringEntity( writer.toString(), ContentType.create( "text/xml", StandardCharsets.UTF_8 ) ); request.setEntity( entity ); return new Response( execute( request ) ); http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-shell/src/main/java/org/apache/knox/gateway/shell/workflow/Submit.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/workflow/Submit.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/workflow/Submit.java index d719e87..f7c920b 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/workflow/Submit.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/workflow/Submit.java @@ -31,6 +31,7 @@ import org.apache.http.entity.StringEntity; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.concurrent.Callable; class Submit { @@ -69,7 +70,7 @@ class Submit { HttpPost request = new HttpPost( uri.build() ); HttpEntity entity = null; if( text != null ) { - entity = new StringEntity( text, ContentType.create( "application/xml", "UTF-8" ) ); + entity = new StringEntity( text, ContentType.create( "application/xml", StandardCharsets.UTF_8 ) ); } else if( file != null ) { entity = new FileEntity( new File( file ), ContentType.create( "application/xml" ) ); } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java index d8de89b..216ff6e 100644 --- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java +++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java @@ -35,6 +35,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.HashMap; import java.util.Locale; @@ -145,7 +146,7 @@ public class GatewayDispatchFilter extends AbstractGatewayFilter { String decodedURL = null; try { - decodedURL = URLDecoder.decode(requestURI, "UTF-8"); + decodedURL = URLDecoder.decode(requestURI, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { // } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java index 046c69b..928857c 100644 --- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java +++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatch.java @@ -20,6 +20,7 @@ package org.apache.knox.gateway.dispatch; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import javax.servlet.http.HttpServletRequest; @@ -36,7 +37,7 @@ public class PassAllHeadersNoEncodingDispatch extends PassAllHeadersDispatch { String query = request.getQueryString(); if (query != null) { try { - query = URLDecoder.decode(query, "UTF-8"); + query = URLDecoder.decode(query, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { // log } @@ -44,7 +45,6 @@ public class PassAllHeadersNoEncodingDispatch extends PassAllHeadersDispatch { str.append( query ); } encodeUnwiseCharacters(str); - URI uri = URI.create( str.toString() ); - return uri; + return URI.create( str.toString() ); } } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java index a3d5c97..7e71776 100644 --- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java +++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/URLDecodingDispatch.java @@ -20,6 +20,7 @@ package org.apache.knox.gateway.dispatch; import javax.servlet.http.HttpServletRequest; import java.net.URI; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; /** * Dispatch which decodes the outgoing URLs (to services). @@ -39,19 +40,18 @@ public class URLDecodingDispatch extends DefaultDispatch { String decoded; try { - decoded = URLDecoder.decode(request.getRequestURL().toString(), "UTF-8" ); + decoded = URLDecoder.decode(request.getRequestURL().toString(), StandardCharsets.UTF_8.name() ); } catch (final Exception e) { /* fall back in case of exception */ decoded = request.getRequestURL().toString(); } - final StringBuffer str = new StringBuffer(decoded); + final StringBuilder str = new StringBuilder(decoded); final String query = request.getQueryString(); if ( query != null ) { str.append('?'); str.append(query); } - final URI url = URI.create(str.toString()); - return url; + return URI.create(str.toString()); } } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java index 1b4f0f2..67b034f 100644 --- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java +++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java @@ -212,11 +212,11 @@ public class BaseKeystoreService { protected void writeCertificateToFile( Certificate cert, final File file ) throws CertificateEncodingException, IOException { byte[] bytes = cert.getEncoded(); - Base64 encoder = new Base64( 76, "\n".getBytes( "ASCII" ) ); + Base64 encoder = new Base64( 76, "\n".getBytes( StandardCharsets.US_ASCII ) ); try( final FileOutputStream out = new FileOutputStream( file ) ) { - out.write( "-----BEGIN CERTIFICATE-----\n".getBytes( "ASCII" ) ); - out.write( encoder.encodeToString( bytes ).getBytes( "ASCII" ) ); - out.write( "-----END CERTIFICATE-----\n".getBytes( "ASCII" ) ); + out.write( "-----BEGIN CERTIFICATE-----\n".getBytes( StandardCharsets.US_ASCII ) ); + out.write( encoder.encodeToString( bytes ).getBytes( StandardCharsets.US_ASCII ) ); + out.write( "-----END CERTIFICATE-----\n".getBytes( StandardCharsets.US_ASCII ) ); } } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/ConfigurableEncryptor.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/ConfigurableEncryptor.java b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/ConfigurableEncryptor.java index 9e6b7a9..e29b1e5 100644 --- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/ConfigurableEncryptor.java +++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/ConfigurableEncryptor.java @@ -17,6 +17,7 @@ */ package org.apache.knox.gateway.services.security.impl; +import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; @@ -98,9 +99,8 @@ public class ConfigurableEncryptor { } public EncryptionResult encrypt(String encrypt) throws Exception { - byte[] bytes = encrypt.getBytes("UTF-8"); - EncryptionResult atom = encrypt(bytes); - return atom; + byte[] bytes = encrypt.getBytes(StandardCharsets.UTF_8); + return encrypt(bytes); } public EncryptionResult encrypt(byte[] plain) throws Exception { http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/X509CertificateUtil.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/X509CertificateUtil.java b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/X509CertificateUtil.java index 095d592..20e98ee 100644 --- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/X509CertificateUtil.java +++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/X509CertificateUtil.java @@ -25,6 +25,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigInteger; +import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.KeyPair; import java.security.KeyStore; @@ -269,18 +270,17 @@ public class X509CertificateUtil { throws Exception { Field privateStringField = obj.getClass().getDeclaredField(setString); privateStringField.setAccessible(true); - String fieldValue = (String) privateStringField.get(obj); - return fieldValue; + return (String) privateStringField.get(obj); } public static void writeCertificateToFile(Certificate cert, final File file) throws CertificateEncodingException, IOException { byte[] bytes = cert.getEncoded(); - Base64 encoder = new Base64( 76, "\n".getBytes( "ASCII" ) ); + Base64 encoder = new Base64( 76, "\n".getBytes( StandardCharsets.US_ASCII ) ); try( final FileOutputStream out = new FileOutputStream( file ) ) { - out.write( "-----BEGIN CERTIFICATE-----\n".getBytes( "ASCII" ) ); - out.write( encoder.encodeToString( bytes ).getBytes( "ASCII" ) ); - out.write( "-----END CERTIFICATE-----\n".getBytes( "ASCII" ) ); + out.write( "-----BEGIN CERTIFICATE-----\n".getBytes( StandardCharsets.US_ASCII ) ); + out.write( encoder.encodeToString( bytes ).getBytes( StandardCharsets.US_ASCII ) ); + out.write( "-----END CERTIFICATE-----\n".getBytes( StandardCharsets.US_ASCII ) ); } } @@ -291,12 +291,9 @@ public class X509CertificateUtil { char[] password = "changeit".toCharArray(); ks.load(null, password); ks.setCertificateEntry("gateway-identity", cert); - FileOutputStream fos = new FileOutputStream(file); /* Coverity Scan CID 1361992 */ - try { + try (FileOutputStream fos = new FileOutputStream(file)) { ks.store(fos, password); - } finally { - fos.close(); } } } http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/CappedBufferHttpEntityTest.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/CappedBufferHttpEntityTest.java b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/CappedBufferHttpEntityTest.java index 14c22a1..702b73a 100644 --- a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/CappedBufferHttpEntityTest.java +++ b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/CappedBufferHttpEntityTest.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; @@ -35,9 +36,6 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.fail; public class CappedBufferHttpEntityTest { - - private static Charset UTF8 = Charset.forName( "UTF-8" ); - // Variables // Consumers: C1, C2 // Reads: FC - Full Content, PC - Partial Content, AC - Any Content @@ -71,7 +69,7 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 20 ); String output; @@ -87,12 +85,12 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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 +101,7 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); String output; @@ -123,13 +121,13 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); String output; try { - output = blockRead( replay.getContent(), UTF8, -1, 3 ); + output = blockRead( replay.getContent(), StandardCharsets.UTF_8, -1, 3 ); fail("expected IOException"); } catch (IOException e) { // expected @@ -143,7 +141,7 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 20 ); String output; @@ -162,15 +160,15 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( "UTF-8" ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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 ) ); } @@ -181,7 +179,7 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); String output; @@ -202,12 +200,12 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); String output; try { - output = blockRead( replay.getContent(), UTF8, -1, 3 ); + output = blockRead( replay.getContent(), StandardCharsets.UTF_8, -1, 3 ); fail( "Expected IOException" ); } catch( IOException e ) { // Expected. @@ -224,7 +222,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 20 ); stream = replay.getContent(); text = byteRead( stream, -1 ); @@ -246,16 +244,16 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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" ) ); } @@ -269,7 +267,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); stream = replay.getContent(); @@ -291,12 +289,12 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); stream = replay.getContent(); try { - text = blockRead( stream, UTF8, -1, 3 ); + text = blockRead( stream, StandardCharsets.UTF_8, -1, 3 ); fail( "Expected IOException" ); } catch( IOException e ) { // Expected. @@ -313,7 +311,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 20 ); stream = replay.getContent(); @@ -331,11 +329,11 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 20 ); stream = replay.getContent(); - text = blockRead( stream, UTF8, 3, 3 ); + text = blockRead( stream, StandardCharsets.UTF_8, 3, 3 ); assertThat( text, is( "012" ) ); } @@ -351,7 +349,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); + basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8))); replay = new CappedBufferHttpEntity(basic, 5); stream = replay.getContent(); text = byteRead(stream, -1); @@ -373,12 +371,12 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); stream = replay.getContent(); try { - text = blockRead( stream, UTF8, -1, 4 ); + text = blockRead( stream, StandardCharsets.UTF_8, -1, 4 ); fail( "Expected IOException" ); } catch (IOException e) { // expected @@ -395,7 +393,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 20 ); stream = replay.getContent(); @@ -418,16 +416,16 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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" ) ); } @@ -442,7 +440,7 @@ public class CappedBufferHttpEntityTest { try { basic = new BasicHttpEntity(); - basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); + basic.setContent(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8))); replay = new CappedBufferHttpEntity(basic, 5); stream = replay.getContent(); @@ -465,12 +463,12 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); stream = replay.getContent(); try { - text = blockRead( stream, UTF8, 7, 2 ); + text = blockRead( stream, StandardCharsets.UTF_8, 7, 2 ); fail("Expected IOExceptin"); } catch (IOException e) { // expected @@ -487,7 +485,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 20 ); stream = replay.getContent(); @@ -510,16 +508,16 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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" ) ); } @@ -533,7 +531,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); try { @@ -553,12 +551,12 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); stream = replay.getContent(); try { - text = blockRead( stream, UTF8, 7, 2 ); + text = blockRead( stream, StandardCharsets.UTF_8, 7, 2 ); fail( "Expected IOException" ); } catch ( IOException e ) { // Expected. @@ -575,7 +573,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 20 ); stream1 = replay.getContent(); @@ -600,17 +598,17 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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" ) ); } @@ -624,7 +622,7 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); stream1 = replay.getContent(); @@ -646,16 +644,16 @@ public class CappedBufferHttpEntityTest { String text; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( data.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( data.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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(); try { - text = blockRead( stream2, UTF8, 6, 4 ); + text = blockRead( stream2, StandardCharsets.UTF_8, 6, 4 ); fail("expected IOException"); } catch (IOException e) { // expected @@ -670,7 +668,7 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); @@ -689,12 +687,12 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( text.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( text.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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 CappedBufferHttpEntity( buffered ); assertThat( replay.isRepeatable(), is( true ) ); @@ -707,12 +705,12 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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 CappedBufferHttpEntity( basic, 5 ); assertThat( replay.isChunked(), is( true ) ); @@ -725,12 +723,12 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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 CappedBufferHttpEntity( basic, 5 ); assertThat( replay.getContentLength(), is( 10L ) ); @@ -743,12 +741,12 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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 CappedBufferHttpEntity( basic, 5 ); assertThat( replay.getContentType().getValue(), is( "application/json" ) ); @@ -761,15 +759,15 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( 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 CappedBufferHttpEntity( basic, 5 ); - assertThat( replay.getContentEncoding().getValue(), is( "UTF-8" ) ); + assertThat( replay.getContentEncoding().getValue(), is( StandardCharsets.UTF_8.name() ) ); } @Test @@ -780,7 +778,7 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); assertThat( replay.isStreaming(), is( true ) ); @@ -789,7 +787,7 @@ public class CappedBufferHttpEntityTest { replay = new CappedBufferHttpEntity( 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 CappedBufferHttpEntity( streaming, 5 ); assertThat( replay.isStreaming(), is( true ) ); } @@ -801,7 +799,7 @@ public class CappedBufferHttpEntityTest { CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); - basic.setContent( new ByteArrayInputStream( input.getBytes( UTF8 ) ) ); + basic.setContent( new ByteArrayInputStream( input.getBytes( StandardCharsets.UTF_8 ) ) ); replay = new CappedBufferHttpEntity( basic, 5 ); try { http://git-wip-us.apache.org/repos/asf/knox/blob/4961cd13/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java index 29b72df..89afd0d 100644 --- a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java +++ b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.lang.reflect.Method; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -150,7 +151,7 @@ public class GatewayDispatchFilterTest { doTestServiceDispatchWhitelist(Collections.singletonList(serviceRole), null, serviceRole, - URLEncoder.encode("http://localhost:9999", "UTF-8"), + URLEncoder.encode("http://localhost:9999", StandardCharsets.UTF_8.name()), true); } @@ -166,7 +167,7 @@ public class GatewayDispatchFilterTest { doTestServiceDispatchWhitelist(Collections.singletonList(serviceRole), "DEFAULT", serviceRole, - URLEncoder.encode("http://www.notonmylist.org:9999", "UTF-8"), + URLEncoder.encode("http://www.notonmylist.org:9999", StandardCharsets.UTF_8.name()), false); }
