Developing an ESB Service Type

This part will introduce you to the development of an ESB Service Type using the maven plugin.

Project Layout

We advise you to look at existing service types on int-factory in the SonicPartnerCodeshare location. These projects can offer an initial guidance to start.

You can also create Arche-Types for your developers. However, this will not be handled in this users-guide.

As depicted in the image, the plugin is working with a standard maven layout. The important locations are:

  1. src/main/sonicesb: Location for the ESB Artifacts (esbstyp file)
  2. src/main/java: Location for the Sources
  3. src/test: For your test resources
  4. src/site: Location to define your site documentation

How-to Develop using the Plugin

The Maven-Plugin for ESB Service Types is allowing you to work in the way you would normally deliver a normal old-school project. You use the ESBSTYP editor in order to define the Service with init and runtime paramters, you upload the Service Type to the Sonic DS, etc.

Using 3rd party Libraries

In the past we have seen a wild-grow of 3rd party libraries in the DS. Each Service Type had its own set of libraries etc. With the Maven Plugin we want to remove this and share the libraries in a central place in the DC. For that reason, the plugin will copy all the dependent libraries into the ds under the ESBResources folder. This means that every service type will have to put the libraries on the Service Type Classpath using that location. The way to get it is as follows:

  1. Add a dependency in the pom file:
                    <dependency>
                            <groupId>xalan</groupId>
                            <artifactId>xalan</artifactId>
                            <version>2.7.1</version>
                    </dependency>
  2. Build the project with Maven. This will now upload the libraries in the Sonic DS.
  3. Add the librarie to your Service Type Classpath using the sonicfs://ESBResources location

As we all use the same dependency list, the libraries will be in one single location.

Generated Snippets

Snippets are small pieces of information that are gathered and saved by the Plugin. They are used by other parts in the plugins in order to build items automatically like adding used Queues to a broker definition or identify the needed configuration parameters.

The snippets generated by the ESB Service Type artifact are:

rules.snippets

<?xml version="1.0" encoding="UTF-8"?>
<ServiceRules>
  <ServiceRule type="Service Type">
    <Param name="InitParam1"/>
    <Param name="InitParam2"/>
    <Param name="InitParam3"/>
  </ServiceRule>
</ServiceRules>

Pom file content

Artifact Definition

        <groupId>your.group.id</groupId>
        <artifactId>artifactId</artifactId>
        <version>1.0-SNAPSHOT</version>
        <name>Short Name</name>
        <packaging>esbstyp</packaging>
        <description>Small description of what this Service Type is doing</description>
        <url>http://Servcer/location-to-doc/${project.groupId}/${project.artifactId}/${project.version}</url>

