From 110c4afc61c43adc2a960d6e87a00d8e5bf9cf38 Mon Sep 17 00:00:00 2001 From: Almeida Stenio Date: Wed, 25 Sep 2024 16:41:56 +0100 Subject: [PATCH] Revert "#451 - start implement Copy" This reverts commit ca8e682ae6c3212e863df617b79872596d38679c. --- .../swisspush/gateleen/delegate/Delegate.java | 7 +- .../gateleen/delegate/DelegateFactory.java | 28 ++++-- .../gateleen/delegate/DelegateHandler.java | 30 +++---- .../gateleen/delegate/DelegateRequest.java | 8 +- .../gateleen_delegate_schema_delegates | 87 +++++++++---------- 5 files changed, 79 insertions(+), 81 deletions(-) diff --git a/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/Delegate.java b/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/Delegate.java index baf45d508..f1aa6cc52 100644 --- a/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/Delegate.java +++ b/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/Delegate.java @@ -36,7 +36,6 @@ public class Delegate { private static final String PAYLOAD = "payload"; private static final String URI = "uri"; private static final String METHOD = "method"; - private static final String COPY = "copy"; private static final int FIRST = 0; private static final int STATUS_CODE_2XX = 2; @@ -240,9 +239,7 @@ private Future extractDelegateExecutionRequestJsonPayload(HttpServerRequ private Future generatePayload(String delegateExecutionRequestJsonPayload, MultiMap headers, DelegateRequest requestContainer, final Matcher matcher) { Promise promise = Promise.promise(); - if (requestContainer.isCopy()) { - promise.complete(Buffer.buffer(delegateExecutionRequestJsonPayload)); - } else if (requestContainer.getJoltSpec() != null) { + if (requestContainer.getJoltSpec() != null) { try { if (delegateExecutionRequestJsonPayload != null) { @@ -272,7 +269,7 @@ private Future generatePayload(String delegateExecutionRequestJsonPayloa } else { // matcher to replace wildcards with matching groups final JsonObject requestObject = requestContainer.getRequest(); - // get the string representation of the payload object + // get the string represantion of the payload object String payloadStr; payloadStr = requestObject.getJsonObject(PAYLOAD).encode(); diff --git a/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateFactory.java b/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateFactory.java index 70bce068d..966ac2d5f 100644 --- a/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateFactory.java +++ b/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateFactory.java @@ -24,6 +24,8 @@ /** * DelegateFactory is used to create delegate objects from their text representation. + * + * @author https://github.com/ljucam [Mario Ljuca] */ public class DelegateFactory { private static final Logger LOG = LoggerFactory.getLogger(DelegateFactory.class); @@ -34,7 +36,6 @@ public class DelegateFactory { private static final String DYNAMIC_HEADERS = "dynamicHeaders"; private static final String TRANSFORM = "transform"; private static final String TRANSFORM_WITH_METADATA = "transformWithMetadata"; - private static final String COPY = "copy"; private final ClientRequestCreator clientRequestCreator; @@ -45,6 +46,11 @@ public class DelegateFactory { /** * Creates a new instance of the DelegateFactory. + * + * @param clientRequestCreator + * @param properties + * @param delegatesSchema + * @param unmatchedDelegateStatusCode */ public DelegateFactory(final ClientRequestCreator clientRequestCreator, final Map properties, final String delegatesSchema, @Nullable StatusCode unmatchedDelegateStatusCode) { @@ -55,7 +61,12 @@ public DelegateFactory(final ClientRequestCreator clientRequestCreator, final Ma } /** - * Tries to create a Delegate object out of the buffer. + * Tries to create a Delegate object out of the + * buffer. + * + * @param delegateName name of the delegate + * @param buffer buffer of the delegate + * @return a Delegate object */ public Delegate parseDelegate(final String delegateName, final Buffer buffer) throws ValidationException { final String configString; @@ -79,6 +90,11 @@ public Delegate parseDelegate(final String delegateName, final Buffer buffer) th /** * Create the delegate out of the prepared string. + * + * @param delegateName name of the delegate + * @param configString the string rep. of the delegate + * @return the new delegate + * @throws ValidationException */ private Delegate createDelegate(final String delegateName, final String configString) throws ValidationException { JsonObject delegateObject = new JsonObject(configString); @@ -103,11 +119,7 @@ private Delegate createDelegate(final String delegateName, final String configSt LOG.trace("request of [{}] #: {}", delegateName, i); } JsonObject requestJsonObject = (JsonObject) delegateObject.getJsonArray(REQUESTS).getValue(i); - boolean copy = requestJsonObject.getBoolean(COPY, false); - JoltSpec joltSpec = null; - if (!copy) { - joltSpec = parsePayloadTransformSpec(requestJsonObject, delegateName); - } + JoltSpec joltSpec = parsePayloadTransformSpec(requestJsonObject, delegateName); HeaderFunction headerFunction; final JsonArray headerFunctionsArray = requestJsonObject.getJsonArray(DYNAMIC_HEADERS); @@ -117,7 +129,7 @@ private Delegate createDelegate(final String delegateName, final String configSt headerFunction = HeaderFunctions.DO_NOTHING; } - requests.add(new DelegateRequest(requestJsonObject, joltSpec, headerFunction, copy)); + requests.add(new DelegateRequest(requestJsonObject, joltSpec, headerFunction)); } return new Delegate(clientRequestCreator, delegateName, pattern, methods, requests, unmatchedDelegateStatusCode); diff --git a/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateHandler.java b/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateHandler.java index ca76fb699..9ed410f65 100644 --- a/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateHandler.java +++ b/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateHandler.java @@ -33,21 +33,21 @@ * delegate.
* PUT /gateleen/server/delegate/v1/delegates/user-zip-copy/definition *
- {
- "methods": [ "PUT", "DELETE" ],
- "pattern": "([^/]*)/(.*)",
- "requests": [
- {
- "headers" : [],
- "uri": "/gateleen/server/copy",
- "method": "POST",
- "payload": {
- "source": "/gateleen/$1?expand=100&zip=true",
- "destination": "/gateleen/zips/users/$1.zip"
- }
- }
- ]
- }
+    {
+        "methods": [ "PUT", "DELETE" ],
+        "pattern": "([^/]*)/(.*)",
+        "requests": [
+            {
+                 "headers" : [],
+                 "uri": "/gateleen/server/copy",
+                 "method": "POST",
+                 "payload": {
+                    "source": "/gateleen/$1?expand=100&zip=true",
+                    "destination": "/gateleen/zips/users/$1.zip"
+                }
+            }
+        ]
+    }
 
  * 
* To trigger an execution, it suffice to perform a PUT request on the virtual collection execution within diff --git a/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateRequest.java b/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateRequest.java index 08a20f44b..66ff0b219 100644 --- a/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateRequest.java +++ b/gateleen-delegate/src/main/java/org/swisspush/gateleen/delegate/DelegateRequest.java @@ -14,13 +14,11 @@ public class DelegateRequest { private final JsonObject request; private final JoltSpec joltSpec; private final HeaderFunction headerFunction; - private final boolean copy; - public DelegateRequest(JsonObject request, JoltSpec joltSpec, HeaderFunction headerFunction, boolean copy) { + public DelegateRequest(JsonObject request, JoltSpec joltSpec, HeaderFunction headerFunction) { this.request = request; this.joltSpec = joltSpec; this.headerFunction = headerFunction; - this.copy = copy; } public JsonObject getRequest() { @@ -34,8 +32,4 @@ public JoltSpec getJoltSpec() { public HeaderFunction getHeaderFunction() { return headerFunction; } - - public boolean isCopy() { - return copy; - } } diff --git a/gateleen-delegate/src/main/resources/gateleen_delegate_schema_delegates b/gateleen-delegate/src/main/resources/gateleen_delegate_schema_delegates index 4f348f394..14f061048 100644 --- a/gateleen-delegate/src/main/resources/gateleen_delegate_schema_delegates +++ b/gateleen-delegate/src/main/resources/gateleen_delegate_schema_delegates @@ -4,7 +4,7 @@ "type": "object", "properties": { "methods": { - "description": "Restricts the HTTP methods concerned by this rule (`GET`, `PUT`, `POST`, `DELETE`). When absent, all methods are concerned.", + "description": "Restricts the HTTP methods concerned by this rule (`GET`, `PUT`, `POST`, `DELETE`).\nWhen absent, all methods are concerned.", "type": "array", "items": { "type": "string" @@ -19,56 +19,55 @@ "type": "string" }, "pattern": { - "description": "Pattern for grouping the incoming URI", + "description": "Pattern for grouping the incoming uri", "type": "string" }, "requests": { "type": "array", - "items": { "$ref": "#/definitions/Request" } + "items": {"$ref": "#/definitions/Request"} } }, "additionalProperties": false, "definitions": { "HeaderFunction": { - "properties": { - "header": { - "description": "The request-header name to manipulate (set, remove or conditional set)", - "type": "string", - "minLength": 1 - }, - "value": { - "description": "The value to be set. Null and empty string means 'remove the header'. Value can contain other header names between single angular brackets which resolves to their values accordingly", - "type": [ - "null", - "string" - ] + "properties": { + "header": { + "description": "the request-header name to manipulate (set, remove or conditional set)", + "type": "string", + "minLength": 1 + }, + "value": { + "description": "the value to be set. null and empty string means 'remove the header'. value can contain other header names between single angular brackets which resolves to their values accordingly", + "type": [ + "null", + "string" + ] + }, + "mode": { + "description": "define a condition-mode. 'complete' sets the header value only if this header is not yet present. 'overwrite' sets the header value only if the header is already present. Ignored if value is null or empty string", + "type": "string", + "enum": [ + "complete", + "override" + ] + } }, - "mode": { - "description": "Define a condition-mode. 'complete' sets the header value only if this header is not yet present. 'overwrite' sets the header value only if the header is already present. Ignored if value is null or empty string", - "type": "string", - "enum": [ - "complete", - "override" - ] - } - }, - "required": [ - "header", - "value" - ] + "required": [ + "header", + "value" + ] }, "Request": { "oneOf": [ { "required": ["payload"] }, { "required": ["transform"] }, - { "required": ["transformWithMetadata"] }, - { "required": ["copy"] } + { "required": ["transformWithMetadata"] } ], "anyOf": [ { "oneOf": [ - { "required": ["dynamicHeaders"] }, - { "required": ["headers"] } + {"required": ["dynamicHeaders"]}, + {"required": ["headers"]} ] }, { @@ -92,28 +91,24 @@ ] }, "payload": { - "description": "The payload to send in the request's body", + "description": "The payload to send in requests body", "type": "object" }, "transform": { - "description": "The JOLT spec definition to transform the payload", + "description": "The jolt spec definition to transform the payload", "type": "array" }, "transformWithMetadata": { - "description": "The JOLT spec definition to transform the payload and additional metadata", + "description": "The jolt spec definition to transform the payload and additional metadata", "type": "array" }, - "copy": { - "description": "Indicates that the original payload should be copied to the new destination", - "type": "boolean" - }, - "dynamicHeaders": { - "description": "Manipulate (set / remove / replace) request headers using HeaderFunctions - option to reference other header values", - "type": "array", - "items": { - "$ref": "#/definitions/HeaderFunction" - } - }, + "dynamicHeaders": { + "description": "Manipulate (set / remove / replace) request headers using HeaderFunctions - option to reference other header vales", + "type": "array", + "items": { + "$ref": "#/definitions/HeaderFunction" + } + }, "headers": { "description": "Headers to send with the request", "type": "array",