Monday, 6 August 2012

Design influenced by high loading

One of the most important requirement against OSB is the response time. Usually we must prepare to process huge amount of requests. The more requests the OSB has to serve the more time the OSB needs to process one request. After a while the response time is going to be so long that it will decrease the user experience or it won't meet the SLA values or simply we get an error as it has caused a timeout.
It is vital to have standby as well to prepare the unexpected loading. Just imagine that a campaign has been launched to popularise a new product. If this campaign is successful then it can cause a bigger traffic than usual. If we are not prepared to handle these more requests then I think it is really hard to explain to the business users or our boss that the problem is that too many customers want to buy our products... :)

The obvious solution is in this case to add more servers to our OSB environment. Of course there are more possible workarounds too (optimizing code of OSB components or external services) but adding servers is the quickest one (Usually it is pretty difficult to change the existing code and sometimes it is not possible if an external system should be optimized.)
I am not stating that getting and installing a new server takes only minutes. A server could cost a fortune so getting one ore more needs the confirmation of different departments which can last ages. Afterwards it has to be set up, installed, etc.
Nevertheless our OSB components/environment must be prepared for working in cluster environment. We could say that it is not so difficult at all as we put the new server into the Weblogic cluster and the components will be deployed onto the new server as well.


On the picture above our cluster contains seven servers and all the OSB components (proxy services, etc.) are going to be deployed onto every server. It doesn't seem to be a bad idea but we can find out better! Have a look at the next figure:



Why is it better? First of all: this architecture is more flexible, we have got many opportunities to set up the system. Probably the system is going to be quicker too.
However I think I have to explain more detail the diagram above. There are three clusters in this architecture. The cluster C1 uses 4 servers (S4, S5, S6, S7), the cluster C2 uses 3 servers (S1, S2, S3) and the cluster C3 has got 7 servers (S1 - S7).
Let's suppose that we have got 40 proxy services which must be deployed onto the servers. In case of the first architecture there is just one cluster which has got all the servers so we just have to deploy the proxy services onto the cluster and that's it. It is very simple but on the other hand we haven't got any possibility to tune our system. What if we should improve the performance of one service? We can improve the performance of the entire OSB environment by adding new servers as we have got just one cluster. If we have got more clusters which use different servers we should add the new server(s) to that cluster where our service is.
It is important to examine the services and estimate their loading (e.g. how many requests must be served in a day/hour/etc.). We have to find the services which will be heavily used and those ones which are won't. Using the former example 10 of the 40 proxy services are overused the rest of the services are not used so often. We have got 3 clusters so we have options how to arrange the services:

Heavily used services Not often used services
Cluster 1 6 5
Cluster 2 4 5
Cluster 3 0 20

Of course it is not sure that this is the best allocation of the services but this is just an example and the important thing is that WE CAN improve the performance of our OSB environment if it is necessary. What's more we could tune that part of our environment which is really needed to improve so the tuning can be much more effective.

So the base idea is to group the services which must be deployed onto the same cluster. The simplest solution is to do that to create an OSB project for each cluster and put those services into the project which should be deployed onto the cluster. Take a look at the next picture:


