This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/2_1_X by this push:
new 5d31ca6c50 A few Batch processing improvements (#337)
5d31ca6c50 is described below
commit 5d31ca6c50dd093768cf421b6f1abd28b06254ac
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Sun Apr 10 19:07:23 2022 +0200
A few Batch processing improvements (#337)
---
.../syncope/common/rest/api/batch/BatchItem.java | 4 ++--
.../common/rest/api/batch/BatchRequestItem.java | 11 +++++++++++
.../common/rest/api/batch/BatchResponseItem.java | 9 +++++++++
.../core/rest/cxf/RestServiceExceptionMapper.java | 16 +++++++++-------
.../syncope/core/rest/cxf/batch/BatchProcess.java | 22 +++++++++++-----------
5 files changed, 42 insertions(+), 20 deletions(-)
diff --git
a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchItem.java
b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchItem.java
index 561ac6a5be..09b6d52a55 100644
---
a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchItem.java
+++
b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchItem.java
@@ -29,9 +29,9 @@ public abstract class BatchItem implements Serializable {
private static final long serialVersionUID = -1393976266651766259L;
- private final Map<String, List<Object>> headers = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ protected final Map<String, List<Object>> headers = new
TreeMap<>(String.CASE_INSENSITIVE_ORDER);
- private String content;
+ protected String content;
public Map<String, List<Object>> getHeaders() {
return headers;
diff --git
a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchRequestItem.java
b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchRequestItem.java
index 834b0fe8d9..5a9739a62f 100644
---
a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchRequestItem.java
+++
b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchRequestItem.java
@@ -51,4 +51,15 @@ public class BatchRequestItem extends BatchItem {
public void setQueryString(final String queryString) {
this.queryString = queryString;
}
+
+ @Override
+ public String toString() {
+ return "BatchRequestItem{"
+ + "method=" + method + " ,"
+ + "requestURI=" + requestURI + " ,"
+ + "queryString=" + queryString + " ,"
+ + "headers=" + headers + ", "
+ + "content=" + content + " ,"
+ + '}';
+ }
}
diff --git
a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchResponseItem.java
b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchResponseItem.java
index e989b65712..8c6f902d41 100644
---
a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchResponseItem.java
+++
b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/batch/BatchResponseItem.java
@@ -31,4 +31,13 @@ public class BatchResponseItem extends BatchItem {
public void setStatus(final int status) {
this.status = status;
}
+
+ @Override
+ public String toString() {
+ return "BatchResponseItem{"
+ + "status=" + status + ", "
+ + "headers=" + headers + ", "
+ + "content=" + content
+ + '}';
+ }
}
diff --git
a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
index acf5c3bebe..a5f3dcd4a5 100644
---
a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
+++
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/RestServiceExceptionMapper.java
@@ -29,6 +29,7 @@ import javax.persistence.EntityExistsException;
import javax.persistence.PersistenceException;
import javax.persistence.RollbackException;
import javax.validation.ValidationException;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@@ -128,17 +129,18 @@ public class RestServiceExceptionMapper implements
ExceptionMapper<Exception> {
header(RESTHeaders.ERROR_CODE,
ClientExceptionType.RESTValidation.name()).
header(RESTHeaders.ERROR_INFO,
ClientExceptionType.RESTValidation.getInfoHeaderValue(
ExceptionUtils.getRootCauseMessage(ex)));
-
- ErrorTO error = new ErrorTO();
-
error.setStatus(ClientExceptionType.RESTValidation.getResponseStatus().getStatusCode());
- error.setType(ClientExceptionType.RESTValidation);
-
error.getElements().add(ExceptionUtils.getRootCauseMessage(ex));
-
- builder.entity(error);
+ }
+ // process web application exceptions
+ if (builder == null && ex instanceof WebApplicationException) {
+ builder = builder(((WebApplicationException)
ex).getResponse()).
+ header(RESTHeaders.ERROR_CODE,
ClientExceptionType.Unknown.name()).
+ header(RESTHeaders.ERROR_INFO,
ClientExceptionType.Unknown.getInfoHeaderValue(
+ ExceptionUtils.getRootCauseMessage(ex)));
}
// ...or just report as InternalServerError
if (builder == null) {
builder =
Response.status(Response.Status.INTERNAL_SERVER_ERROR).
+ header(RESTHeaders.ERROR_CODE,
ClientExceptionType.Unknown.name()).
header(RESTHeaders.ERROR_INFO,
ClientExceptionType.Unknown.getInfoHeaderValue(
ExceptionUtils.getRootCauseMessage(ex)));
diff --git
a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/batch/BatchProcess.java
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/batch/BatchProcess.java
index 2c130956b6..5b9e3fa61e 100644
---
a/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/batch/BatchProcess.java
+++
b/core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/batch/BatchProcess.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.cxf.transport.http.DestinationRegistry;
import org.apache.syncope.common.rest.api.batch.BatchPayloadGenerator;
@@ -93,7 +94,7 @@ public class BatchProcess implements Runnable {
List<BatchResponseItem> batchResponseItems = new
ArrayList<>(batchRequestItems.size());
batchRequestItems.forEach(reqItem -> {
- LOG.debug("Batch item:\n{}", reqItem);
+ LOG.debug("Batch Request item:\n{}", reqItem);
AbstractHTTPDestination dest =
destinationRegistry.getDestinationForPath(reqItem.getRequestURI(), true);
if (dest == null) {
@@ -101,34 +102,33 @@ public class BatchProcess implements Runnable {
}
LOG.debug("Destination found for {}: {}", reqItem.getRequestURI(),
dest);
+ BatchResponseItem resItem = new BatchResponseItem();
+ batchResponseItems.add(resItem);
if (dest == null) {
- BatchResponseItem resItem = new BatchResponseItem();
- resItem.setStatus(404);
- batchResponseItems.add(resItem);
+ resItem.setStatus(HttpServletResponse.SC_NOT_FOUND);
} else {
BatchItemRequest request = new BatchItemRequest(basePath,
servletRequest, reqItem);
BatchItemResponse response = new BatchItemResponse();
try {
dest.invoke(servletConfig,
servletConfig.getServletContext(), request, response);
- LOG.debug("Returned:\nstatus: {}\nheaders: {}\nbody:\n{}",
response.getStatus(),
- response.getHeaders(), new
String(response.getUnderlyingOutputStream().toByteArray()));
- BatchResponseItem resItem = new BatchResponseItem();
resItem.setStatus(response.getStatus());
resItem.setHeaders(response.getHeaders());
String output = new
String(response.getUnderlyingOutputStream().toByteArray());
if (output.length() > 0) {
resItem.setContent(output);
}
- batchResponseItems.add(resItem);
+
+ LOG.debug("Returned:\nstatus: {}\nheaders: {}\nbody:\n{}",
+ response.getStatus(), response.getHeaders(),
output);
} catch (IOException e) {
LOG.error("Invocation of {} failed", dest.getPath(), e);
- BatchResponseItem resItem = new BatchResponseItem();
- resItem.setStatus(404);
- batchResponseItems.add(resItem);
+
resItem.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
+
+ LOG.debug("Batch Response item:\n{}", resItem);
});
String results = BatchPayloadGenerator.generate(batchResponseItems,
JAXRSService.DOUBLE_DASH + boundary);