Author: peter_firmstone Date: Sat Nov 16 09:24:46 2013 New Revision: 1542487
URL: http://svn.apache.org/r1542487 Log: RIVER-426 Support for SchemeSpecificPart with URIString normalization, patch contributed by Shawn Ellis Modified: river/jtsk/skunk/qa_refactor/trunk/src/manifest/jsk-platform.mf river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/impl/net/UriString.java river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/impl/net/UriStringTest.java Modified: river/jtsk/skunk/qa_refactor/trunk/src/manifest/jsk-platform.mf URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/manifest/jsk-platform.mf?rev=1542487&r1=1542486&r2=1542487&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/src/manifest/jsk-platform.mf (original) +++ river/jtsk/skunk/qa_refactor/trunk/src/manifest/jsk-platform.mf Sat Nov 16 09:24:46 2013 @@ -1,4 +1,4 @@ -Manifest-Version: 1.0 -Class-Path: jsk-resources.jar -Implementation-Vendor: Apache Software Foundation -Implementation-Version: 2.2.0 +Manifest-Version: 1.0 +Class-Path: jsk-resources.jar high-scale-lib.jar reference-collections-1.0.1.jar +Implementation-Vendor: Apache Software Foundation +Implementation-Version: 2.2.0 Modified: river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/impl/net/UriString.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/impl/net/UriString.java?rev=1542487&r1=1542486&r2=1542487&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/impl/net/UriString.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/impl/net/UriString.java Sat Nov 16 09:24:46 2013 @@ -505,7 +505,15 @@ public class UriString { } // TODO: query and fragment normalisation. try { - return new URI(scheme, uri.getUserInfo(), host, uri.getPort(), path, uri.getQuery(), uri.getFragment()); + // Patch contributed by Shawn Ellis + URI result; + String schemeSpecificPart = uri.getSchemeSpecificPart(); + if (! schemeSpecificPart.startsWith("/")) { + result = new URI(scheme, schemeSpecificPart, uri.getFragment()); + } else { + result = new URI(scheme, uri.getRawUserInfo(), host, uri.getPort(), path, uri.getQuery(), uri.getFragment()); + } + return result; } catch (URISyntaxException e){ //Somethings gone horribly wrong! Normalisation failed. logger.log(Level.SEVERE, "Normalisation failed: {0}", e.getMessage()); Modified: river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/impl/net/UriStringTest.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/impl/net/UriStringTest.java?rev=1542487&r1=1542486&r2=1542487&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/impl/net/UriStringTest.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/test/src/org/apache/river/impl/net/UriStringTest.java Sat Nov 16 09:24:46 2013 @@ -1,129 +1,140 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.river.impl.net; - -import java.net.URI; -import java.net.URISyntaxException; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author peter - */ -public class UriStringTest { - - public UriStringTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of parse method, of class UriString. - */ - @Test - public void testEscapeIllegalCharacters() throws URISyntaxException { - System.out.println("escapeIllegalCharacters"); - String url = " "; - String expResult = "%20"; - String result = UriString.escapeIllegalCharacters(url); - assertEquals(expResult, result); - } - - @Test - public void testEscape() throws URISyntaxException { - System.out.println("test escape"); - String url = "file:/c:/Program Files/java"; - String expResult = "file:/c:/Program%20Files/java"; - String result = UriString.escapeIllegalCharacters(url); - assertEquals(expResult, result); - url = "file:/c:/Program Files/java<|>lib"; - expResult = "file:/c:/Program%20Files/java%3C%7C%3Elib"; - result = UriString.escapeIllegalCharacters(url); - assertEquals(expResult, result); - } - -// @Test -// public void testNormalise() throws URISyntaxException{ -// System.out.println("normalise test"); -// URI uri = new URI("FILE:/c:/Program%20Files/java"); -// String expResult = "file:/C:/PROGRAM%20FILES/JAVA"; -// String result = UriString.normalise(uri).toString(); -// assertEquals(expResult, result); -// } - - - @Test - public void testNormalisation() throws URISyntaxException { - System.out.println("URI Normalisation Test"); - URI url = new URI("HTTP://river.apache.ORG/foo%7ebar/file%3clib"); - URI expResult = new URI("http://river.apache.org/foo~bar/file%3Clib"); - URI result = UriString.normalisation(url); - assertEquals(expResult, result); - assertEquals(result.toString(), "http://river.apache.org/foo~bar/file%3Clib"); - } - - @Test - public void testNormalisation2() throws URISyntaxException { - System.out.println("URI Normalisation Test 2"); - URI url = new URI("http://Bryan-Thompson-MacBook-Air.local:9082/qa1-start-testservice1-dl.jar"); - URI expResult = new URI("http://bryan-thompson-macbook-air.local:9082/qa1-start-testservice1-dl.jar"); - URI result = UriString.normalisation(url); - assertEquals(expResult.toString(), result.toString()); - } - - @Test - public void testNormalisation3() throws URISyntaxException { - System.out.println("URI Normalisation Test 3"); - URI url = new URI("http://Bryan-Thompson-MacBook-Air.local:9082/qa1-start-testservice1-dl.jar"); - String host = url.getHost(); - String expHost = "Bryan-Thompson-MacBook-Air.local"; - assertEquals(expHost, host); - url = UriString.normalisation(url); - host = url.getHost(); - expHost = "bryan-thompson-macbook-air.local"; - assertEquals(expHost, host); - } - -// @Test -// public void testFixWindowsURI() { -// System.out.println("Test fix Windows file URI string"); -// String uri = "file:C:\\home\\user"; -// String expResult = "file:/C:/home/user"; -// String result = UriString.fixWindowsURI(uri); -// assertEquals(expResult, result); -// } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.river.impl.net; + +import java.net.URI; +import java.net.URISyntaxException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author peter + */ +public class UriStringTest { + + public UriStringTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of parse method, of class UriString. + */ + @Test + public void testEscapeIllegalCharacters() throws URISyntaxException { + System.out.println("escapeIllegalCharacters"); + String url = " "; + String expResult = "%20"; + String result = UriString.escapeIllegalCharacters(url); + assertEquals(expResult, result); + } + + @Test + public void testEscape() throws URISyntaxException { + System.out.println("test escape"); + String url = "file:/c:/Program Files/java"; + String expResult = "file:/c:/Program%20Files/java"; + String result = UriString.escapeIllegalCharacters(url); + assertEquals(expResult, result); + url = "file:/c:/Program Files/java<|>lib"; + expResult = "file:/c:/Program%20Files/java%3C%7C%3Elib"; + result = UriString.escapeIllegalCharacters(url); + assertEquals(expResult, result); + } + +// @Test +// public void testNormalise() throws URISyntaxException{ +// System.out.println("normalise test"); +// URI uri = new URI("FILE:/c:/Program%20Files/java"); +// String expResult = "file:/C:/PROGRAM%20FILES/JAVA"; +// String result = UriString.normalise(uri).toString(); +// assertEquals(expResult, result); +// } + + + @Test + public void testNormalisation() throws URISyntaxException { + System.out.println("URI Normalisation Test"); + URI url = new URI("HTTP://river.apache.ORG/foo%7ebar/file%3clib"); + URI expResult = new URI("http://river.apache.org/foo~bar/file%3Clib"); + URI result = UriString.normalisation(url); + assertEquals(expResult, result); + assertEquals(result.toString(), "http://river.apache.org/foo~bar/file%3Clib"); + } + + @Test + public void testNormalisation2() throws URISyntaxException { + System.out.println("URI Normalisation Test 2"); + URI url = new URI("http://Bryan-Thompson-MacBook-Air.local:9082/qa1-start-testservice1-dl.jar"); + URI expResult = new URI("http://bryan-thompson-macbook-air.local:9082/qa1-start-testservice1-dl.jar"); + URI result = UriString.normalisation(url); + assertEquals(expResult.toString(), result.toString()); + } + + @Test + public void testNormalisation3() throws URISyntaxException { + System.out.println("URI Normalisation Test 3"); + URI url = new URI("http://Bryan-Thompson-MacBook-Air.local:9082/qa1-start-testservice1-dl.jar"); + String host = url.getHost(); + String expHost = "Bryan-Thompson-MacBook-Air.local"; + assertEquals(expHost, host); + url = UriString.normalisation(url); + host = url.getHost(); + expHost = "bryan-thompson-macbook-air.local"; + assertEquals(expHost, host); + } + +// @Test +// public void testFixWindowsURI() { +// System.out.println("Test fix Windows file URI string"); +// String uri = "file:C:\\home\\user"; +// String expResult = "file:/C:/home/user"; +// String result = UriString.fixWindowsURI(uri); +// assertEquals(expResult, result); +// } + + @Test + public void testNormalisationWithSchemeSpecificPart() + throws URISyntaxException { + + URI url = new URI("jar:file:/home/user/files.war!/WEB-INF/classes"); + URI expected = new URI("jar:file:/home/user/files.war!/WEB-INF/classes"); + URI result = UriString.normalisation(url); + + assertEquals(expected.toString(), result.toString()); +} +}
