Skip to content

Commit

Permalink
Revert "#451 - start implement Copy"
Browse files Browse the repository at this point in the history
This reverts commit ca8e682.
  • Loading branch information
Almeida Stenio committed Sep 25, 2024
1 parent c44599e commit 110c4af
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -240,9 +239,7 @@ private Future<String> extractDelegateExecutionRequestJsonPayload(HttpServerRequ
private Future<Buffer> generatePayload(String delegateExecutionRequestJsonPayload, MultiMap headers, DelegateRequest requestContainer, final Matcher matcher) {
Promise<Buffer> promise = Promise.promise();

if (requestContainer.isCopy()) {
promise.complete(Buffer.buffer(delegateExecutionRequestJsonPayload));
} else if (requestContainer.getJoltSpec() != null) {
if (requestContainer.getJoltSpec() != null) {
try {
if (delegateExecutionRequestJsonPayload != null) {

Expand Down Expand Up @@ -272,7 +269,7 @@ private Future<Buffer> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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<String, Object> properties,
final String delegatesSchema, @Nullable StatusCode unmatchedDelegateStatusCode) {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
* delegate.<br>
* <code>PUT /gateleen/server/delegate/v1/delegates/user-zip-copy/definition</code>
* <pre>
{
"methods": [ "PUT", "DELETE" ],
"pattern": "([^/]*)/(.*)",
"requests": [
{
"headers" : [],
"uri": "/gateleen/server/copy",
"method": "POST",
"payload": {
"source": "/gateleen/$1?expand=100&amp;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&amp;zip=true",
"destination": "/gateleen/zips/users/$1.zip"
}
}
]
}
* </pre>
* To trigger an execution, it suffice to perform a PUT request on the virtual collection <code>execution</code> within
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -34,8 +32,4 @@ public JoltSpec getJoltSpec() {
public HeaderFunction getHeaderFunction() {
return headerFunction;
}

public boolean isCopy() {
return copy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]}
]
},
{
Expand All @@ -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",
Expand Down

0 comments on commit 110c4af

Please sign in to comment.