Skip to content

Commit

Permalink
TEIID-5573 allowing for a trailing / to work
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Dec 14, 2018
1 parent ec318ee commit ae17a6e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions olingo/src/main/java/org/teiid/olingo/web/ODataFilter.java
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java
Expand Up @@ -343,17 +343,25 @@ 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());
}

@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());
Expand Down

0 comments on commit ae17a6e

Please sign in to comment.