There are four projects for the OSB components:
  • cluster_1 : for those services which must be deployed onto the Cluster 1
  • common_components : those artifacts can be put here which might be used in more projects or proxy services (e.g. XSD's, internally used proxy services, etc.)
  • services_COMMON : generally used proxy services
  • business_services : for the business services
I put the business services into a different OSB project as it is possible that one business service will be used by a proxy service that is in Cluster 1 and by an other proxy service that is in Cluster 3. I don't think creating the same business service twice (in the cluster_1 and cluster_3 OSB project) would be a good idea so we have to create it in a separate project.
Considering the future it is better solution to define all the business services in one project and just deploy them to every cluster.

Tuesday, 3 July 2012

Service Facade design pattern in OSB

The Service Facade design pattern is a well-known pattern in Java world. We use it if we want to decouple the business logic and the service interface specifications. We can easily add a new interface to our Java component with the help of this design pattern.
This problem (decoupling the business logic and interfaces) occurs not only in Java components but in case of any middleware components.

Applying this pattern would be vital for our OSB components as well. One of the greatest ability of the OSB is to create middleware components very quickly and easily. However using this design pattern in OSB is not so straightforward at first glance. Please have a look at the next image:


As you can see the service definition is bundled with the message flow. Do we have to copy and paste the message flow if we want to create an additional interface (e.g. for JMS)? Of course we mustn't even think of this solution! The solution is the next:


We have to create a proxy service for the business logic and some other proxy services for the facade interfaces (e.g. if we have to implement a JMS and a webservice interface for our service then we have to create three proxy services).
The only tasks of these facade proxy services are to provide their interfaces and to call the WORKFLOW proxy. We can keep the message flow very simple.


We have to implement the business logic in the WORKFLOW proxy service. The attributes of proxy:
Service type: Any XML Service
Protocol: local
This proxy must be defined as a local service. You can find more information about the local proxies here: http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/local.htm. Now it is enough to know that we can use this type of interface to define common components in OSB.
It is very important that in case of fault we have to use an action 'Reply with Success' otherwise we wouldn't be able to catch the fault in the facade proxy service.

I created the next project/folder structure:



Wednesday, 13 June 2012

Deployment framework

The deployment is a completely different operation than the development. Well I haven't told a big truth... :)
The important statement behind this thought is that usually the developer is not the person who will deploy the components but an other expert who hasn't got any idea about the development and similar stuff so we have to provide a framework for them.

The deployment expert needs the source of OSB components, the environment dependant values (see previous blog) and information about OSB server (e.g. admin user name, password, etc.). They can create an installation package and execute it on the development, test, production, ... server.

What does this installation package consist of? How can it be created? Well this is the reason why we need a framework which can be customized.
The OSB components must be deployed onto different environment:
 - during development we use a local machine or a development server
 - for testing we have to use test servers
 - we deploy the components onto the production servers too
 - ...
In these cases we should get the framework from the version control system, add the source of OSB components to it and customize the property files. This package will be our installation package that we just have to copy to the OSB server or to a computer from where the OSB server is accessible.

And a warning: this is my idea of the deployment framework so it may contain errors or bad ideas. :)

Directory structure

└───deploy_framework
    ├───dist
    ├───env.all
    │   │   build-change.xml
    │   │   change-System.xml
    │   │
    │   └───System
    │       ├───JNDI_Providers
    │       ├───Operator_Settings
    │       ├───Proxy_Servers
    │       ├───SMTP_Servers
    │       └───UDDI
    ├───env.dev
    ├───env.local
    │       build.properties
    │       change.properties
    │       run_all.bat
    │       run_build.bat
    │
    ├───env.prod
    ├───env.test
    ├───libs
    │       xmltask.jar
    │
    ├───scripts
    │       build.xml
    │       import.py
    │
    └───src


dist: The sbconfig.jar (this file will be deployed onto the OSB server) can be found here after building. It will be created by the framework.
env.all: Those settings can be found here which are valid for every environments. They have to be modified on project level but not on a given environment level.
For example: we define here where the OSB component source file should be modified (e.g. XPath definitions).
env.dev: It contains the settings which are valid for the development environment. We can start the deployment onto the development server by executing the file run_***.bat. It may contain the same files as there are in folder env.local.
env.local: It contains the settings which are valid for the local (localhost) environment. We can start the deployment onto the local server by executing the file run_***.bat.
env.prod: It contains the settings which are valid for the production environment. We can start the deployment onto the production server by executing the file run_***.bat. It may contain the same files as there are in folder env.local.
env.test: It contains the settings which are valid for the test environment. We can start the deployment onto the test server by executing the file run_***.bat. It may contain the same files as there are in folder env.local.
libs: JAR files which are needed for the framework.
scripts: Script files (ant, python) which are needed for executing the framework
src: Folder for the source files of OSB components. We have to copy the OSP projects which are in configuration project which we want to deploy and the we have to copy the configuration project itself too.

