Repository: olingo-odata2
Updated Branches:
  refs/heads/master 14ef0cdda -> 22e787318


[OLINGO-1092] Extra Slash Issue with precceding segments

Remove addition of extra slash when the servlet path does not have preceeding 
segments

Signed-off-by: Christian Amend <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/22e78731
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/22e78731
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/22e78731

Branch: refs/heads/master
Commit: 22e787318d3a8cf067542ef232f3f359cb122dd7
Parents: 14ef0cd
Author: i050510 <[email protected]>
Authored: Thu Mar 9 16:21:01 2017 +0530
Committer: Christian Amend <[email protected]>
Committed: Thu Mar 9 12:53:11 2017 +0100

----------------------------------------------------------------------
 .../olingo/odata2/core/servlet/RestUtil.java    |  4 ++-
 .../odata2/core/servlet/ODataServletTest.java   | 27 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/22e78731/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
index da7b05b..1bdb1dd 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
@@ -230,7 +230,9 @@ public class RestUtil {
       StringBuilder stringBuilder = new StringBuilder();
       stringBuilder.append(req.getContextPath()).append(req.getServletPath());
       for (final PathSegment ps : precedingPathSegments) {
-        stringBuilder.append("/").append(ps.getPath());
+        if (!ps.getPath().equals("") && ps.getPath().length() > 0) {
+          stringBuilder.append("/").append(ps.getPath());
+        }
         for (final String key : ps.getMatrixParameters().keySet()) {
           List<String> matrixParameters = ps.getMatrixParameters().get(key);
           String matrixParameterString = ";" + key + "=";

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/22e78731/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
index 78baf5f..b3231e3 100644
--- 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
+++ 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/ODataServletTest.java
@@ -298,4 +298,31 @@ public class ODataServletTest {
     String factoryClassName = ODataServiceFactoryImpl.class.getName();
     
Mockito.when(configMock.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn(factoryClassName);
   }
+  
+  @Test
+  public void testWithNoPathAfterServletPath() throws Exception {
+    ODataServlet servlet = new ODataServlet();
+    prepareServlet(servlet);
+    prepareRequestWithNoPathAfterServletPath(reqMock, "", "/servlet-path");
+    Mockito.when(reqMock.getPathInfo()).thenReturn("/Collection");
+    
Mockito.when(reqMock.getRequestURI()).thenReturn("http://localhost:8080/servlet-path;v=1/Collection";);
+    
Mockito.when(servlet.getInitParameter("org.apache.olingo.odata2.path.split")).thenReturn("1");
+    
Mockito.when(respMock.getOutputStream()).thenReturn(Mockito.mock(ServletOutputStream.class));
+
+    servlet.service(reqMock, respMock);
+
+    
Mockito.verify(configMock).getInitParameter(ODataServiceFactory.FACTORY_LABEL);
+    
Mockito.verify(reqMock).getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL);
+
+    Assert.assertEquals(ODataServiceFactoryImpl.class, 
servlet.getServiceFactory(reqMock).getClass());
+  }
+  
+  private void prepareRequestWithNoPathAfterServletPath(final 
HttpServletRequest req, 
+      final String contextPath, final String servletPath) {
+    Mockito.when(req.getMethod()).thenReturn("GET");
+    Mockito.when(req.getContextPath()).thenReturn(contextPath);
+    Mockito.when(req.getServletPath()).thenReturn(servletPath);
+    Mockito.when(req.getRequestURI()).thenReturn(servletPath + ";v=1" + 
"/Collection");
+    
Mockito.when(req.getHeaderNames()).thenReturn(Collections.enumeration(Collections.emptyList()));
+  }
 }

Reply via email to