Build Section

        <build>
                <resources>
                        <resource>
                                <directory>src/main/resources</directory>
                                <filtering>true</filtering>
                        </resource>
                </resources>
                <pluginManagement>
                        <plugins>
                                <plugin>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-surefire-plugin</artifactId>
                                        <version>2.4.3</version>
                                        <inherited>true</inherited>
                                        <configuration>
                                                <forkMode>always</forkMode>
                                                <reportFormat>xml</reportFormat>
                                        </configuration>
                                </plugin>
                                <!-- Java Source Code compilation settings -->
                                <plugin>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-compiler-plugin</artifactId>
                                        <version>2.0.2</version>
                                        <executions>
                                                <execution>
                                                        <id>compile</id>
                                                        <goals>
                                                                <goal>compile</goal>
                                                        </goals>
                                                        <phase>compile</phase>
                                                        <configuration>
                                                                <!-- putting back all classes -->
                                                                <excludes>
                                                                        <exclude>none</exclude>
                                                                </excludes>
                                                                <deprecation>on</deprecation>
                                                                <source>${targetJavaVersion}</source>
                                                                <target>${targetJavaVersion}</target>
                                                                <debug>${compileDebug}</debug>
                                                                <optimize>${compileOptimize}</optimize>
                                                        </configuration>
                                                </execution>
                                        </executions>
                                        <!-- the default life cycle of the e.g. the jar plugin will always execute 
                                                compile and testCompile. It will also pull in the default configuration for 
                                                both. We will disable the default here for compile. We will add it back in 
                                                the executions above. The default compile will still be executed though. -->
                                        <configuration>
                                                <deprecation>on</deprecation>
                                                <source>${targetTestJavaVersion}</source>
                                                <target>${targetTestJavaVersion}</target>
                                                <debug>${compileDebug}</debug>
                                                <optimize>${compileOptimize}</optimize>
                                                <excludes>
                                                        <exclude>**</exclude>
                                                </excludes>
                                        </configuration>
                                </plugin>
                        </plugins>
                </pluginManagement>
                <plugins>
                        <!-- Assemble all dependencies with repository layout -->
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-site-plugin</artifactId>
                                <version>3.2</version>
                                <configuration>
                                        <reportPlugins>
                                                <plugin>
                                                        <groupId>org.apache.maven.plugins</groupId>
                                                        <artifactId>maven-project-info-reports-plugin</artifactId>
                                                        <version>2.6</version>
                                                        <!-- <configuration> <dependencyDetailsEnabled>false</dependencyDetailsEnabled> 
                                                                <dependencyLocationsEnabled>false</dependencyLocationsEnabled> </configuration> -->
                                                        <!-- simpler configuration without reportSets available for usual 
                                                                cases -->
                                                        <!-- <reports> <report>dependencies</report> <report>scm</report> 
                                                                </reports> -->
                                                </plugin>
                                                <plugin>
                                                        <groupId>org.apache.maven.plugins</groupId>
                                                        <artifactId>maven-javadoc-plugin</artifactId>
                                                        <version>2.9</version>
                                                </plugin>

                                                <plugin>
                                                        <groupId>org.apache.maven.plugins</groupId>
                                                        <artifactId>maven-surefire-report-plugin</artifactId>
                                                        <version>2.4.3</version>

                                                        <reportSets>
                                                                <reportSet>
                                                                        <reports>
                                                                                <report>report-only</report>
                                                                        </reports>
                                                                </reportSet>
                                                        </reportSets>
                                                </plugin>


                                                <plugin>
                                                        <groupId>org.apache.maven.plugins</groupId>
                                                        <artifactId>maven-pmd-plugin</artifactId>

                                                        <configuration>
                                                                <linkXref>true</linkXref>
                                                                <targetJdk>${targetJavaVersion}</targetJdk>
                                                        </configuration>
                                                </plugin>

                                                <plugin>
                                                        <groupId>org.codehaus.mojo</groupId>
                                                        <artifactId>jdepend-maven-plugin</artifactId>

                                                </plugin>

                                                <plugin>
                                                        <groupId>org.codehaus.mojo</groupId>
                                                        <artifactId>cobertura-maven-plugin</artifactId>

                                                        <configuration>
                                                                <instrumentation>
                                                                        <excludes>
                                                                                <exclude>**/*Test.class</exclude>
                                                                        </excludes>
                                                                </instrumentation>
                                                        </configuration>
                                                </plugin>

                                        </reportPlugins>
                                </configuration>
                        </plugin>
                        <plugin>
                                <groupId>com.aurea.maven.plugins</groupId>
                                <artifactId>sonicesb-maven-plugin</artifactId>
                                <version>${maven-sonicesb-plugin.version}</version>
                                <extensions>true</extensions>
                                <configuration>
                                        <type>esbstyp</type>
                                        <extension>zip</extension>
                                        <language>java</language>
                                        <containerMap>
                                                <esbContainerSettings>
                                                        <DefaultContainerSetting>
                                                                <name>ESBContainer</name>
                                                        </DefaultContainerSetting>
                                                </esbContainerSettings>
                                                <mfContainerSettings>
                                                        <DefaultContainerSetting>
                                                                <name>@MFESBContainer@</name>
                                                        </DefaultContainerSetting>
                                                </mfContainerSettings>
                                        </containerMap>
                                </configuration>
                        </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <executions>
                                        <execution>
                                                <id>unit-tests</id>
                                                <phase>test</phase>
                                                <goals>
                                                        <goal>test</goal>
                                                </goals>
                                                <configuration>
                                                        <includes>
                                                                <include>**/*UnitTest.java</include>
                                                        </includes>
                                                </configuration>
                                        </execution>
                                        <execution>
                                                <id>integration-tests</id>
                                                <phase>integration-test</phase>
                                                <goals>
                                                        <goal>test</goal>
                                                </goals>
                                                <configuration>
                                                        <includes>
                                                                <include>**/*IntegrationTest.java</include>
                                                        </includes>
                                                </configuration>
                                        </execution>
                                </executions>
                        </plugin>
                </plugins>
        </build>