| At line 1 removed 2 lines. |
| !!!IN PROGRESS |
| At line 5 changed 1 line. |
| Fuji provides a strong support for Interacting of JBI application with that of JAVA code outside of JBI, This documents provide the details how this can achieved easily with the existing simple Service API, and what are the Future plans |
| Fuji provides a strong support for Interacting of JBI application with that of JAVA code outside of JBI, This documents provide the details how this can achieved easily with the existing simple Service API, and what are the Future plans. This document to be precise concentrates on how the api can be used with respect to spring and springDM applications |
| At line 9 changed 1 line. |
| This [blog|http://blogs.sun.com/sujit/entry/fuji_simple_service_api_and ] gives an idea how to provision a service within springDM and access the same from JBI, However we will delve into some of the details which one would require in order the setup the environment |
| This [blog|http://blogs.sun.com/sujit/entry/fuji_simple_service_api_and ] gives an idea how to provision a service and consume a service from within springDM and access the same from JBI, However we will delve into some of the details which one would require in order the setup the environment |
| At line 13 changed 1 line. |
| This is key for the springDM applications to work, There two possible approach one can take in order to install the springDM Bundles on Fuji-Felix or Fuji-Glassfish, The set of Bundles which needs to be installed are |
| This is key for the springDM applications to work, There a two possible approach one can take in order to install the springDM Bundles on Fuji-Felix or Fuji-Glassfish, The set of Bundles which needs to be installed are |
| At line 30 changed 1 line. |
| The order in which this osgi bundles needs to be installed is shown below |
| The order in which this osgi bundles can be installed is shown below |
| At line 49 added 2 lines. |
| One can always create a Fuji-Felix bundle, which has all the required springDM bundle preinstalled, For this follow the steps as shown |
| !a) Modify /fuji/packaging/release-packages/felix/pom.xml |
| At line 52 changed 2 lines. |
| !Modify /fuji/packaging/release-packages/felix/pom.xml |
| __1. Incude the Bundles/jar as part of Fuji-Felix__ |
| At line 54 added 8 lines. |
| <resources> |
| <resource> |
| <targetPath>fuji/bundle</targetPath> |
| <filtering>false</filtering> |
| <directory>target/staging</directory> |
| <includes> |
| <!-- Core OSGi --> |
| ... |
| At line 56 changed 1 line. |
| }}} |
| <!--spring DM--> |
| <include>spring-osgi-core.jar</include> |
| <include>spring-osgi-extender.jar</include> |
| <include>spring-osgi-io.jar</include> |
| <include>cglib-nodep.osgi.jar</include> |
| <include>com.springsource.org.aopalliance.jar</include> |
| <include>com.springsource.slf4j.api.jar</include> |
| <include>com.springsource.slf4j.log4j.jar</include> |
| <include>com.springsource.slf4j.org.apache.commons.logging.jar</include> |
| <include>org.springframework.aop.jar</include> |
| <include>org.springframework.beans.jar</include> |
| <include>org.springframework.context.jar</include> |
| <include>org.springframework.core.jar</include> |
| <include>log4j.osgi.jar</include> |
| </includes> |
| </resource> |
| ... |
| At line 85 added 3 lines. |
| }}} |
| __2.Fetch spring DM framework module jars and dependencies __ |
| At line 89 added 35 lines. |
| <plugins> |
| <plugin> |
| <artifactId>maven-dependency-plugin</artifactId> |
| <executions> |
| ... |
| <!-- fetch spring DM framework module, excluding transitive dependencies false : --> |
| <execution> |
| <id>${project.artifactId}-fetch-springDM</id> |
| <phase>generate-resources</phase> |
| <goals><goal>copy-dependencies</goal></goals> |
| <configuration> |
| <outputDirectory>${stagingDir}</outputDirectory> |
| <stripVersion>true</stripVersion> |
| <includeGroupIds>org.springframework.osgi</includeGroupIds> |
| <excludeTransitive>false</excludeTransitive> |
| </configuration> |
| </execution> |
| <execution> |
| <id>${project.artifactId}-fetch-spring</id> |
| <phase>generate-resources</phase> |
| <goals><goal>copy-dependencies</goal></goals> |
| <configuration> |
| <outputDirectory>${stagingDir}</outputDirectory> |
| <stripVersion>true</stripVersion> |
| <includeGroupIds>org.springframework,org.aopalliance,org.slf4j</includeGroupIds> |
| <excludeTransitive>false</excludeTransitive> |
| </configuration> |
| </execution> |
| </executions> |
| At line 61 removed 1 line. |
| At line 64 changed 1 line. |
| __3. Add the required dependency in the Projects for the springDM jars__ |
| At line 129 added 2 lines. |
| <dependencies> |
| ... |
| At line 132 added 49 lines. |
| <!-- spring DM --> |
| <dependency> |
| <groupId>org.springframework.osgi</groupId> |
| <artifactId>spring-osgi-core</artifactId> |
| <version>1.2.0</version> |
| </dependency> |
| <dependency> |
| <groupId>org.springframework.osgi</groupId> |
| <artifactId>spring-osgi-extender</artifactId> |
| <version>1.2.0</version> |
| </dependency> |
| <dependency> |
| <groupId>org.springframework.osgi</groupId> |
| <artifactId>log4j.osgi</artifactId> |
| <version>1.2.15-SNAPSHOT</version> |
| </dependency> |
| <dependency> |
| <groupId>org.springframework.osgi</groupId> |
| <artifactId>cglib-nodep.osgi</artifactId> |
| <version>2.1.3-SNAPSHOT</version> |
| </dependency> |
| <!-- spring framework --> |
| <dependency> |
| <groupId>org.springframework</groupId> |
| <artifactId>org.springframework.core</artifactId> |
| <version>2.5.6.A</version> |
| </dependency> |
| <dependency> |
| <groupId>org.aopalliance</groupId> |
| <artifactId>com.springsource.org.aopalliance</artifactId> |
| <version>1.0.0</version> |
| </dependency> |
| <dependency> |
| <groupId>org.slf4j</groupId> |
| <artifactId>com.springsource.slf4j.log4j</artifactId> |
| <version>1.5.0</version> |
| </dependency> |
| <dependency> |
| <groupId>org.slf4j</groupId> |
| <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId> |
| <version>1.5.0</version> |
| </dependency> |
| At line 68 removed 1 line. |
| }}} |
| At line 70 changed 1 line. |
| !Modify /fuji/packaging/release-packages/felix/conf/config.properties |
| </dependencies> |
| At line 185 added 4 lines. |
| }}} |
| !b) Modify /fuji/packaging/release-packages/felix/conf/config.properties |
| This will ensure that all the springDM bundles are started, once the Fuji-Felix is started |
| At line 95 changed 1 line. |
| !GO to SRC_ROOT , mvn clean install |
| !c) GO to FUJI SRC_ROOT , mvn clean install |
| i.e build Fuji-Felix bundle |
| At line 215 added 174 lines. |
| !!Create SpringDM application |
| !Maven archetype for creating springDM app |
| {{{ |
| mvn archetype:create |
| -DarchetypeGroupId=org.springframework.osgi |
| -DarchetypeArtifactId=spring-osgi-bundle-archetype |
| -DarchetypeVersion=1.1.0 |
| -DgroupId=org.foo |
| -DartifactId=org.foo.springdm.fuji |
| -Dversion=1.0 |
| }}} |
| !how does the project created look like |
| [{Image src='springDM-project.PNG' align='left|center|right' }] |
| !Add Fuji Simple Service API dependency, add the following to the pom.xml of springDM app |
| {{{ |
| <dependency> |
| <groupId>open-esb.fuji</groupId> |
| <artifactId>api</artifactId> |
| <version>1.0-M9-SNAPSHOT</version> |
| </dependency> |
| }}} |
| now we are all set to make use of the Fuji Simple Service API |
| !Create Service Provider and export the same as osgi service, with the required service properties, Note how this can be easily done declaratively using the springDM, One does not have to write code for bundle activation or service registration. |
| [{Image src='http://wiki.open-esb.java.net/attach/FujiServiceAPI/service-api-provider.jpg' width='300' height='200' align='left|center|right' }] |
| a) POJO Implementation: The example below shows a simple service provider |
| {{{ |
| package org.foo; |
| import org.glassfish.openesb.api.service.ServiceMessage; |
| import org.glassfish.openesb.api.service.ServiceMessageFactory; |
| import org.glassfish.openesb.api.service.ServiceProvider; |
| public class MyProvider implements ServiceProvider { |
| ServiceMessageFactory msgFactory_; |
| public ServiceMessage invoke(ServiceMessage message) throws Exception { |
| // Print out the content of the message |
| String payload = (String)message.getPayload(); |
| System.out.println(payload); |
| // One way exchange, so there's no need to return anything |
| return null; |
| } |
| public void setMessageFactory(ServiceMessageFactory factory) { |
| msgFactory_ = factory; |
| } |
| public void setAnotherBean (AnotherBeanI bean){ |
| //make use the bean |
| } |
| } |
| }}} |
| b) Define the bean in the spring config file |
| {{{ |
| <?xml version="1.0" encoding="UTF-8"?> |
| <beans xmlns="http://www.springframework.org/schema/beans" |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xmlns:osgi="http://www.springframework.org/schema/osgi" |
| xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
| http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd"> |
| <bean name="anotherBean" class="org.foo.AnotherBeanImpl" /> |
| <bean name="fujiService" class="org.foo.MyProvider"> |
| <property name="anotherBean" ref="anotherBean" /> |
| </bean> |
| </beans> |
| }}} |
| c) Define the bean to be exported as osgi service in the spring-osgi config file |
| {{{ |
| <?xml version="1.0" encoding="UTF-8"?> |
| <beans:beans xmlns:beans="http://www.springframework.org/schema/beans" |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xmlns="http://www.springframework.org/schema/osgi" |
| xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
| http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd"> |
| <service id="fujiServiceOsgi" ref="fujiService" |
| interface="org.glassfish.openesb.api.service.ServiceProvider"> |
| <service-properties> |
| <beans:entry key="org.glassfish.openesb.serviceName" value="xyzService" /> |
| <beans:entry key="org.glassfish.openesb.endpointName" value="endpoint1" /> |
| </service-properties> |
| </service> |
| </beans:beans> |
| }}} |
| d) Build and depoy the springDM application |
| * mvn clean install |
| *go to felix console and install/start the springDM app buundle |
| !Service Consumer: Now let us create a service consumer which consumes JBI services, The example below shows a simple Service Consumer |
| [{Image src='http://wiki.open-esb.java.net/attach/FujiServiceAPI/service-api-consumer.jpg' width='300' height='200' align='left|center|right' }] |
| a) POJO Implementation: The example below shows a simple bean using the service consumer |
| {{{ |
| package org.foo; |
| import org.glassfish.openesb.api.service.ServiceConsumer; |
| import org.glassfish.openesb.api.service.ServiceMessage; |
| import org.osgi.framework.ServiceReference; |
| public class BeanWithJbiServiceReference { |
| private ServiceReference serviceReference; |
| private ServiceConsumer service; |
| public void setServiceReference(ServiceReference serviceReference) { |
| this.serviceReference = serviceReference; |
| } |
| public void setService(ServiceConsumer service) { |
| this.service = service; |
| } |
| public void invokeJBIService(Object payload) throws Exception{ |
| ServiceMessage message = service.getServiceMessageFactory().createMessage(); |
| message.setPayload(payload); |
| service.invoke(message); |
| } |
| } |
| }}} |
| b)spring config file, define the bean, this uses dependency injection to inject the service reference |
| {{{ |
| <bean id="someBean" class="org.foo.BeanWithJbiServiceReference" lazy-init="false"> |
| <property name="serviceReference" ref="jbiService" /> |
| <property name="service" ref="jbiService" /> |
| </bean> |
| }}} |
| c)spring osgi config file, define the service reference , which initiated based on the filter |
| {{{ |
| <reference id="jbiService" |
| interface="org.glassfish.openesb.api.service.ServiceConsumer" |
| filter="(org.glassfish.openesb.serviceName=abcService)" /> |
| }}} |
| !Sample Application |
| attached [here|org.foo.springdm.fuji.zip] is sample application which include for both service provider and service consumer |