Property files

The following files must be overridden before the deployment.

Project level settings

build-change.xml: These settings define the values which must be modifed according to the given environment (e.g. we can specify here where the URL of the SMTP server has to be overridden according to value in file changes.properties). These settings must be specified just once. This is an ANT build file in my case. For example:
<project>
    <target name="_change.values">
        <xmltask source="../${env.BUILD_ENVIRONMENT}/tmp/System/SMTP_Servers/EmailServer.SMTPServer" dest="../${env.BUILD_ENVIRONMENT}/tmp/System/SMTP_Servers/EmailServer.SMTPServer">
            <replace path="/xml-fragment/*[local-name(.)='serverURL']/text()" withText="${EmailServer.smtp.Server_URL}"/>
            <replace path="/xml-fragment/*[local-name(.)='portNumber']/text()" withText="${EmailServer.smtp.Port_Number}"/>
        </xmltask>
        ...
    </target>
     ...
 </project>

Environment dependant settings

build.properties: These settings are needed for creating the sbconfig.jar and deploying it onto the server. An example:
middleware.home=E:/Oracle/Middleware
osb.home=${middleware.home}/Oracle_OSB1
wls.username=weblogic
wls.password=weblogic1
wls.server=t3://192.168.1.156:7001
config.project=All-ConfigurationProject
config.jar=E:/work/MAVIR/SOA/deploy/dist/sbconfig.jar
config.subprojects=CommonResources,EmailManager
config.includeDependencies=true
workspace.dir=e:/work/MAVIR/SOA/deploy/src
import.project= None
import.jar=E:/work/MAVIR/SOA/deploy/dist/sbconfig.jar
import.customFile=None

changes.properties: Defining the values which must be written in the OSB source files (e.g. endpoint URLs, usernames, passwords, etc.).
EmailServer.smtp.Server_URL=mailserver.acme.hu
EmailServer.smtp.Port_Number=25
...

run_***.bat: We can start the build/deploy by this scripts.
@ECHO OFF
rem ******************* this value mut be modified *******************
set FMW_HOME=E:\Oracle\Middleware
rem ******************* this value mut be modified *******************
set OSB_HOME_VALUE=Oracle_OSB1
set ANT_HOME=%FMW_HOME%\modules\org.apache.ant_1.7.1
set PATH=%ANT_HOME%\bin;%PATH%
set JAVA_HOME=%FMW_HOME%\jdk160_18
set CLASSPATH=%FMW_HOME%/wlserver_10.3/server/lib/weblogic.jar;%FMW_HOME%/%OSB_HOME_VALUE%/lib/alsb.jar;%FMW_HOME%/%OSB_HOME_VALUE%/modules/com.bea.common.configfwk_1.3.0.0.jar;..\libs\xmltask.jar
SET BUILD_ENVIRONMENT=env.dev
call ant -buildfile ../scripts/build.xml download build change deploy -verbose
pause



We can build and deploy the OSB components automatically by executing the script run_all.bat. It is possible to create the file sbconfig.jar only by executing the script run_build.bat and deploy it manually.

Saturday, 26 May 2012

Deploying OSB components onto different environments

Each OSB expert has already faced the problem of deployment. This task seems to be pretty obvious at first glance but it is quite sophisticated if we dig into the details.
There are many values in the OSB components which are different in each environment (local / development / test / ... / production server). We would like to use the same sourcecode to deploy it into the test server or production server, we want to use a CI tool so it is not possible to use constant values in the source.

The customization file could be a perfect solution for this job ... but it is not. At least it was not the best solution to me.

