Skip to content

Commit 797e80e

Browse files
author
Nemanja Nedeljkovic
committed
Initial SIP Adapter examples
0 parents  commit 797e80e

File tree

174 files changed

+2530
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+2530
-0
lines changed

.gitignore

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
.idea
15+
**/.idea
16+
17+
### Eclipse ###
18+
.apt_generated
19+
.classpath
20+
.factorypath
21+
.project
22+
.settings
23+
.springBeans
24+
.sts4-cache
25+
26+
### NetBeans ###
27+
/nbproject/private/
28+
/nbbuild/
29+
/dist/
30+
/nbdist/
31+
/.nb-gradle/
32+
build/
33+
!**/src/main/**/build/
34+
!**/src/test/**/build/
35+
36+
### VS Code ###
37+
.vscode/
38+
39+
### Mac OS ###
40+
.DS_Store

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SIP Adapter Examples
2+
3+
This repository contains examples of SIP Adapters,
4+
which demonstrate main features of the SIP Framework and how to use them.
5+
6+
## Adapters
7+
[Configuration Handlers Demo](configuration-handlers/README.md) - Adapter which demonstrates how to add and use configuration handlers
8+
(exception handlers, intercepts).
9+
10+
[Connector Orchestration Demo](connector-orchestration/README.md) - Adapter which demonstrates how to add and use processors which transform/handle
11+
request or response inside connectors and how to order them.
12+
13+
[Inbound Service Security Demo](inbound-service-security/README.md) - Adapter which shows how to add spring security to an adapter.
14+
Secured with OIDC (keycloak).
15+
16+
[Outbound Service Security Demo](outbound-service-security/README.md) - Adapter which demonstrates how to fetch a token from a secured server
17+
and later use it in a request to an external service.
18+

configuration-handlers/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Configuration Handlers Demo
2+
3+
This adapter demonstrates how to add configuration and exception handlers
4+
to different components and levels of SIP Framework.
5+
6+
## Configuration
7+
8+
Configuration handlers are added to two SIP components, scenarios and connectors.
9+
10+
There are 3 Configuration Defined in the adapter.
11+
(Names are just for demonstration purposes)
12+
13+
1. ScenarioLevelErrorHandler - placed on the integration scenario,
14+
containing onException definition for RuntimeException and UnknownHostException
15+
2. ConnectorLevelErrorHandler - placed on all connectors found in the adapter,
16+
containing onException definition for IllegalArgumentException
17+
3. InterceptEndpointConfiguration - placed on the integration scenario,
18+
containing interceptSendToEndpoint definition
19+
20+
**OnException**
21+
In case of exception handlers only one will be triggered. The priority is based on the Exception it handles,
22+
starting with the most concrete one.
23+
Priority is not affected by the component they are placed on or the order in which they are defined in annotation.
24+
25+
## Connector Exception Handler
26+
27+
This handler overrides onException handler in general configuration if they handle the same exception type.
28+
This is demonstrated in ConcreteHandlerOutConnector where IllegalArgumentException is handled
29+
and will take priority over ConnectorLevelErrorHandler.
30+
31+
## Usage
32+
33+
Each inbound connector exposes one REST GET endpoint which shows the effects of different handlers.
34+
35+
- `/adapter/success` will not produce an error, but it will invoke InterceptEndpointConfiguration
36+
- `/adapter/exception/runtime` will produce a UnknownHostException which will be handled by ScenarioLevelErrorHandler
37+
- `/adapter/exception/generic` will produce a IllegalArgumentException which will be handled by ConnectorLevelErrorHandler
38+
- `/adapter/exception/concrete` will produce a IllegalArgumentException which will be handled inside the connector itself
39+
(ConcreteHandlerOutConnector)
40+

