Repository: olingo-odata2 Updated Branches: refs/heads/master 742560d27 -> 14ef0cdda
[OLINGO-1090] Incorrect content format in batch error response happens when content type is application/json;odata=verbose 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/cd4a0752 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/cd4a0752 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/cd4a0752 Branch: refs/heads/master Commit: cd4a0752c7adec31b7bff08b1e6e575b5c8e73fb Parents: 742560d Author: i050510 <[email protected]> Authored: Wed Mar 8 09:15:46 2017 +0530 Committer: Christian Amend <[email protected]> Committed: Wed Mar 8 11:47:18 2017 +0100 ---------------------------------------------------------------------- .../odata2/core/rest/ODataExceptionWrapper.java | 6 ++-- .../odata2/fit/client/ClientBatchTest.java | 32 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/cd4a0752/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionWrapper.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionWrapper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionWrapper.java index 4300ab1..9dc7cde 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionWrapper.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionWrapper.java @@ -298,7 +298,8 @@ public class ODataExceptionWrapper { || ContentType.APPLICATION_ATOM_XML_CS_UTF_8.equals(convertedContentType)) { return ContentType.APPLICATION_XML; } else if (ContentType.APPLICATION_JSON.equals(convertedContentType) - || ContentType.APPLICATION_JSON_CS_UTF_8.equals(convertedContentType)) { + || ContentType.APPLICATION_JSON_CS_UTF_8.equals(convertedContentType) + || ContentType.APPLICATION_JSON_ODATA_VERBOSE.equals(convertedContentType)) { return ContentType.APPLICATION_JSON; } } @@ -343,7 +344,8 @@ public class ODataExceptionWrapper { || ContentType.APPLICATION_ATOM_XML_CS_UTF_8.equals(convertedContentType)) { return ContentType.APPLICATION_XML; } else if (ContentType.APPLICATION_JSON.equals(convertedContentType) - || ContentType.APPLICATION_JSON_CS_UTF_8.equals(convertedContentType)) { + || ContentType.APPLICATION_JSON_CS_UTF_8.equals(convertedContentType) + || ContentType.APPLICATION_JSON_ODATA_VERBOSE.equals(convertedContentType)) { return ContentType.APPLICATION_JSON; } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/cd4a0752/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java index cf6c9f3..66be286 100644 --- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java +++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/client/ClientBatchTest.java @@ -319,4 +319,36 @@ public class ClientBatchTest extends AbstractRefTest { assertTrue(requestBody.contains("--" + BOUNDARY)); assertTrue(requestBody.contains("--" + BOUNDARY + "--")); } + + @Test + public void testContentFormatErrorBatch() throws Exception { + List<BatchPart> batch = new ArrayList<BatchPart>(); + Map<String, String> headers = new HashMap<String, String>(); + headers.put("DataServiceVersion", "2.0"); + headers.put("MaxDataServiceVersion", "3.0"); + headers.put("Accept", "application/json;odata=verbose"); + BatchPart request = BatchQueryPart.method(ODataHttpMethod.GET.name()) + .uri("nonsense") + .headers(headers) + .build(); + batch.add(request); + + InputStream body = EntityProvider.writeBatchRequest(batch, BOUNDARY); + String bodyAsString = StringHelper.inputStreamToStringCRLFLineBreaks(body); + checkMimeHeaders(bodyAsString); + checkBoundaryDelimiters(bodyAsString); + + assertTrue(bodyAsString.contains("GET nonsense HTTP/1.1")); + HttpResponse batchResponse = execute(bodyAsString); + InputStream responseBody = batchResponse.getEntity().getContent(); + String contentType = batchResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(); + List<BatchSingleResponse> responses = EntityProvider.parseBatchResponse(responseBody, contentType); + for (BatchSingleResponse response : responses) { + assertEquals("404", response.getStatusCode()); + assertEquals("Not Found", response.getStatusInfo()); + assertEquals("application/json", response.getHeaders().get("Content-Type")); + assertEquals("{\"error\":{\"code\":null,\"message\":{\"lang\":\"en\",\"value\":" + + "\"Could not find an entity set or function import for 'nonsense'.\"}}}", response.getBody()); + } + } }