Let me explain it: I had to send an email in a proxy service. The receiver of the email must be different in the production, the test and the development environments (it is obvious as we wouldn't like to send emails to the business users during tests...). I set the receiver of the email in the message flow by modifying the the Transport Header. We cannot modify this value by the help of the Customization File.
Other example is to change the port number of the SMTP server (you can change the endpoint URL of the SMTP server but not the port number which is a separate property of SMTP server).
There are a lot of other examples too where the Customization File fail so I had to find an other solution to change the values in the proxy services.

Unfortunately I could find any other solution (OSB 11.1.1.3.0) how to change these values. I could work out just one solution: change the XML file of proxy service. It seems to be a sophisticated (or tough ...) solution but you can get used to it. :)
An XML file is created when you produce a proxy service. All you need to do is to find the value in the XML that you want to change and create an XPath to find it in the XML. Afterwards you can change the value with an ant task for example. Unfortunately this is not so easy either...

The first problem is that we don't want to modify the files in the source folder of our local machine. Let's imagine your workspace is in C:\work\OSB\workspace (apologize to the Linux users :) ). You are using your workspace for deploying OSB components into your local OSB domain so I don't think that you'd want to mess that folder.
Besides we need a JAR file as a result with all the environment dependent modifications and we just want to deploy it onto the given domain (see Continuous Integration).
So this is my scenario:
  1. create a deployable JAR file
  2. unzip the JAR file into a temporary folder
  3. change the values according to the given environment
  4. create the JAR files from temporary folder
I used this ANT task at the first step:

<target name="build">
  <delete failonerror="false" includeemptydirs="true" dir="${metadata.dir}"/>
  <java dir="${eclipse.home}"
        jar="${eclipse.home}/plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar"
        fork="true" failonerror="true" maxmemory="768m">
    <jvmarg line="-XX:MaxPermSize=256m"/>   
    <arg line="-data ${workspace.dir}"/>
    <arg line="-application com.bea.alsb.core.ConfigExport"/>
    <arg line="-configProject ${config.project}"/>
    <arg line="-configJar ${config.jar}"/>
    <arg line="-configSubProjects ${config.subprojects}"/>
    <arg line="-includeDependencies ${config.includeDependencies}"/>
    <sysproperty key="weblogic.home" value="${weblogic.home}"/>
    <sysproperty key="osb.home" value="${osb.home}"/>
    <sysproperty key="osgi.bundlefile.limit" value="500"/>
    <sysproperty key="harvester.home" value="${osb.home}/harvester"/>
    <sysproperty key="osgi.nl" value="en_US"/>
    <sysproperty key="sun.lang.ClassLoader.allowArraySyntax" value="true"/>
  </java>
</target>

Performing the second step wasn't very difficult:

<unzip src="${config.jar}" dest="../${env.BUILD_ENVIRONMENT}/tmp"/>

There are more ways for modifying the values unfortunately I chose an inconvenient and sophisticated one. :)

<target name="_change.values">
  <xmltask source="../${env.BUILD_ENVIRONMENT}/tmp/System/SMTP_Servers/EmailServer.SMTPServer" dest="../${env.BUILD_ENVIRONMENT}/tmp/System/SMTP_Servers/EmailServer.SMTPServer">
    <!-- change email server URL -->
    <replace path="/xml-fragment/*[local-name(.)='serverURL']/text()" withText="${EmailServer.smtp.Server_URL}"/>
    <!-- change email server port number -->
    <replace path="/xml-fragment/*[local-name(.)='portNumber']/text()" withText="${EmailServer.smtp.Port_Number}"/>
  </xmltask>
  ...

And I created a properties file and I defined the values.

EmailServer.smtp.Server_URL=XXXXXX
EmailServer.smtp.Port_Number=25

Creating a JAR file is easy too:

<jar destfile="${config.jar}" basedir="../${env.BUILD_ENVIRONMENT}/tmp"/>

Unfortunately I had to implement a 2.1 and 2.2 step as well... When the JAR file was created by the Weblogic ANT task the Configuration Project level resources (e.g. SMTP server) weren't put into the JAR. I don't know it was a problem of the ANT task or I made something badly (but of course it is less likely...:) ).
So I had to copy some folders (see below) into the JAR by the help of ANT and modify the ExportInfo file into the JAR too.


UPDATE
I uploaded my deploy framework that I used to deploy the components, please let me know if you have any issue.

Wednesday, 23 May 2012

