You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2020/05/14 15:33:47 UTC
[syncope] branch 2_1_X updated: Utility methods in BatchResponse
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 d999e3f Utility methods in BatchResponse
d999e3f is described below
commit d999e3f40959738c8f7e109ac3aabc33db930cd8
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Thu May 14 17:32:05 2020 +0200
Utility methods in BatchResponse
---
.../client/console/widgets/JobActionPanel.java | 1 -
.../syncope/client/lib/batch/BatchResponse.java | 75 ++++++++++++++++------
2 files changed, 55 insertions(+), 21 deletions(-)
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobActionPanel.java b/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobActionPanel.java
index c59a93b..34993ba 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobActionPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/widgets/JobActionPanel.java
@@ -158,6 +158,5 @@ public class JobActionPanel extends WizardMgtPanel<Serializable> {
public AjaxRequestTarget getTarget() {
return target;
}
-
}
}
diff --git a/client/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchResponse.java b/client/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchResponse.java
index 5b6ee8b..90882d3 100644
--- a/client/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchResponse.java
+++ b/client/lib/src/main/java/org/apache/syncope/client/lib/batch/BatchResponse.java
@@ -44,6 +44,51 @@ public class BatchResponse {
private static final Logger LOG = LoggerFactory.getLogger(BatchResponse.class);
+ /**
+ * If asynchronous processing was requested, queries the monitor URI.
+ *
+ * @param monitor monitor URI
+ * @param jwt authorization JWT
+ * @param boundary mutipart / mixed boundary
+ * @param tlsClientParameters (optional) TLS client parameters
+ *
+ * @return the last Response received from the Batch service
+ */
+ public static Response poll(
+ final URI monitor,
+ final String jwt,
+ final String boundary,
+ final TLSClientParameters tlsClientParameters) {
+
+ WebClient webClient = WebClient.create(monitor).
+ header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt).
+ type(RESTHeaders.multipartMixedWith(boundary.substring(2)));
+ if (tlsClientParameters != null) {
+ ClientConfiguration config = WebClient.getConfig(webClient);
+ HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
+ httpConduit.setTlsClientParameters(tlsClientParameters);
+ }
+
+ return webClient.get();
+ }
+
+ /**
+ * Parses the given Response into a list of {@link BatchResponseItem}s.
+ *
+ * @param response response to extract items from
+ * @return the Batch Response parsed as list of {@link BatchResponseItem}s
+ * @throws IOException if there are issues when reading the response body
+ */
+ public static List<BatchResponseItem> getItems(final Response response) throws IOException {
+ String body = IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8.name());
+ LOG.debug("Batch response body:\n{}", body);
+
+ return BatchPayloadParser.parse(
+ new ByteArrayInputStream(body.getBytes()),
+ response.getMediaType(),
+ new BatchResponseItem());
+ }
+
private final String boundary;
private final String jwt;
@@ -67,6 +112,14 @@ public class BatchResponse {
this.response = response;
}
+ public String getBoundary() {
+ return boundary;
+ }
+
+ public URI getMonitor() {
+ return monitor;
+ }
+
/**
* Gives the last Response received from the Batch service.
*
@@ -82,19 +135,7 @@ public class BatchResponse {
* @return the last Response received from the Batch service
*/
public Response poll() {
- if (monitor != null) {
- WebClient webClient = WebClient.create(monitor).
- header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt).
- type(RESTHeaders.multipartMixedWith(boundary.substring(2)));
- if (tlsClientParameters != null) {
- ClientConfiguration config = WebClient.getConfig(webClient);
- HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
- httpConduit.setTlsClientParameters(tlsClientParameters);
- }
-
- response = webClient.get();
- }
-
+ response = poll(monitor, jwt, boundary, tlsClientParameters);
return response;
}
@@ -105,12 +146,6 @@ public class BatchResponse {
* @throws IOException if there are issues when reading the response body
*/
public List<BatchResponseItem> getItems() throws IOException {
- String body = IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8.name());
- LOG.debug("Batch response body:\n{}", body);
-
- return BatchPayloadParser.parse(
- new ByteArrayInputStream(body.getBytes()),
- response.getMediaType(),
- new BatchResponseItem());
+ return getItems(response);
}
}