Skip to content

Commit

Permalink
Merge pull request #136 from adobe/110-allow-file-uploading-of-arguments
Browse files Browse the repository at this point in the history
110 allow file uploading and the usage of files asarguments
  • Loading branch information
baubakg authored May 9, 2024
2 parents 144d603 + 5cafb66 commit d74d772
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 110 deletions.
108 changes: 61 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# BridgeService

# PhasedTesting

[![unit-tests](https://github.com/adobe/bridgeService/actions/workflows/onPushSimpleTest.yml/badge.svg)](https://github.com/adobe/bridgeService/actions/workflows/onPushSimpleTest.yml)
[![codecov](https://codecov.io/gh/adobe/bridgeService/branch/main/graph/badge.svg?token=GSi0gUlqq5)](https://codecov.io/gh/adobe/bridgeService)
[![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)
Expand Down Expand Up @@ -191,7 +189,8 @@ The payload returns a JSON with the test results:

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

## Making a basic Java Call
## Making Java Calls
### A basic Java Call

The simplest java call is done in the following way:
```/call```
Expand Down Expand Up @@ -225,7 +224,7 @@ a 'returnValues' object.
}
```

## Instantiating Objects
### Instantiating Objects

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

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

## Managing Timeouts

As of version 2.11.6 we now introduce the notion of timeouts. This means that after a declared time a call will be
interrupted. Setting this value can be done at two levels:

* The deployment level
* The Call session

**Note :** If set to 0, there is no timeout.

### Setting Timeout Globally

You can set a default value when starting the service. This is done by setting the environment
variable `IBS.TIMEOUT.DEFAULT`. If not set, the default value is 10000ms.

### Setting a Timeout for the Call Session

We can also set the Timeout for a java call transaction. In that case the value you pass overrides the global value, but
only for you session. If the `timeout` is not test in the payload at the next call, the global value will be used.

In the example below the method `methodWithTimeOut` waits for the provided, in this case 800ms, amount of time. In the
example below the test will pass because we wait for 800ms, and the timeout is 1000s.

```JSON
{
"callContent": {
"call1": {
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
"method": "methodWithTimeOut",
"args": [
800
]
}
},
"timeout": 1000
}
```

If the payload above would have a timeout below 800ms, the call will fail.

## Call Chaining a basic Java Call
### Call Chaining a basic Java Call

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

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

### Call Chaining and Instance Methods
#### Call Chaining and Instance Methods

We now have the possibility of injecting call results from one call to the other. In the example below we instantiate an
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
Expand Down Expand Up @@ -389,6 +348,61 @@ the `instance` value for the following call.

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

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

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

#### Lists and Arrays
List and Arrays can be passed as JSONArrays. IBS will transform them to the target argument when needed (_Available since 2.116_).

#### Complex Types
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.

#### Files
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.

## Managing Timeouts

As of version 2.11.6 we now introduce the notion of timeouts. This means that after a declared time a call will be
interrupted. Setting this value can be done at two levels:

* The deployment level
* The Call session

**Note :** If set to 0, there is no timeout.

### Setting Timeout Globally

You can set a default value when starting the service. This is done by setting the environment
variable `IBS.TIMEOUT.DEFAULT`. If not set, the default value is 10000ms.

### Setting a Timeout for the Call Session

We can also set the Timeout for a java call transaction. In that case the value you pass overrides the global value, but
only for you session. If the `timeout` is not test in the payload at the next call, the global value will be used.

In the example below the method `methodWithTimeOut` waits for the provided, in this case 800ms, amount of time. In the
example below the test will pass because we wait for 800ms, and the timeout is 1000s.

```JSON
{
"callContent": {
"call1": {
"class": "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods",
"method": "methodWithTimeOut",
"args": [
800
]
}
},
"timeout": 1000
}
```

If the payload above would have a timeout below 800ms, the call will fail.

## Creating a Call Context

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

### Duration-based Assertions
### Duration-Based Assertions

As mentioned earlier an assertion can be duration based. In that case, IBS will consider the call duration of a call for
the assertion. In order to perform an assertion the payload needs to include the entry `"type": "DURATION"` to the
Expand Down
2 changes: 2 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
## 2.11.16-SNAPSHOT
* **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.
* **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.
* **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.
* [#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.
* [#88 Logging action steps](https://github.com/adobe/bridgeService/issues/88). We now log the steps we take during execution for better debugging.
* [#48 Logging action steps](https://github.com/adobe/bridgeService/issues/48). We now log the current class and method being executed.

## 2.11.15
* [#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.
Expand Down
8 changes: 3 additions & 5 deletions bridgeService-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
<artifactId>log4j-api</artifactId>
<version>2.23.1</version>
</dependency>
<!--
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2022 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it.
*/
package com.adobe.campaign.tests.bridge.testdata.one;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class MimeMessageMethods {
public static MimeMessage createMessage(String in_suffix) throws MessagingException {

String from = "[email protected]";
MimeMessage message = new MimeMessage((Session) null);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
message.setSubject("a subject by me " + in_suffix);
message.setText("a content by yours truely " + in_suffix);
return message;
}

public static List<MimeMessage> fetchMessages(String in_suffix, int nrOfMessages) throws MessagingException {
List<MimeMessage> lr_messages = new ArrayList<>();
for (int i=0; i < nrOfMessages; i++ ){
lr_messages.add(createMessage(in_suffix+"_"+i));
}
return lr_messages;
}

public static MimeMessage[] fetchMessagesArray(String in_suffix, int nrOfMessages) throws MessagingException {
MimeMessage[] lr_messages = new MimeMessage[nrOfMessages];
for (int i=0; i < nrOfMessages; i++ ){
lr_messages[i]= createMessage(in_suffix+"_"+i);
}
return lr_messages;
}

public static List<String> fetchMessageSubjects(List<MimeMessage> messages) {

return messages.stream().map(m -> {
try {
return m.getSubject();
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}

public static List<String> fetchMessageArraySubjects(MimeMessage[] messages) {

return Arrays.stream(messages).map(m -> {
try {
return m.getSubject();
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*/
package com.adobe.campaign.tests.bridge.testdata.one;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -115,4 +120,8 @@ public static void methodCallingMethodThrowingExceptionAndPackingIt() {
throw new IllegalStateException("Got that one", e);
}
}

public static String methodAcceptingFile(File fileObject) throws IOException {
return Files.readString(fileObject.toPath(), StandardCharsets.UTF_8);
}
}
6 changes: 0 additions & 6 deletions integroBridgeService/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.adobe.campaign.tests.bridge.testdata</groupId>
<artifactId>bridgeService-data</artifactId>
Expand Down
Loading

0 comments on commit d74d772

Please sign in to comment.