The beginnings... - how to organize OSB components

To create and support an OSB platform is not an easy task. Ok it might be more precise to say "it is hard and very difficult". I think I have told nobody a great truth...

You have to address and find good solutions for the next problem domains:
  •  design
  •  develop
  •  deploy
  •  monitoring
  •  management
And we have arrived already ... this is SOA Governance for OSB. But I don't want to begin with this topic now so let's start with the basics: how to desing.

I would like to refine the topic above not how to design but how to make a structure  for OSB components. It doesn't seem to be important but believe me it is! If You've got a lot of services on OSB and You haven't got a well-defined vision about how to arrange your services then ... well You will go crazy after a while.

Let me tell You an example. Suppose that You've got a virgin OSB and You have to develop and deploy a proxy service which will poll an email server. It will send the content of attachment of incoming email to a system via webservice. This email is sent by your customers and contains their orders.
We would think 'it is no problem let's create a folder name it as EmailService and put the OSB proxy service into it'. It is a "good" solution it will work.
After some days our boss will find out to process emails coming from our suppliers using OSB. Perfect, we've got a folder for services polling emails let's put this new proxy services into it as well. Then we have to receive orders from our customers via webservice. And here is the real dilemma: we need to create an other folder for this proxy services? But these two services (receiving orders from customers via email and webservice) belong to the same client... Should we create a new folder and name it as CustomerServices? And there is an other trick here. These services mustn't belong to the customer because the customers here are just the clients of services, the Order Management System must own these services.
I would like to clarify this problem, check the next figure:


As You can see multiple clients try to use the same OSB service so the the service must belong to the Order Management System.
If we consider this idea we will realize that in this aspect the OSB is a part of the source system. Ok it sounds strange but have a look at the next figure:


The OSB is transparent for the clients they just want to call the services of the Order Management System. The OSB can extend the possibilities of the source system so the clients can access it via new protocols, other data structure and so on.

This is my vision about the structures of OSB components:
 
* services_OrderManagementSystem (folder)
       * atomic (folder)
              * order (folder)
                     * webservice (folder)
                            * business (folder)
                                   - BS (business service)
                             * proxy (folder)
                                   - PS (proxy service)
       * domain (folder)
              * order (folder)
                     * email (folder)
                             * proxy (folder)
                                   - PS (proxy service)

* services_UnknownSystem (folder)
       * atomic (folder)
              * unknown_business_logic (folder)
                     * webservice (folder)
                            * business (folder)
                                   - BS (business service)
                             * proxy (folder)
                                   - PS (proxy service)

The systems of the company are on the top level of directory structure. Other name conventions can be used on top level as well e.g. the name of business areas (CRM, billing and so on) but for me it was the best one. As You can see on the figure below these are Oracle Service Bus projects and not folders.
On the second level: Is the service an atomic or domain service?  And what is the difference between atomic and domain services? The simple answer is the complexity. I mean if You want to pass the incoming request to the source system and don't want process it this is an atomic service. But if You need to do something with the input data this is a domain service (e.g. if You have to do protocol transformation then the service mustn't be atomic). It depends on You which one is an atomic or a domain service and actually whether You need this level or You don't.
Third level: I think the services must be distinguished by business logic.  In this sample the client can send orders to source system with the OSB components and it means we use this service managing orders.
The fourth level is the protocol. It can ease the navigation in OSB You can easily find the service which You need.
Last level: the proxy and business services must be put into different folders.


It is up to You to use the levels otherwise. For example change the second and third level because it better for your requirements.

So this is my pattern how to organize the OSB components. It helped me a lot not to get confused.

UPDATE1
********
Nobody can be  experienced enough... :)

So if your services are heavily used (100.000 hits / day) then usually you have to deploy these services onto different services (I am not talking about cluster. In case of clusters all the services can be found on each managed servers.
For example you have got 5 services and 2 of 5 services are on the cluster 1 (which consists of more managed servers) and the remaining services are on cluster 2).