configuration-handlers/pom.xml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>de.ikor.sip</groupId>
8+
<artifactId>sip-examples</artifactId>
9+
<version>3.4.0</version>
10+
</parent>
11+
12+
<groupId>de.ikor.sip.adapter</groupId>
13+
<artifactId>configuration-handlers</artifactId>
14+
<version>1.0.0-SNAPSHOT</version>
15+
<description>SIP Integration adapter</description>
16+
17+
<name>Configuration Handlers</name>
18+
19+
<url/>
20+
<licenses>
21+
<license/>
22+
</licenses>
23+
<scm>
24+
<connection/>
25+
<developerConnection/>
26+
<url/>
27+
</scm>
28+
<issueManagement>
29+
<system/>
30+
<url/>
31+
</issueManagement>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.projectlombok</groupId>
36+
<artifactId>lombok</artifactId>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>de.ikor.sip.foundation</groupId>
44+
<artifactId>sip-maven-plugin</artifactId>
45+
</plugin>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-compiler-plugin</artifactId>
49+
<configuration>
50+
<annotationProcessorPaths>
51+
<path>
52+
<groupId>org.projectlombok</groupId>
53+
<artifactId>lombok</artifactId>
54+
<version>${lombok.version}</version>
55+
</path>
56+
<path>
57+
<groupId>org.projectlombok</groupId>
58+
<artifactId>lombok-mapstruct-binding</artifactId>
59+
<version>${lombok-mapstruct-binding.version}</version>
60+
</path>
61+
<path>
62+
<groupId>org.mapstruct</groupId>
63+
<artifactId>mapstruct-processor</artifactId>
64+
<version>${mapstruct.version}</version>
65+
</path>
66+
</annotationProcessorPaths>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-maven-plugin</artifactId>
72+
<configuration>
73+
<skip>false</skip>
74+
</configuration>
75+
<executions>
76+
<execution>
77+
<goals>
78+
<goal>repackage</goal>
79+
<goal>build-info</goal>
80+
</goals>
81+
<configuration>
82+
<additionalProperties>
83+
<sipFrameworkVersion>${project.parent.version}</sipFrameworkVersion>
84+
</additionalProperties>
85+
</configuration>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-surefire-plugin</artifactId>
92+
</plugin>
93+
</plugins>
94+
</build>
95+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package de.ikor.sip.adapter.config;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import de.ikor.sip.foundation.core.annotation.SIPIntegrationAdapter;
5+
6+
@SIPIntegrationAdapter
7+
public class SIPApplication {
8+
public static void main(String[] args) {
9+
SpringApplication.run(SIPApplication.class, args);
10+
}
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package de.ikor.sip.adapter.config.config.exception;
2+
3+
import de.ikor.sip.foundation.core.declarative.configuration.ConfigurationDefinition;
4+
import org.apache.camel.model.OutputDefinition;
5+
import org.apache.camel.model.RouteConfigurationDefinition;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
/**
9+
* Implementation of {@link ConfigurationDefinition} which is used to handle {@link IllegalArgumentException}
10+
*/
11+
@Configuration
12+
public class ConnectorLevelErrorHandler implements ConfigurationDefinition {
13+
14+
@Override
15+
public OutputDefinition define(RouteConfigurationDefinition routeConfigurationDefinition) {
16+
return routeConfigurationDefinition
17+
.onException(IllegalArgumentException.class)
18+
.process(new ErrorHandlerProcessor(this.getClass()))
19+
.handled(true);
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package de.ikor.sip.adapter.config.config.exception;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.apache.camel.Exchange;
5+
import org.apache.camel.Processor;
6+
import org.springframework.util.ClassUtils;
7+
8+
/**
9+
* Default processor for exception handling
10+
*/
11+
@RequiredArgsConstructor
12+
public class ErrorHandlerProcessor implements Processor {
13+
14+
private final Class<?> source;
15+
@Override
16+
public void process(Exchange exchange) throws Exception {
17+
Exception caught = exchange
18+
.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
19+
exchange.getMessage().setBody(
20+
String.format("Exception %s was handled by %s",
21+
caught.getClass().getSimpleName(),
22+
ClassUtils.getShortName(source)));
23+
exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package de.ikor.sip.adapter.config.config.exception;
2+
3+
import de.ikor.sip.foundation.core.declarative.configuration.ConfigurationDefinition;
4+
import org.apache.camel.model.OutputDefinition;
5+
import org.apache.camel.model.RouteConfigurationDefinition;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
import java.net.UnknownHostException;
9+
10+
/**
11+
* Implementation of {@link ConfigurationDefinition} which is used to handle
12+
* {@link RuntimeException} and {@link UnknownHostException}
13+
*/
14+
@Configuration
15+
public class ScenarioLevelErrorHandler implements ConfigurationDefinition {
16+
17+
@Override
18+
public OutputDefinition define(RouteConfigurationDefinition routeConfigurationDefinition) {
19+
return routeConfigurationDefinition
20+
.onException(RuntimeException.class, UnknownHostException.class)
21+
.process(new ErrorHandlerProcessor(this.getClass()))
22+
.handled(true);
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package de.ikor.sip.adapter.config.config.intercept;
2+
3+
import de.ikor.sip.foundation.core.declarative.configuration.ConfigurationDefinition;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.apache.camel.model.OutputDefinition;
6+
import org.apache.camel.model.RouteConfigurationDefinition;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
/**
10+
* Implementation of {@link ConfigurationDefinition} which is used to define
11+
* interceptSendToEndpoint define which intercepts all log endpoints
12+
*/
13+
@Configuration
14+
@Slf4j
15+
public class InterceptEndpointConfiguration implements ConfigurationDefinition {
16+
17+
@Override
18+
public OutputDefinition define(RouteConfigurationDefinition routeConfigurationDefinition) {
19+
return routeConfigurationDefinition
20+
.interceptSendToEndpoint("log*")
21+
.process(exchange -> {
22+
log.info("Finalised message");
23+
exchange.getMessage().setBody("Intercepted");
24+
});
25+
}
26+
}

configuration-handlers/src/main/java/de/ikor/sip/adapter/config/connectorgroups/first/config/.keep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package de.ikor.sip.adapter.config.connectorgroups.first.connectors;
2+
3+
import de.ikor.sip.adapter.config.config.exception.ConnectorLevelErrorHandler;
4+
import de.ikor.sip.adapter.config.scenarios.definitions.DemoConcreteHandlerScenario;
5+
import de.ikor.sip.foundation.core.declarative.annonation.ConfigurationHandler;
6+
import de.ikor.sip.foundation.core.declarative.annonation.InboundConnector;
7+
import de.ikor.sip.foundation.core.declarative.connector.RestInboundConnectorBase;
8+
import lombok.RequiredArgsConstructor;
9+
import org.apache.camel.model.rest.RestDefinition;
10+
11+
/**
12+
* Inbound connector designed to demonstrate exception handling on the most fine-grained level
13+
*/
14+
@InboundConnector(
15+
connectorId = "ConcreteHandlerInConnector",
16+
connectorGroup = "first",
17+
requestModel = String.class,
18+
responseModel = String.class,
19+
integrationScenario = DemoConcreteHandlerScenario.ID)
20+
@RequiredArgsConstructor
21+
@ConfigurationHandler(ConnectorLevelErrorHandler.class)
22+
public class ConcreteHandlerInConnector extends RestInboundConnectorBase {
23+
24+
@Override
25+
protected void configureRest(RestDefinition restDefinition) {
26+
restDefinition.get("/exception/concrete");
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.ikor.sip.adapter.config.connectorgroups.first.connectors;
2+
3+
import de.ikor.sip.adapter.config.config.exception.ConnectorLevelErrorHandler;
4+
import de.ikor.sip.adapter.config.scenarios.definitions.DemoGenericHandlerScenario;
5+
import de.ikor.sip.foundation.core.declarative.annonation.ConfigurationHandler;
6+
import de.ikor.sip.foundation.core.declarative.annonation.InboundConnector;
7+
import de.ikor.sip.foundation.core.declarative.connector.RestInboundConnectorBase;
8+
import lombok.RequiredArgsConstructor;
9+
import org.apache.camel.model.rest.RestDefinition;
10+
11+
/**
12+
* Inbound connector designed to demonstrate exception handling by connector level handler
13+
*/
14+
@InboundConnector(
15+
connectorId = "ConnectorHandlerInConnector",
16+
connectorGroup = "first",
17+
requestModel = String.class,
18+
responseModel = String.class,
19+
integrationScenario = DemoGenericHandlerScenario.ID)
20+
@RequiredArgsConstructor
21+
@ConfigurationHandler(ConnectorLevelErrorHandler.class)
22+
public class ConnectorHandlerInConnector extends RestInboundConnectorBase {
23+
@Override
24+
protected void configureRest(RestDefinition restDefinition) {
25+
restDefinition.get("/exception/generic");
26+
}
27+
}

0 commit comments

Comments
 (0)