JBI Component development (Part 6)
By Christophe Vaille on Nov 02, 2008
Build the generic Service Engine
1. Build the generic Service Engine
We will create the Generic Library Wrapper Service Engine component: LibWrapperServiceEngine:
The component LibWrapperServiceEngine will implement the IMapper interface.
We need to use NetBeans and the CDK to create a LibWrapperServiceEngine.
The CDK provides a development tools that helps user to develop, debug, unit test and install JBI components ( Service Engines and Binding Components ) using NetBeans IDE and also provides tools to develop the NetBeans plugin for the component.
The NetBeans plugin help the component end user to develop, test and deploy composite applications ( SA ) for the component using the IDE.
The CDK need to be downloaded and installed into NetBeans6.1:
The illustration below shows the Service Engine wizard.
The NetBeans Service Engine wizard generates a full Service Engine project:
The code generator provides a great starting point with:
- NMR interface
- WSDL interface
- Multithreaded code
- XSLT Service Engine sample code
In fact, this wizard has generated in fact a fully fonctionnal XSLT Service Engine.
We only need to code in the placeholders and remove the specific XSLT parts.
At this time it's mandatory to understand the JBI component specification.
1.2. Theory of JBI components:
Implementing a JBI plug-in component involves fulfilling several JBI-defined contracts.
These contracts cover:
• Installation packaging and description
• Component life cycle management
• Messaging based on defined message exchange patterns
• Publication of offered services
• Service unit management
More details are available on the document: the JBI Components: Part 1 (Theory) from Ron Ten-Hove
Technical document on developing JBI components from Srinivasan Chikkala
1.3. Start to implement the Lib Wrapper Service Engine
Customisation of the LibMapperServiceEngine project:
Modification from the generated XSLT SE project the following file:
- Refactor the XSLTFileLocator.java as SELibService.java
- Refactor the XSLTService.java as SEMapperFileLocator.java
Create a new package com.sun.se.lib.mapper that will contain custom classes:
This package will contain the following files:
Create into com.sun.se.lib.mapper:
Copy into com.sun.se.lib.mapper the previous renamed files:
Refactor the package com.sun.jbi.se.xltserviceengine as com.sun.se.lib.provider
The illustration shows the updated LibMapperServiceEngine project:
First we need to check the jbi.xml descriptor.
The refactoring of the package com.sun.jbi.se.xltserviceengine as com.sun.se.lib.provider impact the ProviderSERuntime class.
Edit the jbi.xml descriptor to update the ProviderSERuntime name.
Browse on LibMapperServiceEngine classes:
Declaration of the two methods:
init(String rootPath, String wsdlName);
Creation of the Params class that handles NMR message data.
Creation of four variables:
- Node node;
DOM that will contain the MyLib method parameters transferred from the NMR.
- String messageInputType;
Will contain the messageInputName (from WSDL def) transferred from the NMR.
- String messageOutputType;
Will contain the messageOutputName (from WSDL def) transferred from the NMR.
- String version;
Version of the NMR message.
The illustration below shows the Params class:
SELibService will implement:
NMR parsing code.
Creation of the DOM that parse the NMR and extration of the method parameters.
The method callMapper() that will call the right external Mapper class.
The name of the Mapper class have been loaded by the SEMapperFileLocator by reading the semap.properties file available on the SU associated to the Lib Wrapper Service Engine.
The illustration below shows the DOM creation and extraction data:
The illustration below shows the call to the libCall() methods implemented into the callMapper method of the SELibService:
SEMapperFileLocator will implement:
The Mapping properties that will loaded from the semap.properties file.
The illustration below shows the loadMappingProperties method:
Creation of the custom init code that lauch at the SU init:
Instanciation of the mapper class;
Call to the init method of the mapper to perform initialization at the mapper level as the unmarshlling of the dedicated WSDL associated with the library.
The illustration below shows the custom init code:
Creation of the custom code that call the callMapper() method of the SELibService class.
This code is implemented into the processInMessageOnProvider() method of the ProviderSEMessageExchangeHandler class.
The illustration below shows the callMapper code:
This class contain the following variables:
The doInit() method of the ProviderSEEnpoint will instanciate the two following classes: SELibService and SEMapperFileLocator.
1.4. Build and deploy the Service Engine:
Use the NetBeans LibMapperServiceEngine project menu to build the full project.
After the successful build, deploy your new LibMapperServiceEngine on the JBI-Glassfish implementation.
The illustration below shows the NetBeans6.1 Glassfish service JBI par with the LibMapperServiceEngine deployed: