From 098ed145dbafa2bd59d35448ec37fcf0b01bcb98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= <--global> Date: Fri, 4 Jul 2014 11:23:36 +0200 Subject: [PATCH] [OLINGO-341] Fix --- .../apache/olingo/fit/tecsvc/BasicITCase.java | 14 +++++++++-- .../AbstractODataRetrieveRequest.java | 6 +---- .../retrieve/EdmMetadataRequestImpl.java | 10 ++++++++ .../retrieve/v4/XMLMetadataRequestImpl.java | 24 +++++++++++-------- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java index 136d513ac..8c5650f80 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java @@ -18,14 +18,17 @@ */ package org.apache.olingo.fit.tecsvc; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; +import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.ODataClientFactory; import org.apache.olingo.commons.api.domain.ODataServiceDocument; import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.junit.Before; import org.junit.Test; @@ -43,7 +46,7 @@ public class BasicITCase { @Test public void readServiceDocument() { ODataServiceDocumentRequest request = - odata.getRetrieveRequestFactory().getServiceDocumentRequest(REF_SERVICE); + odata.getRetrieveRequestFactory().getServiceDocumentRequest(REF_SERVICE); request.setAccept("application/json;odata.metadata=minimal"); assertNotNull(request); ODataServiceDocument serviceDocument = request.execute().getBody(); @@ -54,7 +57,14 @@ public class BasicITCase { public void readMetadata() { EdmMetadataRequest request = odata.getRetrieveRequestFactory().getMetadataRequest(REF_SERVICE); assertNotNull(request); - Edm edm = request.execute().getBody(); + + ODataRetrieveResponse response = request.execute(); + assertEquals(200, response.getStatusCode()); + + Edm edm = response.getBody(); assertNotNull(edm); + assertEquals("com.sap.odata.test1", edm.getSchema("com.sap.odata.test1").getNamespace()); + assertEquals("Namespace1_Alias", edm.getSchema("com.sap.odata.test1").getAlias()); + assertNotNull(edm.getTerm(new FullQualifiedName("Core.Description"))); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java index 1a28a14a6..c42832c2d 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractODataRetrieveRequest.java @@ -62,7 +62,7 @@ public abstract class AbstractODataRetrieveRequest * Response abstract class about an ODataRetrieveRequest. */ protected abstract class AbstractODataRetrieveResponse - extends AbstractODataResponse implements ODataRetrieveResponse { + extends AbstractODataResponse implements ODataRetrieveResponse { /** * Constructor. @@ -83,10 +83,6 @@ public abstract class AbstractODataRetrieveRequest super(client, res); } - protected HttpResponse getHttpResponse() { - return res; - } - @Override public abstract T getBody(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/EdmMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/EdmMetadataRequestImpl.java index 5a02a19f6..64486fff5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/EdmMetadataRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/EdmMetadataRequestImpl.java @@ -57,6 +57,16 @@ class EdmMetadataRequestImpl extends AbstractMetadataRequestImpl implements xmlMetadataResponse.close(); } + @Override + public int getStatusCode() { + return xmlMetadataResponse.getStatusCode(); + } + + @Override + public String getStatusMessage() { + return xmlMetadataResponse.getStatusMessage(); + } + @Override public Edm getBody() { if (metadata == null) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java index 88fb07a4d..4645d861f 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/XMLMetadataRequestImpl.java @@ -23,6 +23,8 @@ import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.edm.xml.Schema; @@ -50,7 +52,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl rootRes = rootReq.execute(); - final XMLMetadataResponseImpl response = new XMLMetadataResponseImpl(); + final XMLMetadataResponseImpl response = new XMLMetadataResponseImpl(httpClient, rootReq.getHttpResponse()); final XMLMetadata rootMetadata = rootRes.getBody(); for (Schema schema : rootMetadata.getSchemas()) { @@ -87,7 +89,7 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl { + private HttpResponse httpResponse; + public SingleXMLMetadatRequestImpl(final ODataClient odataClient, final URI uri) { super(odataClient, uri); } + public HttpResponse getHttpResponse() { + return httpResponse; + } + @Override public ODataRetrieveResponse execute() { - return new AbstractODataRetrieveResponse(httpClient, doExecute()) { + httpResponse = doExecute(); + return new AbstractODataRetrieveResponse(httpClient, httpResponse) { @Override public XMLMetadata getBody() { @@ -147,13 +156,8 @@ public class XMLMetadataRequestImpl extends AbstractMetadataRequestImpl schemas = new HashMap(); - /** - * Constructor. - *
- * Just to create response templates to be initialized from batch. - */ - private XMLMetadataResponseImpl() { - super(); + private XMLMetadataResponseImpl(final HttpClient client, final HttpResponse res) { + super(client, res); } @Override