[OLINGO-1574] ....
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
index e24796e..5b29506 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
@@ -78,7 +78,7 @@
// This should be 202 for service version <= 3.0 and 200 for service version >= 4.0 but it seems that
// many service implementations are not fully compliant in this respect.
if (response.getStatusCode() != 202 && response.getStatusCode() != 200) {
- throw new ODataServerErrorException(new ResponseStatusLine(response));
+ throw new ODataServerErrorException(new ResponseStatusLine(response), response.getRawResponse());
}
if (!items.isEmpty()) {
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
index 290f59f..ada04b3 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataClientErrorException.java
@@ -23,6 +23,8 @@
import org.apache.olingo.commons.api.ex.ODataError;
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
+import java.io.InputStream;
+
/**
* Represents a client error in OData.
*
@@ -35,7 +37,9 @@
private final StatusLine statusLine;
private final ODataError error;
-
+
+ private final InputStream rawResponse;
+
private Header[] headerInfo;
/**
@@ -44,10 +48,27 @@
* @param statusLine request status info.
*/
public ODataClientErrorException(final StatusLine statusLine) {
- super(statusLine.toString());
+ this(statusLine, null, null);
+ }
- this.statusLine = statusLine;
- this.error = null;
+ /**
+ * Constructor
+ *
+ * @param statusLine request status info.
+ * @param rawResponse raw response of the request.
+ */
+ public ODataClientErrorException(final StatusLine statusLine, final InputStream rawResponse) {
+ this(statusLine, null, rawResponse);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param statusLine request status info.
+ * @param error OData error to be wrapped.
+ */
+ public ODataClientErrorException(final StatusLine statusLine, final ODataError error) {
+ this(statusLine, error, null);
}
/**
@@ -55,8 +76,9 @@
*
* @param statusLine request status info.
* @param error OData error to be wrapped.
+ * @param rawResponse raw response of the request.
*/
- public ODataClientErrorException(final StatusLine statusLine, final ODataError error) {
+ public ODataClientErrorException(final StatusLine statusLine, final ODataError error, final InputStream rawResponse) {
super(error == null ?
statusLine.toString() :
(error.getCode() == null || error.getCode().isEmpty() ? "" : "(" + error.getCode() + ") ")
@@ -64,6 +86,7 @@
this.statusLine = statusLine;
this.error = error;
+ this.rawResponse = rawResponse;
}
/**
@@ -99,4 +122,13 @@
public Header[] getHeaderInfo() {
return headerInfo;
}
+
+ /**
+ * Return raw response from the request (can be null).
+ *
+ * @return raw response from the request (can be null).
+ */
+ public InputStream getRawResponse() {
+ return rawResponse;
+ }
}
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataServerErrorException.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataServerErrorException.java
index 932e3cb..9141784 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataServerErrorException.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/ODataServerErrorException.java
@@ -21,6 +21,8 @@
import org.apache.http.StatusLine;
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
+import java.io.InputStream;
+
/**
* Represents a server error in OData.
*/
@@ -28,12 +30,34 @@
private static final long serialVersionUID = -6423014532618680135L;
+ private InputStream rawResponse;
+
/**
* Constructor.
*
* @param statusLine request status info.
*/
public ODataServerErrorException(final StatusLine statusLine) {
+ this(statusLine, null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param statusLine request status info.
+ * @param rawResponse raw response of the request.
+ */
+ public ODataServerErrorException(final StatusLine statusLine, final InputStream rawResponse) {
super(statusLine.toString());
+ this.rawResponse = rawResponse;
+ }
+
+ /**
+ * Return raw response from the request (can be null).
+ *
+ * @return raw response from the request (can be null).
+ */
+ public InputStream getRawResponse() {
+ return rawResponse;
}
}
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java
index 1f8413b..0c05af4 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/header/ODataErrorResponseChecker.java
@@ -18,6 +18,7 @@
*/
package org.apache.olingo.client.core.communication.header;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
@@ -31,7 +32,6 @@
import org.apache.olingo.commons.api.ex.ODataError;
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.client.api.serialization.ODataDeserializerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +51,8 @@
final ODataClient odataClient, final StatusLine statusLine, final InputStream entity,
final String accept) {
- ODataRuntimeException result = null;
+ ODataRuntimeException result;
+ InputStream entityForException = null;
if (entity == null) {
result = new ODataClientErrorException(statusLine);
@@ -61,7 +62,9 @@
ODataError error = new ODataError();
if (!accept.contains("text/plain")) {
try {
- error = odataClient.getReader().readError(entity, contentType);
+ byte[] bytes = IOUtils.toByteArray(entity);
+ entityForException = new ByteArrayInputStream(bytes);
+ error = odataClient.getReader().readError(new ByteArrayInputStream(bytes), contentType);
if (error != null) {
Map<String, String> innerError = error.getInnerError();
if (innerError != null) {
@@ -72,7 +75,7 @@
}
}
}
- } catch (final RuntimeException | ODataDeserializerException e) {
+ } catch (final RuntimeException | ODataDeserializerException | IOException e) {
LOG.warn("Error deserializing error response", e);
error = getGenericError(
statusLine.getStatusCode(),
@@ -94,9 +97,9 @@
if (statusLine.getStatusCode() >= 500 && error!= null &&
(error.getDetails() == null || error.getDetails().isEmpty()) &&
(error.getInnerError() == null || error.getInnerError().size() == 0)) {
- result = new ODataServerErrorException(statusLine);
+ result = new ODataServerErrorException(statusLine, entityForException);
} else {
- result = new ODataClientErrorException(statusLine, error);
+ result = new ODataClientErrorException(statusLine, error, entityForException);
}
}