Repository: olingo-odata4
Updated Branches:
  refs/heads/master dbf7fd386 -> b6c7d401e


OLINGO-907:corrected the usage to treat  as individual query parameter and then 
combine with others to build the complete url


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

Branch: refs/heads/master
Commit: b6c7d401e22f698237674283f5271749c50b0e60
Parents: dbf7fd3
Author: Ramesh Reddy <[email protected]>
Authored: Mon Mar 21 15:45:08 2016 -0500
Committer: Ramesh Reddy <[email protected]>
Committed: Mon Mar 21 15:46:39 2016 -0500

----------------------------------------------------------------------
 .../olingo/server/core/ServiceDispatcher.java   | 34 ++++++++++++++++++--
 .../server/core/ServiceDispatcherTest.java      | 19 +++++++++++
 .../server/example/TripPinServiceTest.java      | 13 ++++----
 3 files changed, 58 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b6c7d401/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
 
b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
index fc5c88c..45e9b06 100644
--- 
a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
+++ 
b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
@@ -18,15 +18,16 @@
  */
 package org.apache.olingo.server.core;
 
-import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.StringTokenizer;
 
 import org.apache.olingo.commons.api.ex.ODataException;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.commons.core.Decoder;
 import org.apache.olingo.server.api.OData;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.ODataLibraryException;
@@ -83,8 +84,35 @@ public class ServiceDispatcher extends 
RequestURLHierarchyVisitor {
       contentType = ContentNegotiator.doContentNegotiation(null,
           odRequest, this.customContentSupport, RepresentationType.ERROR);
       
+      String path = odRequest.getRawODataPath();      
+      String query = odRequest.getRawQueryPath();      
+      if(path.indexOf("$entity") != -1) {
+        StringBuilder sb = new StringBuilder();
+        StringTokenizer st = new StringTokenizer(query, "&");
+        while(st.hasMoreTokens()) {
+          String token = st.nextToken();
+          if (token.startsWith("$id=")) {
+            try {
+              path = new URL(Decoder.decode(token.substring(4))).getPath();
+              int index = path.indexOf('/', 1);
+              if (index != -1) {
+                path = path.substring(index);
+              }
+            } catch (Exception e) {
+              path = Decoder.decode(token.substring(4));
+            }
+          } else {
+            if (sb.length() > 0) {
+              sb.append("&");
+            }
+            sb.append(token);
+          }
+        }
+        query = sb.toString();
+      }
+      
       UriInfo uriInfo = new Parser(this.metadata.getEdm(), odata)
-      .parseUri(odRequest.getRawODataPath(), odRequest.getRawQueryPath(), 
null);
+        .parseUri(path, query, null);
       
       contentType = 
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
           odRequest, this.customContentSupport, RepresentationType.ERROR);     
 
@@ -244,6 +272,7 @@ public class ServiceDispatcher extends 
RequestURLHierarchyVisitor {
     DataRequest dataRequest = new DataRequest(this.odata, this.metadata);
     this.request = dataRequest;
 
+    /*
     // this can relative or absolute form
     String id = info.getIdOption().getValue();
     try {
@@ -252,6 +281,7 @@ public class ServiceDispatcher extends 
RequestURLHierarchyVisitor {
     } catch (MalformedURLException e) {
       this.idOption = id;
     }
+    */
     super.visit(info);
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b6c7d401/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
 
b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
index ab4a62a..53adc2e 100644
--- 
a/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
+++ 
b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
@@ -43,6 +43,7 @@ import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.commons.core.Encoder;
 import org.apache.olingo.server.api.OData;
 import org.apache.olingo.server.api.ODataHttpHandler;
 import org.apache.olingo.server.api.ServiceMetadata;
@@ -444,4 +445,22 @@ public class ServiceDispatcherTest {
           }
         });
   }
+  
+  @Test
+  public void test$id() throws Exception {
+    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+    helpGETTest(handler, 
"trippin/$entity?$id="+Encoder.encode("http://localhost:"; + TOMCAT_PORT
+        + 
"/trippin/People('russelwhyte')")+"&"+Encoder.encode("$")+"select=FirstName", 
new TestResult() {
+      @Override
+      public void validate() throws Exception {
+        ArgumentCaptor<DataRequest> arg1 = 
ArgumentCaptor.forClass(DataRequest.class);
+        ArgumentCaptor<EntityResponse> arg2 = 
ArgumentCaptor.forClass(EntityResponse.class);
+        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+
+        DataRequest request = arg1.getValue();
+        assertEquals("application/json;odata.metadata=minimal", 
request.getResponseContentType()
+            .toContentTypeString());
+      }
+    });
+  }  
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b6c7d401/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
 
b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
index eb2384b..c537edd 100644
--- 
a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
+++ 
b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
@@ -396,16 +396,17 @@ public class TripPinServiceTest {
 
   @Test
   public void testEntityId() throws Exception {
-    HttpResponse response = httpGET(baseURL+"/$entity?$id="+baseURL + 
"/People('kristakemp')", 200);
+    HttpResponse response = httpGET(baseURL+"/$entity?$id="+baseURL 
+        + "/People('kristakemp')&$select=FirstName", 200);
     JsonNode node = getJSONNode(response);
-    assertEquals("$metadata#People/$entity", 
node.get("@odata.context").asText());
-    assertEquals("kristakemp", node.get("UserName").asText());
+    assertEquals("$metadata#People(FirstName)/$entity", 
node.get("@odata.context").asText());
+    assertEquals("Krista", node.get("FirstName").asText());
 
     // using relative URL
-    response = httpGET(baseURL+"/$entity?$id="+"People('kristakemp')", 200);
+    response = 
httpGET(baseURL+"/$entity?$id="+"People('kristakemp')&$select=FirstName", 200);
     node = getJSONNode(response);
-    assertEquals("$metadata#People/$entity", 
node.get("@odata.context").asText());
-    assertEquals("kristakemp", node.get("UserName").asText());
+    assertEquals("$metadata#People(FirstName)/$entity", 
node.get("@odata.context").asText());
+    assertEquals("Krista", node.get("FirstName").asText());
   }
 
   @Test

Reply via email to