You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by fm...@apache.org on 2014/03/28 19:37:11 UTC
git commit: [OLINGO-175, OLINGO-205] Resolving References via ~/?=…
Repository: olingo-odata4
Updated Branches:
refs/heads/olingo200 645cdff84 -> 583a83dc4
[OLINGO-175, OLINGO-205] Resolving References via ~/?=…
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/583a83dc
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/583a83dc
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/583a83dc
Branch: refs/heads/olingo200
Commit: 583a83dc4baef7891df36db009ae672db3456c76
Parents: 645cdff
Author: fmartelli <fa...@gmail.com>
Authored: Fri Mar 28 19:36:47 2014 +0100
Committer: fmartelli <fa...@gmail.com>
Committed: Fri Mar 28 19:36:47 2014 +0100
----------------------------------------------------------------------
.../org/apache/olingo/fit/AbstractServices.java | 8 ++-
.../org/apache/olingo/fit/V4NorthWindExt.java | 3 +-
.../java/org/apache/olingo/fit/V4Services.java | 3 +-
.../utils/ResolvingReferencesInterceptor.java | 57 ++++++++++++++++++++
.../core/it/v4/EntityRetrieveTestITCase.java | 26 ++++++---
5 files changed, 87 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/583a83dc/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index e25908f..237d0ae 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -144,7 +144,13 @@ public abstract class AbstractServices {
return xml.createFaultResponse(Accept.XML.toString(getVersion()), e);
}
}
-
+//
+// @GET
+// @Path("/$entity")
+// public Response getEntityReference(@QueryParam("$id") String id){
+// return null;
+// }
+
/**
* Retrieve entity reference sample.
*
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/583a83dc/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java b/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java
index 0dad6ac..a3d60a7 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4NorthWindExt.java
@@ -24,9 +24,10 @@ import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import org.apache.cxf.interceptor.InInterceptors;
import static org.apache.olingo.fit.utils.Constants.METADATA;
+import org.apache.olingo.fit.utils.ResolvingReferencesInterceptor;
@Path("/V40/NorthWindExt.svc")
-@InInterceptors(classes = XHTTPMethodInterceptor.class)
+@InInterceptors(classes = {XHTTPMethodInterceptor.class, ResolvingReferencesInterceptor.class})
public class V4NorthWindExt extends AbstractServices {
public V4NorthWindExt() throws Exception {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/583a83dc/fit/src/main/java/org/apache/olingo/fit/V4Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
index 3fc5ddc..327e82d 100644
--- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java
@@ -22,9 +22,10 @@ import org.apache.olingo.fit.utils.ODataVersion;
import org.apache.olingo.fit.utils.XHTTPMethodInterceptor;
import javax.ws.rs.Path;
import org.apache.cxf.interceptor.InInterceptors;
+import org.apache.olingo.fit.utils.ResolvingReferencesInterceptor;
@Path("/V40/Static.svc")
-@InInterceptors(classes = XHTTPMethodInterceptor.class)
+@InInterceptors(classes = {XHTTPMethodInterceptor.class, ResolvingReferencesInterceptor.class})
public class V4Services extends AbstractServices {
public V4Services() throws Exception {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/583a83dc/fit/src/main/java/org/apache/olingo/fit/utils/ResolvingReferencesInterceptor.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/ResolvingReferencesInterceptor.java b/fit/src/main/java/org/apache/olingo/fit/utils/ResolvingReferencesInterceptor.java
new file mode 100644
index 0000000..4adac8a
--- /dev/null
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/ResolvingReferencesInterceptor.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.fit.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URLDecoder;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class ResolvingReferencesInterceptor extends AbstractPhaseInterceptor<Message> {
+
+ public ResolvingReferencesInterceptor() {
+ super(Phase.PRE_PROTOCOL);
+ }
+
+ @Override
+ public void handleMessage(final Message message) throws Fault {
+ final String path = (String) message.get(Message.PATH_INFO);
+ final String query = (String) message.get(Message.QUERY_STRING);
+
+ try {
+ if (path.endsWith("$entity") && StringUtils.isNotBlank(query)
+ && URLDecoder.decode(query, "UTF-8").contains("$id=")) {
+ final String id = URLDecoder.decode(query, "UTF-8");
+ final String newURL = id.substring(id.indexOf("$id=") + 4);
+
+ final URI uri = URI.create(newURL);
+
+ message.put(Message.REQUEST_URL, uri.toASCIIString());
+ message.put(Message.REQUEST_URI, uri.getPath());
+ message.put(Message.PATH_INFO, uri.getPath());
+ }
+
+ } catch (UnsupportedEncodingException ignore) {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/583a83dc/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
index a96384f..6d2a89d 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.olingo.client.core.it.v4;
+import java.net.URI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -38,6 +39,7 @@ import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.domain.ODataProperty;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
+import static org.apache.olingo.client.core.it.v4.AbstractTestITCase.client;
import org.apache.olingo.commons.core.op.ResourceFactory;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.junit.Ignore;
@@ -252,29 +254,39 @@ public class EntityRetrieveTestITCase extends AbstractTestITCase {
}
@Test
- public void retrieveEntityReferenceAsAtom() {
- retrieveEntityReference(ODataPubFormat.ATOM);
+ public void retrieveEntityViaReferenceAsAtom() {
+ retrieveEntityViaReference(ODataPubFormat.ATOM);
}
@Test
@Ignore
- public void retrieveEntityReferenceAsJSON() {
- retrieveEntityReference(ODataPubFormat.JSON_FULL_METADATA);
+ public void retrieveEntityViaReferenceAsJSON() {
+ retrieveEntityViaReference(ODataPubFormat.JSON_FULL_METADATA);
}
- private void retrieveEntityReference(final ODataPubFormat format) {
+ private void retrieveEntityViaReference(final ODataPubFormat format) {
final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
appendEntitySetSegment("Orders").appendKeySegment(8).appendNavigationSegment("CustomerForOrder").
appendRefSegment();
- final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(format);
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ ODataRetrieveResponse<ODataEntity> res = req.execute();
assertNotNull(res);
final ODataEntity entity = res.getBody();
assertNotNull(entity);
assertTrue(entity.getReference().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
+
+ final URI referenceURI =
+ client.getURIBuilder(getServiceRoot()).appendEntityIdSegment(entity.getReference()).build();
+
+ req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI);
+ req.setFormat(format);
+
+ res = req.execute();
+ assertNotNull(res);
+ assertNotNull(res.getBody());
}
}