Skip to content

Commit 7c8d39f

Browse files
authored
Merge pull request #137 from adobe/updating-docs
Updating docs
2 parents d74d772 + 29d9159 commit 7c8d39f

File tree

3 files changed

+187
-43
lines changed

3 files changed

+187
-43
lines changed

README.md

Lines changed: 183 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ from any language or framework you are in.
1111
## Table of Contents
1212

1313
<!-- TOC -->
14-
* [BridgeService](#bridgeservice)
15-
* [PhasedTesting](#phasedtesting)
1614
* [Table of Contents](#table-of-contents)
1715
* [Release Notes](#release-notes)
1816
* [Implementing The Bridge Service in Your Project](#implementing-the-bridge-service-in-your-project)
@@ -26,14 +24,20 @@ from any language or framework you are in.
2624
* [Setting Information About your Environment](#setting-information-about-your-environment)
2725
* [Testing That all is Working](#testing-that-all-is-working)
2826
* [Testing That all External Devices can be Accessed](#testing-that-all-external-devices-can-be-accessed)
29-
* [Making a basic Java Call](#making-a-basic-java-call)
30-
* [Instantiating Objects](#instantiating-objects)
27+
* [Making Java Calls](#making-java-calls)
28+
* [A basic Java Call](#a-basic-java-call)
29+
* [Instantiating Objects](#instantiating-objects)
30+
* [Call Chaining a basic Java Call](#call-chaining-a-basic-java-call)
31+
* [Call Chaining and Call Dependencies](#call-chaining-and-call-dependencies)
32+
* [Call Chaining and Instance Methods](#call-chaining-and-instance-methods)
33+
* [Argument Types](#argument-types)
34+
* [Simple Java Objects](#simple-java-objects)
35+
* [Lists and Arrays](#lists-and-arrays)
36+
* [Complex Types](#complex-types)
37+
* [Files](#files)
3138
* [Managing Timeouts](#managing-timeouts)
3239
* [Setting Timeout Globally](#setting-timeout-globally)
3340
* [Setting a Timeout for the Call Session](#setting-a-timeout-for-the-call-session)
34-
* [Call Chaining a basic Java Call](#call-chaining-a-basic-java-call)
35-
* [Call Chaining and Call Dependencies](#call-chaining-and-call-dependencies)
36-
* [Call Chaining and Instance Methods](#call-chaining-and-instance-methods)
3741
* [Creating a Call Context](#creating-a-call-context)
3842
* [Static Variable Scopes](#static-variable-scopes)
3943
* [Session Scopes](#session-scopes)
@@ -42,7 +46,7 @@ from any language or framework you are in.
4246
* [Secrets](#secrets)
4347
* [Steamlining Headers](#steamlining-headers)
4448
* [Making Assertions](#making-assertions)
45-
* [Duration-based Assertions](#duration-based-assertions)
49+
* [Duration-Based Assertions](#duration-based-assertions)
4650
* [Error Management](#error-management)
4751
* [Contribution](#contribution)
4852
* [Known Errors](#known-errors)
@@ -190,6 +194,7 @@ The payload returns a JSON with the test results:
190194
In the example above "<URL ID 2>" is marked as false because it can not be accessed from the BridgeService.
191195

192196
## Making Java Calls
197+
193198
### A basic Java Call
194199

195200
The simplest java call is done in the following way:
@@ -224,6 +229,36 @@ a 'returnValues' object.
224229
}
225230
```
226231

232+
Here is an example for the POST call `http://localhost:8080/call` and the payload:
233+
234+
```JSON
235+
{
236+
"callContent": {
237+
"fetchString1": {
238+
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
239+
"method": "methodAcceptingStringArgument",
240+
"args": [
241+
"REAL"
242+
]
243+
}
244+
}
245+
}
246+
```
247+
248+
`SimpleStaticMethods.methodAcceptingStringArgument` accepts a string argument and concatenates the given argument
249+
with `_SUCCESS`. The call will return the following result:
250+
251+
```JSON
252+
{
253+
"callDurations": {
254+
"fetchString1": 7
255+
},
256+
"returnValues": {
257+
"fetchString1": "REAL_Success"
258+
}
259+
}
260+
```
261+
227262
### Instantiating Objects
228263

229264
If we do not specify a method, the bridge service assumes that we are instantiating the given class:
@@ -319,6 +354,49 @@ In the example above "ID-2" will use the return value of the call "ID-1" as ts f
319354
**NOTE** : When passing a call result as an argument, it needs to be a String. In many languages such as JavaScript, the
320355
JSON keys need not be a string, however, for this to work you need to pass the ID as a string.
321356

357+
Here is an example of for a call chaining:
358+
359+
```JSON
360+
{
361+
"callContent": {
362+
"fetchStringsList": {
363+
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
364+
"method": "methodReturningList",
365+
"args": []
366+
},
367+
"fetchSubjects": {
368+
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
369+
"method": "methodAcceptingListArguments",
370+
"args": [
371+
"fetchStringsList"
372+
]
373+
}
374+
}
375+
}
376+
```
377+
378+
`methodReturningList` returns a list of Strings. `methodAcceptingListArguments` accepts a list and returns its size. As
379+
you can see we have passed the identity of the first call, `fetchStringsList` to the second one `fetchSubjects`. Here
380+
is the return payload:
381+
382+
```JSON
383+
{
384+
"callDurations": {
385+
"fetchStringsList": 5,
386+
"fetchSubjects": 1
387+
},
388+
"returnValues": {
389+
"fetchStringsList": [
390+
"NA1",
391+
"NA2",
392+
"NA3",
393+
"NA4"
394+
],
395+
"fetchSubjects": 4
396+
}
397+
}
398+
```
399+
322400
#### Call Chaining and Instance Methods
323401

324402
We now have the possibility of injecting call results from one call to the other. In the example below we instantiate an
@@ -349,19 +427,66 @@ the `instance` value for the following call.
349427
In the example above "ID-2" will use call the instance method of the object created in call "ID-1".
350428

351429
### Argument Types
430+
352431
Since we are using JSON to pass values to the method, we need to cover how different types are passed.
353432

354433
#### Simple Java Objects
434+
355435
The internal Java objects such as int, String and boolean can be passed with no problems
356436

357437
#### Lists and Arrays
358-
List and Arrays can be passed as JSONArrays. IBS will transform them to the target argument when needed (_Available since 2.116_).
438+
439+
List and Arrays can be passed as JSONArrays. IBS will transform them to the target argument when needed (_Available
440+
since 2.116_).
359441

360442
#### Complex Types
361-
Some methods require complex Objects as arguments. In this case you need to have a constructor/factory call in one call, and pass they key as an argument.
443+
444+
Some methods require complex Objects as arguments. In this case you need to have a constructor/factory call in one call,
445+
and pass they key as an argument.
362446

363447
#### Files
364-
As of version 2.11.16 we have the possibility to pass a file to the bridgeService. When doing so, you need to send your request as a multi-part request. As in most multi-part requests, you need to give each uploaded file a key value. In that case the file is referenced with that key value.
448+
449+
As of version 2.11.16 we have the possibility to pass a file to the bridgeService. When doing so, you need to send your
450+
request as a multi-part request. As in most multi-part requests, you need to give each uploaded file a key value. In
451+
that case the file is referenced with that key value.
452+
453+
Below is an example using curl (_executed from the project root_). We are uploading the file `integroBridgeService/src/test/resources/uploadFiles/testaRosa.txt` with the id `uploaded_file`, like in call chaining we have passed this id to the method call `fileReader`, whose job is to return the file contents.
454+
455+
```shell
456+
curl --request POST \
457+
--url http://localhost:8080/call \
458+
--header 'Content-Type: multipart/form-data' \
459+
--form 'jsonbody={
460+
"assertions": {},
461+
"timeout": 10000,
462+
"callContent": {
463+
"fileReader": {
464+
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
465+
"method": "methodAcceptingFile",
466+
"args": [
467+
"uploaded_file"
468+
]
469+
470+
}
471+
},
472+
"environmentVariables": {}
473+
}' \
474+
--form uploaded_file=@integroBridgeService/src/test/resources/uploadFiles/testaRosa.txt
475+
476+
```
477+
478+
The result is then:
479+
480+
```JSON
481+
{
482+
"callDurations": {
483+
"call1PL": 7
484+
},
485+
"returnValues": {
486+
"fileReader": "Hello World"
487+
}
488+
}
489+
```
365490

366491
## Managing Timeouts
367492

@@ -470,29 +595,26 @@ All you need to do is to reference your header name in the `args` section.
470595

471596
Example:
472597

473-
```
474-
POST /api/call HTTP/1.1
475-
ibs-header-var1: MyValue
476-
```
477-
478-
```JSON
479-
{
480-
"callContent": {
481-
"fetchString1": {
482-
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
483-
"method": "methodAcceptingStringArgument",
484-
"args": [
485-
"ibs-header-var1"
486-
]
487-
}
488-
}
489-
}
598+
```shell
599+
curl --request POST \
600+
--url http://localhost:8080/call \
601+
--header 'Content-Type: application/json' \
602+
--header 'ibs-header-var1: MyValue' \
603+
--data '{
604+
"callContent": {
605+
"fetchHeader": {
606+
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
607+
"method": "methodAcceptingStringArgument",
608+
"args": [
609+
"ibs-header-var1"
610+
]
611+
}
612+
}
613+
}'
490614
```
491615

492616
In the call above we pass `MyValue` with the key `ibs-header-var1` as a header. Our payload will fetch the value in
493-
the `args`section.
494-
495-
The call will return :
617+
the `args`section. The call will return :
496618

497619
```JSON
498620
{
@@ -505,7 +627,36 @@ The call will return :
505627
}
506628
```
507629

508-
As mentioned earlier, if `MyValue` were to be passed as a secret (with a prefix `ibs-secret-`), we would be getting an exception:
630+
### Secrets
631+
632+
Secrets allow you to have an extra level of security. This will mean that we will not allow you to print the secret in
633+
the output.
634+
635+
A secret sent to the IBS will have to be prefixed with `ibs-secret-`. This can be overridden by setting the run-time
636+
variable `IBS.SECRETS.FILTER.PREFIX`.
637+
638+
In the example earlier, if `MyValue` were to be passed as a secret (with a prefix `ibs-secret-`), we would be getting an
639+
exception:
640+
641+
```shell
642+
curl --request POST \
643+
--url http://localhost:8080/call \
644+
--header 'Content-Type: application/json' \
645+
--header 'ibs-header-var1: MyValue' \
646+
--data '{
647+
"callContent": {
648+
"fetchHeader": {
649+
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
650+
"method": "methodAcceptingStringArgument",
651+
"args": [
652+
"ibs-secret-var1"
653+
]
654+
}
655+
}
656+
}'
657+
```
658+
Below is the exception we will get:
659+
509660
```JSON
510661
{
511662
"title": "We detected an inconsistency in your payload.",
@@ -515,14 +666,6 @@ As mentioned earlier, if `MyValue` were to be passed as a secret (with a prefix
515666
}
516667
```
517668

518-
### Secrets
519-
520-
Secrets allow you to have an extra level of security. This will mean that we will not allow you to print the secret in
521-
the output.
522-
523-
A secret sent to the IBS will have to be prefixed with `ibs-secret-`. This can be overridden by setting the run-time
524-
variable `IBS.SECRETS.FILTER.PREFIX`.
525-
526669
Sometimes you may want to debug the system. In these cases you can deactivate the output check by setting run-time
527670
variable `IBS.SECRETS.BLOCK.OUTPUT` to false. However, this should only be temporary, and in production it is best to
528671
keep this control.

integroBridgeService/src/main/java/com/adobe/campaign/tests/bridge/service/IntegroAPI.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class IntegroAPI {
4848
protected static final String ERROR_JAVA_OBJECT_NOT_ACCESSIBLE = "The java object you want to call is inaccessible. This is very possibly a scope problem.";
4949
private static final Logger log = LogManager.getLogger();
5050
public static final String ERROR_BAD_MULTI_PART_REQUEST = "When sending a multi-part request, you need to at least have a payload for the callContent.";
51+
public static final String STD_UPLOAD_DIR = "upload";
5152

5253
public static void startServices(int port) {
5354

@@ -88,13 +89,13 @@ public static void startServices(int port) {
8889
return BridgeServiceFactory.transformServiceAccessResult(
8990
l_serviceAccess.checkAccessibilityOfExternalResources());
9091
});
91-
File uploadDir = new File("upload");
92+
93+
File uploadDir = new File(STD_UPLOAD_DIR);
9294
uploadDir.mkdir(); // create the upload directory if it doesn't exist
9395
//staticFiles.externalLocation("upload");
9496

9597
post("/call", (req, res) -> {
9698

97-
9899
boolean isMultiPart = false;
99100
JavaCalls fetchedFromJSON;
100101

integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ public void testCallWithFileUpload_XML() throws IOException {
910910
post(EndPointURL + "call").then().assertThat().body("returnValues.call1PL",
911911
Matchers.equalTo(fileContent));
912912

913-
File uploadDir = new File("upload");
913+
File uploadDir = new File(IntegroAPI.STD_UPLOAD_DIR);
914914
Arrays.stream(uploadDir.list()).forEach(System.out::println);
915915
assertThat("The directory should be empty", uploadDir.list().length, Matchers.equalTo(0));
916916
}

0 commit comments

Comments
 (0)