In this case you have to group the services and deploy them onto different servers (if you are using the grouping above you can deploy all the services in a OSB project onto only one server).
It is more reasonable to group services according to your cluster structure. What I mean is:

You want to deploy serviceA and serviceB onto cluster1 and serviceC, serviceD and serviceE onto cluster 2 then:

* cluster_1
       * service_A
       * service_B
* cluster_2
       * service_C
       * service_D
       * service_E

My original idea about grouping is correct if your services are not heavily use and you want to keep together your services in a cluster. However if some of your services are overused then you should think about deploying your services individually.

Friday, 3 February 2012

How to design? - the performance of OSB

What factors do we have to take into consideration in the design phase or architecture planning to ensure the best performance of OSB? I am sure that I won't be able to give a complete answer for this question but just some tricks or thoughts. Not because I don't want to but simply I just don't have suffice knowledge. :)

The performance is important for any system but for the OSB it is really vital. As I mentioned earlier the OSB seems to be a gateway between two or more systems (we know it is not just a gateway but if we consider a communication between 2 systems then it seems to be).
The data don't just flow through the OSB (this is true even if we are thinking of the simplest message) but the OSB parses the the requests/responses XML messages, logs the events, handles some inner handler components (e.g. What to display on the OSB console), save data into the OSB management database and so on. These operations take time and resources.

So we can say that the communication is quicker without than with OSB... This is a hard conclusion but take a look at the next figure:


It is clear that the second communication is quicker than the first one. But the situation is unambiguous if we are talking about pure network communication (e.g. webservice calling).
I know that the mission of OSB is not to accelerate the communication (it can do it in some cases as we will see soon) but I am going to examine the performance factor in this blog.

The business services in OSB can handle a lot of protocols and even we can use many adapters of the Oracle SOA Suite. Using these adapters might be more effective than how any system could handle the communication. So it is more useful to use the OSB to connect two systems than you should develop a new communication way (e.g. 'system A' has to send data to 'system B' but 'system B' can receive data via email so you should develop an email sending module into 'system A').

We can use the Oracle Coherence to cache static data on OSB. If we are sure that the source system sends back static data (not transactional data but product code or date of birth of people) then the OSB (with Oracle Coherence) can send back these information directly without using the source system. Take a look at the next figure:


The OSB (Oracle Coherence) can serve multiple client requests without using the source system. For the first time (when any of clients send its first request) the cache has to be filled. It means that OSB needs to call the source system and put the result from the source system to the cache. Later the cache will call the source system when it must refresh its data (the frequence of the refresh can be set).
We can disencumber the source system with OSB's help so the performance of communication can be optimized as well. We should be careful how we use Oracle Coherence. I mean how often do we have to refresh the cache, which services should we mock with Coherence and so on.

We can protect the source system against overwhelming it with requests. We can limit the number of requests by the throttling function of OSB. This is an attribute group of business services.

Other important possibility of OSB is to alert if there is problem with some services of source systems. We can define SLA alerts for business services and indicate if the service stopped working. We can assign operations to these alerts for sending emails, logging and so on.
Moreover we can assign these SLA alerts to throttling metrics as well so we can predict events (OSB can notify us that a service can serve less requests now than earlier).

The service bus can analyze the request and route it to different systems according to the request parameters. For example there is a date parameter in the request of a query service and if the difference between the actual date and this date is greater than 6 months then the OSB has to call the service of the data warehouse but if it is less then the service bus has to use the service of the transactional system.
And there are a lot of other tricks as well...

And I don't want to talk about how much time and money You can save to use the OSB (considering the cost of starting a new project in a legacy system...). But we are discussing about the performance topic.
You can improve the performance by considering :
- the efficiency of the message flows
- the configuration of OSB
- the configuration of Weblogic

The message flow must be as simple as possible. You mustn't put any unnecessary steps into the message flow as it might slow down the service.
If You have to call administration services (e.g. logging) then You should use asynchronous calls (if possible) not to bother the main message flow. In case of asynchronous call there is not response so the message flow doesn't have to wait for it.
You should consider how many times the service must be called (in case of an error) and how much time the message flow must wait between two calls. You must set the attributes of business services very carefully.
Other effective trick is to use split-join to execute multiple tasks in parallel.

