diff --git a/olingo/src/main/java/org/teiid/olingo/web/ContextAwareHttpSerlvetRequest.java b/olingo/src/main/java/org/teiid/olingo/web/ContextAwareHttpSerlvetRequest.java index a16c817ab8..b090124a9a 100644 --- a/olingo/src/main/java/org/teiid/olingo/web/ContextAwareHttpSerlvetRequest.java +++ b/olingo/src/main/java/org/teiid/olingo/web/ContextAwareHttpSerlvetRequest.java @@ -30,6 +30,16 @@ public ContextAwareHttpSerlvetRequest(HttpServletRequest delegate) { public void setContextPath(String path) { this.contextPath = path; } + + @Override + public StringBuffer getRequestURL() { + //Workaround for https://issues.apache.org/jira/browse/OLINGO-1324 + StringBuffer result = super.getRequestURL(); + if (result.charAt(result.length()-1) == '/') { + result.setLength(result.length() - 1); + } + return result; + } @Override public String getContextPath() { diff --git a/olingo/src/main/java/org/teiid/olingo/web/ODataFilter.java b/olingo/src/main/java/org/teiid/olingo/web/ODataFilter.java index 50cc2ac88e..44f2211c4d 100644 --- a/olingo/src/main/java/org/teiid/olingo/web/ODataFilter.java +++ b/olingo/src/main/java/org/teiid/olingo/web/ODataFilter.java @@ -146,8 +146,8 @@ public void internalDoFilter(ServletRequest request, ServletResponse response, String version = null; String modelName = null; - String uri = ((HttpServletRequest) request).getRequestURI().toString(); - String fullURL = ((HttpServletRequest) request).getRequestURL().toString(); + String uri = httpRequest.getRequestURI().toString(); + String fullURL = httpRequest.getRequestURL().toString(); if (uri.startsWith("/odata4/static/") || uri.startsWith("/odata4/keycloak/")){ //$NON-NLS-1$ //$NON-NLS-2$ chain.doFilter(httpRequest, response); return; diff --git a/olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java b/olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java index 9393b1070b..36cab00c03 100644 --- a/olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java +++ b/olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java @@ -343,9 +343,17 @@ public void testEntitySet() throws Exception { response.getContentAsString()); } + @Test + public void testEntitySetWithTrailingSlash() throws Exception { + ContentResponse response = http.GET(baseURL + "/loopy/vm1/G1/"); + assertEquals(200, response.getStatus()); + assertEquals("{\"@odata.context\":\""+baseURL+"/loopy/vm1/$metadata#G1\",\"value\":[{\"e1\":\"ABCDEFGHIJ\",\"e2\":0,\"e3\":0.0}]}", + response.getContentAsString()); + } + @Test public void testEntitySetSkipOnly() throws Exception { - ContentResponse response = http.GET(baseURL + "/loopy/vm1/G1?$skip=1"); + ContentResponse response = http.GET(baseURL + "/loopy/vm1/G1/?$skip=1"); assertEquals(200, response.getStatus()); assertEquals("{\"@odata.context\":\""+baseURL + "/loopy/vm1/$metadata#G1\",\"value\":[]}", response.getContentAsString()); @@ -353,7 +361,7 @@ public void testEntitySetSkipOnly() throws Exception { @Test public void testEntitySetWithKey() throws Exception { - ContentResponse response = http.GET(baseURL + "/loopy/vm1/G1(0)"); + ContentResponse response = http.GET(baseURL + "/loopy/vm1/G1(0)/"); assertEquals(200, response.getStatus()); assertEquals("{\"@odata.context\":\""+baseURL+"/loopy/vm1/$metadata#G1/$entity\",\"e1\":\"ABCDEFGHIJ\",\"e2\":0,\"e3\":0.0}", response.getContentAsString());