From cd81b64daa45831ba99b8d93bdc5a4d33943ee11 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 24 Jan 2017 00:11:49 +0100 Subject: Add a failing unit test for consecutive slahes in uri --- .../src/test/java/com/yahoo/document/restapi/RestUriTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'vespaclient-container-plugin') diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java index 4bb7a264aba..db1fe220614 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java @@ -106,4 +106,13 @@ public class RestUriTest { new RestUri(createUri("/document/v1/namespace/doctype/Q/myid", "")); } + @Test + public void testDocIdAsIs() throws Exception { + RestUri restUri = new RestUri(new URI("/document/v1/test/newsarticle/docid/http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html").normalize()); + assertThat(restUri.getNamespace(), is("test")); + assertThat(restUri.getDocumentType(), is("newsarticle")); + assertThat(restUri.getDocId(), is("http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); + assertThat(restUri.generateFullId(), is("id:test:newsarticle::http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); + } + } -- cgit v1.2.3 From 0eb6bde381b186ec08f308c93180c9fe28733cf9 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 24 Jan 2017 13:06:38 +0100 Subject: Add getRawUri() --- jdisc_core/src/main/java/com/yahoo/jdisc/Request.java | 15 ++++++++++++++- .../src/test/java/com/yahoo/jdisc/RequestTestCase.java | 16 ++++++++++++++++ .../java/com/yahoo/document/restapi/RestUriTest.java | 4 ++-- 3 files changed, 32 insertions(+), 3 deletions(-) (limited to 'vespaclient-container-plugin') diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java b/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java index d893bb443b7..4f7ccee64bf 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java @@ -46,6 +46,7 @@ public class Request extends AbstractResource { private TimeoutManager timeoutManager; private boolean serverRequest; private Long timeout; + private URI rawUri; private URI uri; /** @@ -125,7 +126,7 @@ public class Request extends AbstractResource { } /** - *

Returns the Uniform Resource Identifier used by the {@link Container} to resolve the appropriate {@link + *

Returns the normalized Uniform Resource Identifier used by the {@link Container} to resolve the appropriate {@link * RequestHandler} for this Request.

* * @return The resource identifier. @@ -135,6 +136,17 @@ public class Request extends AbstractResource { return uri; } + /** + *

Returns the original raw Uniform Resource Identifier used by the {@link Container} to resolve the appropriate {@link + * RequestHandler} for this Request.

+ * + * @return The resource identifier. + * @see #setUri(URI) + */ + public URI getRawUri() { + return rawUri; + } + /** *

Sets the Uniform Resource Identifier used by the {@link Container} to resolve the appropriate {@link * RequestHandler} for this Request. Because access to the URI is not guarded by any lock, any changes made after @@ -145,6 +157,7 @@ public class Request extends AbstractResource { * @see #getUri() */ public Request setUri(URI uri) { + this.rawUri = uri; this.uri = uri.normalize(); return this; } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java index fe5af79a6d3..6c2b62a49ab 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java @@ -62,6 +62,22 @@ public class RequestTestCase { assertTrue(driver.close()); } + @Test + public void requireThatOriginalUriIsRetained() { + MyTimer timer = new MyTimer(); + timer.currentTime = 69; + + TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(timer); + driver.activateContainer(driver.newContainerBuilder()); + Request request = new Request(driver, URI.create("http://foo/bar")); + assertEquals("http://foo/bar", request.getUri().toString()); + assertEquals("http://foo/bar", request.getRawUri().toString()); + + request = new Request(driver, URI.create("http://foo//bar")); + assertEquals("http://foo/bar", request.getUri().toString()); + assertEquals("http://foo//bar", request.getRawUri().toString()); + } + @Test public void requireThatCancelWorks() { MyTimer timer = new MyTimer(); diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java index db1fe220614..5f646286254 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java @@ -108,10 +108,10 @@ public class RestUriTest { @Test public void testDocIdAsIs() throws Exception { - RestUri restUri = new RestUri(new URI("/document/v1/test/newsarticle/docid/http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html").normalize()); + RestUri restUri = new RestUri(new URI("/document/v1/test/newsarticle/docid/http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); assertThat(restUri.getNamespace(), is("test")); assertThat(restUri.getDocumentType(), is("newsarticle")); - assertThat(restUri.getDocId(), is("http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); + assertThat(restUri.getDocId(), is("http://vn.news.yahoo.com//gi-th-ng-t-n-ng-khoa-h-205000458.html")); assertThat(restUri.generateFullId(), is("id:test:newsarticle::http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); } -- cgit v1.2.3 From 5b01e13c4654946496c6f0bb2b4834e47d2b18d1 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 24 Jan 2017 13:14:26 +0100 Subject: Finger trouble --- .../src/test/java/com/yahoo/document/restapi/RestUriTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vespaclient-container-plugin') diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java index 5f646286254..6d642c7c57c 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java @@ -111,7 +111,7 @@ public class RestUriTest { RestUri restUri = new RestUri(new URI("/document/v1/test/newsarticle/docid/http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); assertThat(restUri.getNamespace(), is("test")); assertThat(restUri.getDocumentType(), is("newsarticle")); - assertThat(restUri.getDocId(), is("http://vn.news.yahoo.com//gi-th-ng-t-n-ng-khoa-h-205000458.html")); + assertThat(restUri.getDocId(), is("http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); assertThat(restUri.generateFullId(), is("id:test:newsarticle::http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); } -- cgit v1.2.3 From 3ba4dac28e917a9d9d86f7879093a84ea8419d0f Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 24 Jan 2017 13:16:51 +0100 Subject: Wire in access to the raw original uri. --- .../src/main/java/com/yahoo/container/jdisc/HttpRequest.java | 11 ++++++++++- .../java/com/yahoo/document/restapi/resource/RestApi.java | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'vespaclient-container-plugin') diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java b/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java index fa875e53875..e54cd6817b1 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java @@ -461,7 +461,7 @@ public class HttpRequest { } /** - * Get the full URI corresponding to this request. + * Get the full normalized URI corresponding to this request. * * @return the URI of this request */ @@ -469,6 +469,15 @@ public class HttpRequest { return parentRequest.getUri(); } + /** + * Get the full original URI corresponding to this request. + * + * @return the URI of this request + */ + public URI getRawUri() { + return parentRequest.getRawUri(); + } + /** * Access the underlying JDisc for this HTTP request. * diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index 6a7797c20a7..fc6d20c06b8 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -115,7 +115,7 @@ public class RestApi extends LoggingRequestHandler { protected HttpResponse handleInternal(HttpRequest request) { final RestUri restUri; try { - restUri = new RestUri(request.getUri()); + restUri = new RestUri(request.getRawUri()); } catch (RestApiException e) { return e.getResponse(); } catch (Exception e2) { -- cgit v1.2.3 From ae3d728e62bd3ff00ecf14649504aa34773cf63e Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 24 Jan 2017 14:16:11 +0100 Subject: Properly encode the URI to avoid normalization. --- .../main/java/com/yahoo/container/jdisc/HttpRequest.java | 11 +---------- jdisc_core/src/main/java/com/yahoo/jdisc/Request.java | 15 +-------------- .../src/test/java/com/yahoo/jdisc/RequestTestCase.java | 16 ---------------- .../com/yahoo/document/restapi/resource/RestApi.java | 2 +- .../java/com/yahoo/document/restapi/RestUriTest.java | 2 +- 5 files changed, 4 insertions(+), 42 deletions(-) (limited to 'vespaclient-container-plugin') diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java b/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java index e54cd6817b1..fa875e53875 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/HttpRequest.java @@ -461,7 +461,7 @@ public class HttpRequest { } /** - * Get the full normalized URI corresponding to this request. + * Get the full URI corresponding to this request. * * @return the URI of this request */ @@ -469,15 +469,6 @@ public class HttpRequest { return parentRequest.getUri(); } - /** - * Get the full original URI corresponding to this request. - * - * @return the URI of this request - */ - public URI getRawUri() { - return parentRequest.getRawUri(); - } - /** * Access the underlying JDisc for this HTTP request. * diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java b/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java index 4f7ccee64bf..d893bb443b7 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/Request.java @@ -46,7 +46,6 @@ public class Request extends AbstractResource { private TimeoutManager timeoutManager; private boolean serverRequest; private Long timeout; - private URI rawUri; private URI uri; /** @@ -126,7 +125,7 @@ public class Request extends AbstractResource { } /** - *

Returns the normalized Uniform Resource Identifier used by the {@link Container} to resolve the appropriate {@link + *

Returns the Uniform Resource Identifier used by the {@link Container} to resolve the appropriate {@link * RequestHandler} for this Request.

* * @return The resource identifier. @@ -136,17 +135,6 @@ public class Request extends AbstractResource { return uri; } - /** - *

Returns the original raw Uniform Resource Identifier used by the {@link Container} to resolve the appropriate {@link - * RequestHandler} for this Request.

- * - * @return The resource identifier. - * @see #setUri(URI) - */ - public URI getRawUri() { - return rawUri; - } - /** *

Sets the Uniform Resource Identifier used by the {@link Container} to resolve the appropriate {@link * RequestHandler} for this Request. Because access to the URI is not guarded by any lock, any changes made after @@ -157,7 +145,6 @@ public class Request extends AbstractResource { * @see #getUri() */ public Request setUri(URI uri) { - this.rawUri = uri; this.uri = uri.normalize(); return this; } diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java index 6c2b62a49ab..fe5af79a6d3 100644 --- a/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/RequestTestCase.java @@ -62,22 +62,6 @@ public class RequestTestCase { assertTrue(driver.close()); } - @Test - public void requireThatOriginalUriIsRetained() { - MyTimer timer = new MyTimer(); - timer.currentTime = 69; - - TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(timer); - driver.activateContainer(driver.newContainerBuilder()); - Request request = new Request(driver, URI.create("http://foo/bar")); - assertEquals("http://foo/bar", request.getUri().toString()); - assertEquals("http://foo/bar", request.getRawUri().toString()); - - request = new Request(driver, URI.create("http://foo//bar")); - assertEquals("http://foo/bar", request.getUri().toString()); - assertEquals("http://foo//bar", request.getRawUri().toString()); - } - @Test public void requireThatCancelWorks() { MyTimer timer = new MyTimer(); diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index fc6d20c06b8..6a7797c20a7 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -115,7 +115,7 @@ public class RestApi extends LoggingRequestHandler { protected HttpResponse handleInternal(HttpRequest request) { final RestUri restUri; try { - restUri = new RestUri(request.getRawUri()); + restUri = new RestUri(request.getUri()); } catch (RestApiException e) { return e.getResponse(); } catch (Exception e2) { diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java index 6d642c7c57c..b2a8200b4e1 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java @@ -108,7 +108,7 @@ public class RestUriTest { @Test public void testDocIdAsIs() throws Exception { - RestUri restUri = new RestUri(new URI("/document/v1/test/newsarticle/docid/http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); + RestUri restUri = new RestUri(new URI("/document/v1/test/newsarticle/docid/http%3a%2f%2fvn.news.yahoo.com%2fgi-th-ng-t-n-ng-khoa-h-205000458.html").normalize()); assertThat(restUri.getNamespace(), is("test")); assertThat(restUri.getDocumentType(), is("newsarticle")); assertThat(restUri.getDocId(), is("http://vn.news.yahoo.com/gi-th-ng-t-n-ng-khoa-h-205000458.html")); -- cgit v1.2.3