Sunday, 9 October 2011

How to design? - the message flow

Message flow


How to model the message flow? The best answer to this question is it must be as simple as possible. Why? Consider that the OSB is the center of the communication. If we just consider the performance of the network then the OSB seems to be unnecessary as this is just a new station between two systems. It may slow down the communication (Ok we know the OSB is a very important IT platform of the company).

The message flow must be quick and contains the least steps. Of course we have to be concerned with some basic things as error handling and monitoring. But we have to put these logics into the message flow not to disturb the main workflow (e.g. At the beginning of each proxy services we have to call a monitoring system. To consider the conclusion above we have to make an asynchronous call to monitor system not a synchronous one).

It is very important to understand that the OSB is not a business workflow engine. You mustn't implement this kind of logic in the message flow. And the next question is evident: What should we consider the business logic? The answer is difficult. You have to think of the OSB as a funnel. You (the client) fill something (e.g. milk) on the one side and You (the server system) get the same (milk) or other (chocolate milk) thing. But You don't do anything just fill! Ok, I think it is enough of the metaphors... :)
Usually the proxy services use just one source system (business service). The OSB service can modify the requests / responses, change the protocol, add some basic functionalities and so on. If You should use more source systems in the proxy service You have to consider to implement it in a workflow engine. If You haven’t got such an engine You can develop enterprise services in the OSB.

To decide what You may put into the OSB depends on your actual IT possibilities as well. If You have got a BPEL engine then You can take out easily the logic which is complicated to implement in the OSB. But if your the company has got just the OSB (and not BPEL engine)... well in this case we can't put this workflow into a non-existent workflow engine. It is sad to say but You don't have any other chance just to implement these logics into the OSB (if the tools of the OSB are sufficient for this...).

The OSB enterprise service use more systems not just one. They are built on the existing services of the company systems but they seem to be new ones. You have to find out the requests/responses, the message flows and how to transform or summarize the results of the called systems. So these ones are the so called enterprise services which are brand new services in the IT platform of the company.

Every message flow is different but there are similar / general parts. We have to find these high level parts to develop the message flow easier. Check the next figure:

I would like to emphasize this is my vision about the basic parts of the message flow. There could be a lot of other area which I haven't met yet and could change the figure above so forgive me if this is not the complete picture. :) If you have got any idea about what to change please write me!

Monitoring
So the first step is the monitoring. I illustrated this with dotted line which means that I don't think this step is compulsory in each cases. This step is necessary in those cases if the proxy service is an asynchronous service. For example if You receives an email and an error occurs then usually it is not reasonable or there is not any chance to send back an email about the error to the sender. Or in case of FTP we should send back a file...?
But it is rarely informative to monitor if a synchronous service is called. The monitoring funcionality is belong to the client in this case not to the OSB. But if we consider an asynchronous service this is the task of the OSB. You should monitor as much information as possible (of course it depends on the possibilities of the monitoring system as well).

Check the incoming data
It is very very essential to check the incoming data before using them (e.g. to send to source system). Here there is a good chance to use the OSB: we can disencumber the source system. It is absolutely unnecessary to call the source system if there is no chance for a successful execution. Usually we have got two tasks to do in this step:
  1. to validate the data
    We know the expected structure of the data so the validation of the incoming data can be performed. We have an easy task in case of webservice (the structure is determined in the WSDL) but in the case of other protocols the structure is discovered in the phase of business design already. Usually we use scheme to validate but other validation logic can work as well (e.g. in case of text files).
  2. to check if any necessary information is available
    We have to examine if we have got all the data to call the source system. For example: if we develop a service to send an email and we doesn't receive the email address then we have to raise an error to the client. Of course we can handle these cases with the XSD as well but there might be situations when we have to check this without the help of the XSD (e.g. the XSD mustn't be modified).
