This is an automated email from the ASF dual-hosted git repository.
mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git
The following commit(s) were added to refs/heads/master by this push:
new 4958f21b1 [OLINGO-1574] ....
4958f21b1 is described below
commit 4958f21b1a921639dd293ea32227c3be336bad4b
Author: mibo <[email protected]>
AuthorDate: Fri Aug 26 17:33:00 2022 +0200
[OLINGO-1574] ....
---
.../TransactionalPersistenceManagerImpl.java | 2 +-
.../communication/ODataClientErrorException.java | 42 +++++++++++++++++++---
.../communication/ODataServerErrorException.java | 24 +++++++++++++
.../header/ODataErrorResponseChecker.java | 15 ++++----
4 files changed, 71 insertions(+), 12 deletions(-)
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 e24796efa..5b29506ae 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 @@ public class TransactionalPersistenceManagerImpl extends
AbstractPersistenceMana
// 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 290f59f89..ada04b32c 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.http.StatusLine;
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 @@ public class ODataClientErrorException extends
ODataRuntimeException {
private final StatusLine statusLine;
private final ODataError error;
-
+
+ private final InputStream rawResponse;
+
private Header[] headerInfo;
/**
@@ -44,19 +48,37 @@ public class ODataClientErrorException extends
ODataRuntimeException {
* @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.
+ * 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);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @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, final InputStream rawResponse) {
super(error == null ?
statusLine.toString() :
(error.getCode() == null || error.getCode().isEmpty() ? "" : "(" +
error.getCode() + ") ")
@@ -64,6 +86,7 @@ public class ODataClientErrorException extends
ODataRuntimeException {
this.statusLine = statusLine;
this.error = error;
+ this.rawResponse = rawResponse;
}
/**
@@ -99,4 +122,13 @@ public class ODataClientErrorException extends
ODataRuntimeException {
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 932e3cb3b..9141784fb 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 @@ package org.apache.olingo.client.api.communication;
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 @@ public class ODataServerErrorException extends
ODataRuntimeException {
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 1f8413ba0..0c05af46c 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.client.api.serialization.ODataDeserializerException;
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 @@ public final class ODataErrorResponseChecker {
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 @@ public final class ODataErrorResponseChecker {
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 @@ public final class ODataErrorResponseChecker {
}
}
}
- } 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 @@ public final class ODataErrorResponseChecker {
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);
}
}