Repository: olingo-odata4
Updated Branches:
  refs/heads/master 32ff14fe7 -> 66ea810b0


[ODATAJAVA-1134]Enhancement to run better with Spring


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/66ea810b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/66ea810b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/66ea810b

Branch: refs/heads/master
Commit: 66ea810b0f054642f3fa5ae3c4e0d9295cc55c1f
Parents: 32ff14f
Author: Archana Rai <[email protected]>
Authored: Thu Jun 8 16:37:27 2017 +0530
Committer: Archana Rai <[email protected]>
Committed: Thu Jun 8 16:37:27 2017 +0530

----------------------------------------------------------------------
 .../server/core/ODataHttpHandlerImpl.java       |  8 ++-
 .../server/core/ODataHttpHandlerImplTest.java   | 60 ++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/66ea810b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index b6ebc6b..6c4b1b3 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -57,6 +57,7 @@ import org.apache.olingo.server.core.debug.ServerCoreDebugger;
 public class ODataHttpHandlerImpl implements ODataHttpHandler {
 
   public static final int COPY_BUFFER_SIZE = 8192;
+  private static final String REQUESTMAPPING = "requestMapping";
 
   private final ODataHandlerImpl handler;
   private final ServerCoreDebugger debugger;
@@ -267,7 +268,12 @@ public class ODataHttpHandlerImpl implements 
ODataHttpHandler {
     String rawRequestUri = httpRequest.getRequestURL().toString();
 
     String rawODataPath;
-    if (!"".equals(httpRequest.getServletPath())) {
+    //Application need to set the request mapping attribute if the request is 
coming from a spring based application
+    if(httpRequest.getAttribute(REQUESTMAPPING)!=null){
+      String requestMapping = 
httpRequest.getAttribute(REQUESTMAPPING).toString();
+      int beginIndex = rawRequestUri.indexOf(requestMapping) + 
requestMapping.length();
+      rawODataPath = rawRequestUri.substring(beginIndex);
+    }else if(!"".equals(httpRequest.getServletPath())) {
       int beginIndex = rawRequestUri.indexOf(httpRequest.getServletPath()) + 
httpRequest.getServletPath().length();
       rawODataPath = rawRequestUri.substring(beginIndex);
     } else if (!"".equals(httpRequest.getContextPath())) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/66ea810b/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataHttpHandlerImplTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataHttpHandlerImplTest.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataHttpHandlerImplTest.java
index 2a58f57..0645423 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataHttpHandlerImplTest.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataHttpHandlerImplTest.java
@@ -164,4 +164,64 @@ public class ODataHttpHandlerImplTest {
       assertEquals(rawServiceResolutionUri, odr.getRawServiceResolutionUri());
     }
   }
+  
+  @Test
+  public void extractUriForController() {
+
+    //@formatter:off (Eclipse formatter)
+    //CHECKSTYLE:OFF (Maven checkstyle)
+    String [][] uris = {
+        /* 0: host                    1: cp         2: sp       3: sr          
4: od       5: qp        6: spl  */
+        
+        {  "http://localhost";,          "",           "/sp",      "",          
"",          "",         "0"},
+        {  "http://localhost";,          "",           "/sp",      "",          
"/",         "",         "0"},
+        {  "http://localhost";,          "",           "/sp",      "",          
"/od",       "",         "0"},
+       
+        {  "http://localhost";,          "/cp",        "/sp",      "",          
"",          "",         "0"},
+        {  "http://localhost";,          "/cp",        "/sp",      "",          
"/",         "",         "0"},
+        {  "http://localhost";,          "/cp",        "/sp",      "",          
"/od",       "",         "0"},
+       
+        {  "http://localhost";,          "/cp",        "/sp",      "/sr",       
"",          "",         "1"},
+        {  "http://localhost";,          "/cp",        "/sp",      "/sr",       
"/",         "",         "1"},
+        {  "http://localhost";,          "/cp",        "/sp",      "/sr",       
"/od",       "",         "1"},
+
+     
+        {  "http://localhost";,          "/cp",        "/sp",      "/sr",       
"/od",       "qp",       "1"},
+
+        {  "http://localhost:8080";,     "/c%20p",     "/s%20p",   "/s%20r",    
"/o%20d",    "p+q",      "1"},
+    };
+    //@formatter:on
+    // CHECKSTYLE:on
+
+    for (String[] p : uris) {
+      HttpServletRequest hr = mock(HttpServletRequest.class);
+
+      String requestUrl = p[0] + p[1] + p[2] + p[3] + p[4];
+      String requestUri = p[1] + p[2] + p[3] + p[4];
+      String queryString = p[5].isEmpty() ? null : p[5];
+
+      when(hr.getRequestURL()).thenReturn(new StringBuffer(requestUrl));
+      when(hr.getRequestURI()).thenReturn(requestUri);
+      when(hr.getQueryString()).thenReturn(queryString);
+      when(hr.getContextPath()).thenReturn(p[1]);
+      when(hr.getServletPath()).thenReturn(p[2]);
+
+      ODataRequest odr = new ODataRequest();
+
+      String rawBaseUri = p[0] + p[1] + p[2] + p[3];
+      String rawODataPath = p[4];
+      String rawQueryPath = "".equals(p[5]) ? null : p[5];
+      String rawRequestUri = requestUrl + (queryString == null ? "" : "?" + 
queryString);
+      String rawServiceResolutionUri = "".equals(p[3]) ? null : p[3];
+
+      when(hr.getAttribute("requestMapping")).thenReturn(p[2]);
+      ODataHttpHandlerImpl.fillUriInformation(odr, hr, Integer.parseInt(p[6]));
+      assertEquals(rawBaseUri, odr.getRawBaseUri());
+      assertEquals(rawODataPath, odr.getRawODataPath());
+      assertEquals(rawQueryPath, odr.getRawQueryPath());
+      assertEquals(rawRequestUri, odr.getRawRequestUri());
+      assertEquals(rawServiceResolutionUri, odr.getRawServiceResolutionUri());
+    
+    }
+  }
 }

Reply via email to