Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Hrms 803 added custom headers (#14)
Browse files Browse the repository at this point in the history
* added possibility to test custom headers;
added tests for the raw endpoint;
custom headers will be set as the allowed key-value pairs in the configuration for the `http` and `event` headers respectively, so the `event-emitter` reads the `http` header and convert it to proper `event` header

* fixed CODEOWNERS team name

---------

Co-authored-by: Denys Ovcharuk <[email protected]>
  • Loading branch information
dov-mallakath and denyso-bb authored Dec 13, 2023
1 parent fb72387 commit c0fa8f8
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
# In each subsection folders are ordered first by depth, then alphabetically.
# This should make it easy to add new rules without breaking existing ones.

* @backbase/gromit
* @backbase/hermes
.github/ @backbase/backend-leadership
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
name: Maven Verify
uses: backbase/workflows/.github/workflows/maven-verify.yml@main
secrets:
maven-username: ${{ secrets.MAVEN_USERNAME }}
maven-password: ${{ secrets.MAVEN_PASSWORD }}
maven-username: ${{ secrets.REPO_USERNAME }}
maven-password: ${{ secrets.REPO_PASSWORD }}
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,31 @@ Event emitter allows you to produce events using REST to the underlying message

Event emitter allows you to produce events using REST.


### Custom Headers Configuration

In order to pass custom headers from HTTP request to Event - you need to configure key-value mapping pairs for such headers:

```yaml
backbase:
event-emitter:
custom-header-pairs:
- http: X-LOB
event: bbLineOfBusiness
```
The service will filter out the HTTP headers by the `http` field as key and will set the respective values to the Event under the matching `event` key from configuration.

For the listed example, if service receive the HTTP request with header `X-LOB: RETAIL` - this header would be converted added to the event as `bbLineOfBusiness: RETAIL`

If the conversion is not required - please set the same values to `http` and `event`

### Raw Event

```shell
curl --location --request POST 'http://localhost:8079/events/raw' \
--header 'Content-Type: application/json' \
--header 'X-LOB: RETAIL' \
--data-raw '{
"destination": "Backbase.engagement.ProvisionItem",
"eventType": "com.backbase.engagement.provisioning.messaging.dto.ProvisionItemCommand",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.backbase.eo.testing.events.configuration;

import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
@Getter
@ConfigurationProperties("backbase.event-emitter")
@EnableConfigurationProperties(value = EventEmitterConfiguration.class)
public class EventEmitterConfiguration {

private final List<CustomHeaderPairs> customHeaderPairs = new ArrayList<>();

public record CustomHeaderPairs(
String http,
String event) {
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.backbase.eo.testing.events.emitter;

import static java.util.Collections.emptyEnumeration;
import static java.util.Optional.ofNullable;

import com.backbase.buildingblocks.backend.communication.context.OriginatorContext;
import com.backbase.buildingblocks.backend.communication.event.EnvelopedEvent;
import com.backbase.buildingblocks.backend.communication.event.scs.EventMessageProcessor;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.backbase.eo.testing.events.configuration.EventEmitterConfiguration;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -22,6 +21,13 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
* {@link RawEmittingController}
* <br>
Expand All @@ -42,11 +48,13 @@ public class RawEmittingController {
@Autowired(required = false)
private List<EventMessageProcessor> eventMessageProcessors = Collections.emptyList();

private final EventEmitterConfiguration eventEmitterConfiguration;

@PostMapping(
path = "/events/raw",
consumes = {MediaType.APPLICATION_JSON_VALUE}
)
public ResponseEntity<Void> emitEvent(@RequestBody RawEventPayload payload) {
public ResponseEntity<Void> emitEvent(HttpServletRequest request, @RequestBody RawEventPayload payload) {

OriginatorContext originatorContext = new OriginatorContext();
originatorContext.setRequestUuid(payload.getRequestId());
Expand All @@ -57,6 +65,14 @@ public ResponseEntity<Void> emitEvent(@RequestBody RawEventPayload payload) {
envelopedEvent.setEvent(payload.getBody());

MessageBuilder eventMessageBuilder = MessageBuilder.withPayload(payload.getBody()).setHeader("bbEventType", payload.getEventType());

eventEmitterConfiguration.getCustomHeaderPairs()
.stream()
.filter(customHeaderPairs ->
Collections.list(ofNullable(request.getHeaderNames()).orElse(emptyEnumeration())).contains(customHeaderPairs.http()))
.forEach(customHeaderPairs ->
eventMessageBuilder.setHeader(customHeaderPairs.event(), request.getHeader(customHeaderPairs.http())));

this.eventMessageProcessors.forEach((processor) -> {
processor.prepareEventMessage(eventMessageBuilder, envelopedEvent);
});
Expand All @@ -69,7 +85,6 @@ public ResponseEntity<Void> emitEvent(@RequestBody RawEventPayload payload) {

@Data
static class RawEventPayload {

private String destination;
private String eventType;
private String requestId = UUID.randomUUID().toString();
Expand Down
93 changes: 0 additions & 93 deletions src/test/java/com/backbase/eo/testing/events/EventEmitterIT.java

This file was deleted.

Loading

0 comments on commit c0fa8f8

Please sign in to comment.