Skip to content

Commit d74d772

Browse files
authored
Merge pull request #136 from adobe/110-allow-file-uploading-of-arguments
110 allow file uploading and the usage of files asarguments
2 parents 144d603 + 5cafb66 commit d74d772

File tree

14 files changed

+407
-110
lines changed

14 files changed

+407
-110
lines changed

README.md

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# BridgeService
22

3-
# PhasedTesting
4-
53
[![unit-tests](https://github.com/adobe/bridgeService/actions/workflows/onPushSimpleTest.yml/badge.svg)](https://github.com/adobe/bridgeService/actions/workflows/onPushSimpleTest.yml)
64
[![codecov](https://codecov.io/gh/adobe/bridgeService/branch/main/graph/badge.svg?token=GSi0gUlqq5)](https://codecov.io/gh/adobe/bridgeService)
75
[![javadoc](https://javadoc.io/badge2/com.adobe.campaign.tests.bridge.service/integroBridgeService/javadoc.svg)](https://javadoc.io/doc/com.adobe.campaign.tests.bridge.service/integroBridgeService)
@@ -191,7 +189,8 @@ The payload returns a JSON with the test results:
191189

192190
In the example above "<URL ID 2>" is marked as false because it can not be accessed from the BridgeService.
193191

194-
## Making a basic Java Call
192+
## Making Java Calls
193+
### A basic Java Call
195194

196195
The simplest java call is done in the following way:
197196
```/call```
@@ -225,7 +224,7 @@ a 'returnValues' object.
225224
}
226225
```
227226

228-
## Instantiating Objects
227+
### Instantiating Objects
229228

230229
If we do not specify a method, the bridge service assumes that we are instantiating the given class:
231230

@@ -246,47 +245,7 @@ If we do not specify a method, the bridge service assumes that we are instantiat
246245
**Note :** You can also set the method name to the class name, but it may be easier to simply skip setting a method name
247246
in this case.
248247

249-
## Managing Timeouts
250-
251-
As of version 2.11.6 we now introduce the notion of timeouts. This means that after a declared time a call will be
252-
interrupted. Setting this value can be done at two levels:
253-
254-
* The deployment level
255-
* The Call session
256-
257-
**Note :** If set to 0, there is no timeout.
258-
259-
### Setting Timeout Globally
260-
261-
You can set a default value when starting the service. This is done by setting the environment
262-
variable `IBS.TIMEOUT.DEFAULT`. If not set, the default value is 10000ms.
263-
264-
### Setting a Timeout for the Call Session
265-
266-
We can also set the Timeout for a java call transaction. In that case the value you pass overrides the global value, but
267-
only for you session. If the `timeout` is not test in the payload at the next call, the global value will be used.
268-
269-
In the example below the method `methodWithTimeOut` waits for the provided, in this case 800ms, amount of time. In the
270-
example below the test will pass because we wait for 800ms, and the timeout is 1000s.
271-
272-
```JSON
273-
{
274-
"callContent": {
275-
"call1": {
276-
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
277-
"method": "methodWithTimeOut",
278-
"args": [
279-
800
280-
]
281-
}
282-
},
283-
"timeout": 1000
284-
}
285-
```
286-
287-
If the payload above would have a timeout below 800ms, the call will fail.
288-
289-
## Call Chaining a basic Java Call
248+
### Call Chaining a basic Java Call
290249

291250
We can chain a series of java calls in the same payload:
292251

@@ -360,7 +319,7 @@ In the example above "ID-2" will use the return value of the call "ID-1" as ts f
360319
**NOTE** : When passing a call result as an argument, it needs to be a String. In many languages such as JavaScript, the
361320
JSON keys need not be a string, however, for this to work you need to pass the ID as a string.
362321

363-
### Call Chaining and Instance Methods
322+
#### Call Chaining and Instance Methods
364323

365324
We now have the possibility of injecting call results from one call to the other. In the example below we instantiate an
366325
object, and in the following call we call a method of that object. This is done by passing the ID of the first call as
@@ -389,6 +348,61 @@ the `instance` value for the following call.
389348

390349
In the example above "ID-2" will use call the instance method of the object created in call "ID-1".
391350

351+
### Argument Types
352+
Since we are using JSON to pass values to the method, we need to cover how different types are passed.
353+
354+
#### Simple Java Objects
355+
The internal Java objects such as int, String and boolean can be passed with no problems
356+
357+
#### 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_).
359+
360+
#### 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.
362+
363+
#### 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.
365+
366+
## Managing Timeouts
367+
368+
As of version 2.11.6 we now introduce the notion of timeouts. This means that after a declared time a call will be
369+
interrupted. Setting this value can be done at two levels:
370+
371+
* The deployment level
372+
* The Call session
373+
374+
**Note :** If set to 0, there is no timeout.
375+
376+
### Setting Timeout Globally
377+
378+
You can set a default value when starting the service. This is done by setting the environment
379+
variable `IBS.TIMEOUT.DEFAULT`. If not set, the default value is 10000ms.
380+
381+
### Setting a Timeout for the Call Session
382+
383+
We can also set the Timeout for a java call transaction. In that case the value you pass overrides the global value, but
384+
only for you session. If the `timeout` is not test in the payload at the next call, the global value will be used.
385+
386+
In the example below the method `methodWithTimeOut` waits for the provided, in this case 800ms, amount of time. In the
387+
example below the test will pass because we wait for 800ms, and the timeout is 1000s.
388+
389+
```JSON
390+
{
391+
"callContent": {
392+
"call1": {
393+
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
394+
"method": "methodWithTimeOut",
395+
"args": [
396+
800
397+
]
398+
}
399+
},
400+
"timeout": 1000
401+
}
402+
```
403+
404+
If the payload above would have a timeout below 800ms, the call will fail.
405+
392406
## Creating a Call Context
393407

394408
We sometimes need to set environment variables when making calls. This is usually indirectly related to the call you are
@@ -599,7 +613,7 @@ behavior or this. Currently, assertions are of two types:
599613
* Result Based,
600614
* Duration Based
601615

602-
### Duration-based Assertions
616+
### Duration-Based Assertions
603617

604618
As mentioned earlier an assertion can be duration based. In that case, IBS will consider the call duration of a call for
605619
the assertion. In order to perform an assertion the payload needs to include the entry `"type": "DURATION"` to the

ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
## 2.11.16-SNAPSHOT
44
* **New Feature** [#3 Include an Assertion Feature](https://github.com/adobe/bridgeService/issues/3). We have now included the possibility for users to define assertions. This allows you to clarify accepted results for the call you make with the IBS.
55
* **New Feature** [#79 Allow or passing secrets in headers](https://github.com/adobe/bridgeService/issues/79). You can now pass variables and secrets as headers.
6+
* **New Feature** [#110 Allow for Fileuploading and Multi-part requests](https://github.com/adobe/bridgeService/issues/100). We can now upload a file and reference it in the request.
67
* [#111 Allowing the passing of array and vararg arguments](https://github.com/adobe/bridgeService/issues/111). Previously we were unable to execute methods accepting Arrays and varargs. This has now been corrected.
78
* [#88 Logging action steps](https://github.com/adobe/bridgeService/issues/88). We now log the steps we take during execution for better debugging.
9+
* [#48 Logging action steps](https://github.com/adobe/bridgeService/issues/48). We now log the current class and method being executed.
810

911
## 2.11.15
1012
* [#71 Adding step name when throwing exceptions](https://github.com/adobe/bridgeService/issues/71). When an exception happens, include the step in which it occurred.

bridgeService-data/pom.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
<artifactId>log4j-api</artifactId>
3131
<version>2.23.1</version>
3232
</dependency>
33-
<!--
3433
<dependency>
35-
<groupId>com.googlecode.json-simple</groupId>
36-
<artifactId>json-simple</artifactId>
37-
<version>1.1.1</version>
34+
<groupId>com.sun.mail</groupId>
35+
<artifactId>javax.mail</artifactId>
36+
<version>1.6.2</version>
3837
</dependency>
39-
-->
4038
<dependency>
4139
<groupId>com.google.code.gson</groupId>
4240
<artifactId>gson</artifactId>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2022 Adobe
3+
* All Rights Reserved.
4+
*
5+
* NOTICE: Adobe permits you to use, modify, and distribute this file in
6+
* accordance with the terms of the Adobe license agreement accompanying
7+
* it.
8+
*/
9+
package com.adobe.campaign.tests.bridge.testdata.one;
10+
11+
import javax.mail.Message;
12+
import javax.mail.MessagingException;
13+
import javax.mail.Session;
14+
import javax.mail.internet.InternetAddress;
15+
import javax.mail.internet.MimeMessage;
16+
import java.util.ArrayList;
17+
import java.util.Arrays;
18+
import java.util.List;
19+
import java.util.stream.Collectors;
20+
21+
public class MimeMessageMethods {
22+
public static MimeMessage createMessage(String in_suffix) throws MessagingException {
23+
24+
String from = "[email protected]";
25+
MimeMessage message = new MimeMessage((Session) null);
26+
message.setFrom(new InternetAddress(from));
27+
message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
28+
message.setSubject("a subject by me " + in_suffix);
29+
message.setText("a content by yours truely " + in_suffix);
30+
return message;
31+
}
32+
33+
public static List<MimeMessage> fetchMessages(String in_suffix, int nrOfMessages) throws MessagingException {
34+
List<MimeMessage> lr_messages = new ArrayList<>();
35+
for (int i=0; i < nrOfMessages; i++ ){
36+
lr_messages.add(createMessage(in_suffix+"_"+i));
37+
}
38+
return lr_messages;
39+
}
40+
41+
public static MimeMessage[] fetchMessagesArray(String in_suffix, int nrOfMessages) throws MessagingException {
42+
MimeMessage[] lr_messages = new MimeMessage[nrOfMessages];
43+
for (int i=0; i < nrOfMessages; i++ ){
44+
lr_messages[i]= createMessage(in_suffix+"_"+i);
45+
}
46+
return lr_messages;
47+
}
48+
49+
public static List<String> fetchMessageSubjects(List<MimeMessage> messages) {
50+
51+
return messages.stream().map(m -> {
52+
try {
53+
return m.getSubject();
54+
} catch (MessagingException e) {
55+
throw new RuntimeException(e);
56+
}
57+
}).collect(Collectors.toList());
58+
}
59+
60+
public static List<String> fetchMessageArraySubjects(MimeMessage[] messages) {
61+
62+
return Arrays.stream(messages).map(m -> {
63+
try {
64+
return m.getSubject();
65+
} catch (MessagingException e) {
66+
throw new RuntimeException(e);
67+
}
68+
}).collect(Collectors.toList());
69+
}
70+
71+
72+
}
73+

bridgeService-data/src/main/java/com/adobe/campaign/tests/bridge/testdata/one/SimpleStaticMethods.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
*/
99
package com.adobe.campaign.tests.bridge.testdata.one;
1010

11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.nio.charset.Charset;
14+
import java.nio.charset.StandardCharsets;
15+
import java.nio.file.Files;
1116
import java.util.Arrays;
1217
import java.util.HashMap;
1318
import java.util.List;
@@ -115,4 +120,8 @@ public static void methodCallingMethodThrowingExceptionAndPackingIt() {
115120
throw new IllegalStateException("Got that one", e);
116121
}
117122
}
123+
124+
public static String methodAcceptingFile(File fileObject) throws IOException {
125+
return Files.readString(fileObject.toPath(), StandardCharsets.UTF_8);
126+
}
118127
}

integroBridgeService/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@
150150
<version>3.1.0</version>
151151
<scope>compile</scope>
152152
</dependency>
153-
<dependency>
154-
<groupId>com.sun.mail</groupId>
155-
<artifactId>javax.mail</artifactId>
156-
<version>1.6.2</version>
157-
<scope>test</scope>
158-
</dependency>
159153
<dependency>
160154
<groupId>com.adobe.campaign.tests.bridge.testdata</groupId>
161155
<artifactId>bridgeService-data</artifactId>

0 commit comments

Comments
 (0)