Skip to main content

Agile development of apache tucsany SCA with Ilog jrules decision services

Apache tucsany provides a framework for developing SOA solution that is based on Service Component Architecture (SCA) standard. Tucsany offers following advantages:
1) Provides a model for creating composite applications by defining the services in the fabric and their relationships with one another.
2) Enables service developers to create reusable services that only contain business logic.
3) Existing applications can work with new SCA compositions. This allows for incremental growth towards a more flexible architecture, outsourcing or providing services to others.

Tucsany implemented in java and c++ programming language. For more information visit apache tucsany site.
In the growing uses of business rules in SOA, on the current post i decide to make a laboratory work to show how to use business rules in SCA SOA solution.
For more information to get benifit from business rules please consider my some previous post about Ilog business rules.
On the current tutorial we are going to use following tools and libraries:
1) Maven 2.0.9
2) JAX-WS 2.1.5
3) Tucsany SCA 1.4
4) Ilog Jrules 6.0.7
All the information to download and install of all tools and frameworks should be found on their home site.
For developing the tutorial i preferred to use Intelli Idea 7. But you can use your own IDE because we uses maven to manage the project and you can easily create any particullar project by maven tools.
Create composite service application:
The following shows the composition diagram for the composite service application we are about to create.

The composite stock agent component consist of two services and one decision service. There is Customer agent service, from where you might get all the necessary information of customer by customer id. From the otder service we will get product information and sned all the information to decision service for some validation. If outgoing status approved, then stock agent generate products bill. Actually example used here to only show the jax-ws binding to ilog decision service.
Now we start developing from the scratch by using maven tools. First we will start ilog jrules server and deploy the example decision service provide with the jrules installation. If you deploy it's properly, you should get the wsdl in the folowing location
http://localhost:8080/DecisionService/ws/PreTradeChecksRuleApp/1.0/PreTradeChecks/1.0?WSDL
For more information develop and deploy decesion service on Jrules, please refer to the following post.
Now it's time to create the pom.xml file as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blu.sca.simple</groupId>
<artifactId>sca-simple</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>sca-simple</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>apache.incubator</id>
<url>http://people.apache.org/repo/m2-incubating-repository</url>
</repository>
</repositories>    
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-api</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-impl</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-domain-manager</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-sca</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-sca-axis2</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.1.5</version>
</dependency>

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<!--<phase>process-resources</phase>-->
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.blu.sca.dservice</packageName>
<keep>true</keep>
<sourceDestDir>${basedir}/src/main/java</sourceDestDir>
<wsdlDirectory>${basedir}/src/main/resources</wsdlDirectory>
<wsdlFiles>
<wsdlFile>pretrade.wsdl</wsdlFile>
</wsdlFiles>            
</configuration>
<dependencies>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.5</version>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.blu.sca.simple.agent.decision</mainClass>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

First of all we build the project name sca-simple by maven tools and append all the necessary dependency on it. Download the wsdl file to the src\main\resources folder to generate proxy releated class from the decesion service. In the current project i use latest version of JAX-WS which you probably need to download and install manually on the local maven repositories.
Here is the command to install libraries manually on the maven local repositories.
mvn install:install-file -Dfile=D:\Distributors\java\webservice\jax-ws\jaxws-ri\lib\jaxws-rt.jar -DgroupId=com.sun.xml.ws -DartifactId=jaxws-rt -Dversion=2.1.5 -Dpackaging=jar -DgeneratePom=true

Project is now ready to coding. If we will run the following command in console,
$mvn clean compile
the maven will first generate all the stub class from the wsdl and compile the project. This may take a few minutes because maven will download a lot of tuscany modules and files to your local repositories.
For simplicity we will only take a look to the main parts of the project. Anyway the source code the project will be downlodable.
First we will create interface for the decision service as follows:
package com.blu.sca.simple.services;

import org.osoa.sca.annotations.Remotable;
@Remotable
public interface IRulesService {
String lookup(Customer customer, Product product);
}

and also the implemention:
package com.blu.sca.simple.impl;

import com.blu.sca.simple.services.IRulesService;
import com.blu.sca.rules.*;
import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.AllowsPassByReference;
import org.osoa.sca.annotations.Service;
import org.osoa.sca.ServiceRuntimeException;

import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import java.io.StringWriter;

