This page describes the extension points for Storefront Orchestration in Infosys Equinox.
Overview
The Storefront Orchestration (SFO) microservice allows you to customize the existing functional flow with the new functional flow as per the business requirement. In this document, the sample code snippet provides the customization of authGetSession
with ValidateSessionIdAndGetAuthToken
.
Prerequisites
To customize the Storefront Orchestration (SFO) microservice, you need to understand the following:
- Routes
- RESTs
- Endpoints
Steps Require for SFO Customization
To customize the SFO,
Starting the SFO Application
To start and view the SFO application:
- Start the SFO application with the
<a href="https://jolokia.org/agent/jvm.html">jolokia jvm agent</a>
jar. Use the below mentioned Jolokia JVM Agent:
java -javaagent:jolokia-jvm-1.6.0-agent.jar=port=8778,host=localhost -jar orchestration-8.0.2.RELEASE-exec.jar
Note:
- Make sure the SFO application is started with the Jolokia Agent as highlighted in the screenshot below:
- Start the Apache Camel Visualiser by using Hawtio. See hawt.io and follow the instructions.
- Click Add to add the connection to the Remote tab.
The connection is added to the Remote tab:
- Click Connect to start the visualizer of the SFO application via Jolokia Agent.
SFO application visualizer starts as shown below:
- Click the Source tab to see the selected route.
Customizing the SFO Extension
Apache Camel provides an interface CamelContextConfiguration
to customize the Camel context before and after the SFO application startup.
The sample code snippet is used for:
Customizing the Existing Functional Flow
Overview
This section explains how to customize the existing functional flow by using the sample code snippet. Intercept the direct:authGetSession
endpoint in the ValidateSessionIdAndGetAuthToken
router.
Sample Code Snippet
Use the following sample code snippet for customizing the existing functional flow:
- Create a Maven project by using the sample extension
pom.xml
.
Extension Point – pom.xml <project xmlns=
"<a href="https://maven.apache.org/POM/4.0.0">https://maven.apache.org/POM/4.0.0</a>"
xmlns:xsi=
"<a href="https://www.w3.org/2001/XMLSchema-instance">https://www.w3.org/2001/XMLSchema-instance</a>"
xsi:schemaLocation=
"<a href="https://maven.apache.org/POM/4.0.0">https://maven.apache.org/POM/4.0.0</a> <a href="https://maven.apache.org/xsd/maven-4.0.0.xsd">https://maven.apache.org/xsd/maven-4.0.0.xsd</a>"
>
<modelVersion>
4.0
.
0
</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>
2.0
.
3
.RELEASE</version>
</parent>
<groupId>com.skava.partner</groupId>
<artifactId>orchestration-extension</artifactId>
<version>
0.0
.
1
-SNAPSHOT</version>
<name>orchestration-extension</name>
<description>orchestration-extension</description>
<packaging>jar</packaging>
<properties>
<camel.version>
2.22
.
0
</camel.version>
<maven.compiler.source>
1.8
</maven.compiler.source>
<maven.compiler.target>
1.8
</maven.compiler.target>
<maven.compiler.version>
3.5
.
1
</maven.compiler.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>
import
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>
true
</optional>
</dependency>
<!-- Orchestration libs -->
<dependency>
<groupId>com.skava.orchestration</groupId>
<artifactId>orchestration</artifactId>
<version>
8.0
.
2
.RELEASE</version>
</dependency>
</dependencies>
</project>
where,
version
tag is the latest release version of the SFO microservice.
Note: You need to avail access to the Skava artifactory to get the dependency jar. Contact Skava for further details. - Create
CustomCamelConfiguration.java
.
import
org.apache.camel.CamelContext;
import
org.apache.camel.builder.AdviceWithRouteBuilder;
import
org.apache.camel.spring.boot.CamelContextConfiguration;
import
org.slf4j.Logger;
import
org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.context.annotation.Configuration;
import
com.skava.orchestration.CamelContextUtilityBean;
@Configuration
public
class
CustomCamelConfiguration
implements
CamelContextConfiguration {
private
static
final
Logger LOGGER = LoggerFactory.getLogger(CustomCamelConfiguration.
class
);
static
{
LOGGER.info(
"###### Custom camel configuration found ######"
);
}
@Autowired
private
CamelContextUtilityBean camelContextUtilityBean;
public
void
beforeApplicationStart(CamelContext camelContext) {
LOGGER.info(
"##### Custom camel configuration started #####"
);
try
{
// Disable default routes in the camel context
camelContext.getRouteDefinition(
"sendNotificationRoute"
)
.autoStartup(
false
);
// Delete default route in the camel context
camelContext.removeRoute(
"deleteCustomerRoute"
);
// Load external routes and rests
camelContextUtilityBean.loadXmlRoutes(camelContext,
"classpath:routes/*.xml"
);
camelContextUtilityBean.loadXmlRests(camelContext,
"classpath:rests/*.xml"
);
// Some other ways to load external routes and rests
// camelContextUtilityBean.loadXmlRoutes(camelContext, "file:D:/usr/local/exts/orchestration/camel-routes/*.xml");
// camelContextUtilityBean.loadXmlRests(camelContext, "file:D:/usr/local/exts/orchestration/camel-rests/*.xml");
// Intercept existing route with custom implementation
camelContext.getRouteDefinition(
"ValidateSessionIdAndGetAuthToken"
)
.adviceWith(camelContext,
new
AdviceWithRouteBuilder() {
@Override
public
void
configure() {
interceptSendToEndpoint(
"direct:authGetSession"
)
.skipSendToOriginalEndpoint()
.log(
"Redirect to custom get session"
)
.to(
"direct:customGetSession"
);
}
});
}
catch
(Exception e) {
LOGGER.error(
"Exception occured while loading custom routes"
);
throw
new
RuntimeException(
"Exception occured while loading custom routes"
, e);
}
}
public
void
afterApplicationStart(CamelContext camelContext) {
LOGGER.info(
"##### Custom camel configuration done #####"
);
}
Note: The SFO’s
authGetSession
functionality will get replaced bycustomGetSession
functionality from the extension. - Create
src/main/resources/routes/custom-auth-routes.xml
.
Note: ThecustomGetSession
should be implemented as shown in the sample below:<
routes
xmlns
=
"<a href="https://camel.apache.org/schema/spring">
https://camel.apache.org/schema/spring</a>">
<
route
id
=
"customGetSessionRoute"
>
<
from
uri
=
"direct:customGetSession"
/>
<
log
message
=
"Custom get session router"
loggingLevel
=
"INFO"
/>
<
setHeader
headerName
=
"CamelHttpResponseCode"
>
<
simple
>200</
simple
>
</
setHeader
>
<
setHeader
headerName
=
"Exchange.HTTP_URI"
>
<
simple
><a href="https://localhost/orchestration/stubs/session.json">
https://localhost/orchestration/stubs/session.json</a></simple
>
</
setHeader
>
<
to
uri
=
"{{skava.component.http}}"
/>
<
unmarshal
>
<
json
library
=
"Jackson"
unmarshalTypeName
=
"com.skava.auth.model.Session"
/>
</
unmarshal
>
</
route
>
</
routes
>
Adding a New Endpoint in Extensions
In this section, you will see how to add a new endpoint by using the sample code snippet.
Here is the sample code snippet for creating src/main/resources/rests/custom-rests.xml
:
<? xml version = "1.0" encoding = "UTF-8" ?> < rest path = "/extension" xmlns = "<a href="https://camel.apache.org/schema/spring">https://camel.apache.org/schema/spring</a>" > < description >Custom rest for extension </ description > < get uri = "/ping" produces = "application/json" outType = "java.lang.String" > < description >Custom rest ping</ description > < responseMessage message = "Ok" code = "200" responseModel = "java.lang.String" /> < route id = "extensionRestPingRoute" > < log message = "Extension rest ping call triggered" loggingLevel = "INFO" /> < transform > < simple >Extension rest ping ${bean:java.lang.System?method=currentTimeMillis} </ simple > </ transform > </ route > </ get > </ rest > |
Building Your Project
To build your project,
-
- Run the following maven command:
mvn clean install
Note: The extension jar will be available in the target directory.
- Move the extension jar from the target directory to the extensions directory.
- Start the SFO jar with available extension jar by using the following command:
java -cp orchestration-8.0.2.RELEASE-exec.jar -Dloader.path=extensions\ org.springframework.boot.loader.PropertiesLauncher
where,
orchestration-8.0.2.RELEASE-EXEC.jar
represents the application jar of a particular release.-Dloader.path
contains the path of the generated jar within the extensions directory.
- Verify the customization has been applied or not by checking the Swagger where you can find the extension as a new tag.
- Run the following maven command:
Revision History
2022-04-10 | JP – Fixed link and http issues.
2020-04-25 | JP – Minor copyedit.
2019-07-12 | Mary – Page created and content uploaded.