Transform the incoming data
After we checked the incoming data sometimes we have to transform it. What I mean to transform? Just remember, an important usage of the OSB is to play a gateway role between systems. For example if the CRM system wants to communicate to the billing system and they have got different data structure then it should mean some development works in one of the systems. But it doesn't because You can make the conversion in the OSB! The costs might be lower as if You should start a development project in a legacy system...
When I am talking about conversion I mean XQuery transformation which is a powerful tool to transform an XML to an other one. If the source is not an XML then You have to develop individual solutions. If You should change the namespace of tha XML only then You could use the action 'Rename'.

Create the request for calling the source system
To call a system we need a request message. How to create the request depends on the protocol (I won't specify all of them but the more important ones for me):
- Webservice
We have to create a SOAP message. We have to set the body part of the message and occasionally the SOAP header. Usually we use the header to set the security (e.g. OASIS security or custom solutions).
We have already produced the data to send before this step so we just have to put it into the SOAP body. Sometimes we have to add some tags to the XML. To be clear have a look at the next sample request  for the header part:
<soap-env:Header xmlns:ws="http://ws.billing.acme.com/">
    <ws:username>...</ws:username>
    <ws:password>...</ws:password>
</soap-env:Header>
and for the body part:
<ws:receiveOrder xmlns:ws="http://ws.billing.acme.com/">
    <ws:Container>
        {$incomingTransformedData}
    </ws:Container>
</ws:receiveOrder>
At the first sample we use custom security solution, we put the user and password into the SOAP header. At the second sample we have produced the variable 'incomingTransformedData' already in the previous step so we create the SOAP body and put this data into it.
- Email
To send an email you have to use the action 'Transport Header'. You can set the email address of the sender and receiver and the subject (and a lot of other things as well...). The content of the email has to be put into the internal variable 'body' when you use the action 'Routing' or 'Service Callout'. It can be any text or XML but it depends on the mail system.
If you want to send attachment as well then you have to insert a similar XML to the internal variable 'attachments':
<con:attachment xmlns:con="http://www.bea.com/wli/sb/context">
    <con:Content-Type>application/octet-stream</con:Content-Type>
    <con:Content-Disposition>attachment; filename="{$fileName}"</con:Content-Disposition>
    <con:Content-Transfer-Encoding>base64</con:Content-Transfer-Encoding>    
    <con:body>{$fileContent}</con:body> 
</con:attachment>
- FTP
You have to use the action 'Transport Header' in this case as well. The name of the file which will be sent through FTP can be set in the property 'fileName'. You can set the FTP endpoint dynamically with the action 'Routing Options'. And again you have to put the content of file into the internal variable 'body'.
- any Java serviceYou can call a service of a Java service (e.g. session bean) directly from the OSB. The key is the action 'Java Callout'. If you have got the client (proxy) java classes of the session bean in a JAR file and put to the classpath of the OSB then You can use them in the action 'Java Callout'. This is a simple but not too elegant possibility to use a Java service in the OSB.
You can reach an EJB3.0 service directly from the OSB but this is true only the EJB3.0 services.

Call the source system
To call a system you have got two possibilities: routing or service callout / publish. If you need to execute some steps after calling the system then You have to use service callout / publish (first one is for sync. services, second one for async. ones).
You have to pay attention for the error handling. To thow the exception to the client or catch them? I will deal these questions later in another blog.
You have to be concerned with the parameters (e.g. retry interval, retry count) of the calling. If you don't set the values of these parameters prudently then it can cause an unnecessary bottleneck. The attibute 'Retry Application Errors' of the business services is such a parameter as well (why try again if the source system sent back a response?).


Transform the response of the source system
This step is similar to step 'Transform the incoming data'. This step is unnecessary if the proxy service is an asynchronous service or there is no need to transform the data.


Create and send back the reponse
If our proxy service is synchronous then we have to send back a resposne to the client. If the source system synchronous as well then we send back its response to the client. If it is asynchronous then we have to create a reponse to send back. Usually these reponse are not complicated just a sign that the execution of the operation was correct.