@Service(IRulesService.class)
@AllowsPassByReference
public class RulesService implements IRulesService {
@Reference
protected DecisionServicePreTradeChecks dsrService;

public String lookup(Customer customer, Product product) {
// create request  
DecisionServiceRequest request = new DecisionServiceRequest();
CustomerParameter customarP = new CustomerParameter();

customarP.setCustomer(customer);
OrderParameter orderP = new OrderParameter();

orderP.setOrder(product);

request.setCustomerParameter(customarP);
request.setOrderParameter(orderP);

DecisionServiceResponse response = null;
String str="";
ReportParameter report=null;
try{
response = dsrService.executeDecisionService(request);
report = response.getReportParameter();
str = report.getOrder().getStatus();
}catch(DecisionServiceSoapFault fault){
str = fault.getMessage());
}
return str;
}
}

Finally we will create composite xml file to compose all the component.
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://scadecision"
xmlns:sample="http://scadecision"
name="Decisionservice">

<component name="BookingAgentServiceComponent">
<implementation.java class="com.blu.sca.simple.impl.BookingAgentServiceComponent"/>
<reference name="customerService" target="CustomerServiceComponent" />
<reference name="orderService" target="OrderServiceComponent" />
<reference name="rulesService" target="RulesServiceComponent" />
</component>

<component name="RulesServiceComponent">
<implementation.java class="com.blu.sca.simple.impl.RulesService"/>
<reference name="dsrService">
<binding.ws uri="http://localhost:8080/DecisionService/ws/PreTradeChecksRuleApp/1.0/PreTradeChecks/1.0?WSDL" />
</reference>
</component>

<component name="CustomerServiceComponent">
<implementation.java class="com.blu.sca.simple.impl.CustomerService"/>
</component>

<component name="OrderServiceComponent">
<implementation.java class="com.blu.sca.simple.impl.OrderService"/>
</component>

</composite>

At these moment all the component is ready to compose. You can build and run the program by maven as follows:
$mvn clean compile
$mvn exec:java

Comments

Popular posts from this blog

8 things every developer should know about the Apache Ignite caching

Any technology, no matter how advanced it is, will not be able to solve your problems if you implement it improperly. Caching, precisely when it comes to the use of a distributed caching, can only accelerate your application with the proper use and configurations of it. From this point of view, Apache Ignite is no different, and there are a few steps to consider before using it in the production environment. In this article, we describe various technics that can help you to plan and adequately use of Apache Ignite as cutting-edge caching technology. Do proper capacity planning before using Ignite cluster. Do paperwork for understanding the size of the cache, number of CPUs or how many JVMs will be required. Let’s assume that you are using Hibernate as an ORM in 10 application servers and wish to use Ignite as an L2 cache. Calculate the total memory usages and the number of Ignite nodes you have to need for maintaining your SLA. An incorrect number of the Ignite nodes can become a b...

Analyse with ANT - a sonar way

After the Javaone conference in Moscow, i have found some free hours to play with Sonar . Here is a quick steps to start analyzing with ANT projects. Sonar provides Analyze with ANT document to play around with ANT, i have just modify some parts. Here is it. 1) Download the Sonar Ant Task and put it in your ${ANT_HOME}/lib directory 2) Modify your ANT build.xml as follows: <?xml version = '1.0' encoding = 'windows-1251'?> <project name="abc" default="build" basedir="."> <!-- Define the Sonar task if this hasn't been done in a common script --> <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"> <classpath path="E:\java\ant\1.8\apache-ant-1.8.0\lib" /> </taskdef> <!-- Out-of-the-box those parameters are optional --> <property name="sonar.jdbc.url" value="jdbc:oracle:thin:@xyz/sirius.xyz" /> <property na...

Writing weblogic logs to database table

By default, oracle weblogic server logging service uses an implementation, based on the Java Logging APIs by using the LogMBean.isLog4jLoggingEnabled attribute. With a few effort you can use log4j with weblogic logging service. In the Administration Console, you can specify Log4j or keep the default Java Logging implementation. In this blog i will describe how to configure log4j with weblogic logging service and writes all the logs messages to database table. Most of all cases it's sufficient to writes log on files, however it's better to get all the logs on table to query on it. In our case we have 3 different web logic servers in our project and our consumer need to get all the logs in one central place to diagnose if something goes wrong. First of all we will create a simple table on our oracle database schema and next configure all other parts. Here we go: 1) CREATE TABLE LOGS (USER_ID VARCHAR2(20), DOMAIN varchar2(50), DATED DATE NOT NULL, LOGGER VARCHAR2(500) NOT...