Wednesday 19 October 2016

Get the hostname of the executing server in BPEL

This week I got involved in a question on the Oracle Forums on getting the hostname of the server executing the bpel process. In itself this is not possible in BPEL. Also if you have a long running async process, the process gets dehydrated at several points (at a receive, wait, etc.). After an incoming signal, another server could process it further. You can't be sure that one server will process it to the end.

However, using Java, you can get the hostname of an executing server, quite easily. @AnatoliAtanasov suggested this question on stackOverflow. I thought that it would be fun to try this out.

Although you can opt for creating an embedded java activity, I used my earlier article on SOA and Spring Contexts to have it in a separate bean. By the way, in contrast to my suggestions in the article, you don't have to create a separate spring context for every bean you use.

My java bean looks like:
package nl.darwinit.soasuite;

public class ServerHostBeanImpl implements IServerHostBean {
    public ServerHostBeanImpl() {
    public  String getHostName(String hostNameDefault){
        String hostName;
            InetAddress addr;
            addr = InetAddress.getLocalHost();
            hostName = addr.getHostName();
        catch (UnknownHostException ex)
            System.out.println("Hostname can not be resolved");
            hostName = hostNameDefault;
        return hostName;

The interface class I generated is:
package nl.darwinit.soasuite;

public interface IServerHostBean {
    String getHostName(String hostNameDefault);

Then I defined a Spring Context, getHostNameContext, with the following content
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="" xmlns:util=""
       xmlns:jee="" xmlns:lang=""
       xmlns:aop="" xmlns:tx=""
       xmlns:sca="" xmlns:xsi=""
       xsi:schemaLocation=" META-INF/weblogic-sca.xsd">
    <!--Spring Bean definitions go here-->
    <sca:service name="GetHostService" target="ServerHostBeanImpl" type="nl.darwinit.soasuite.IServerHostBean"/>
    <bean id="ServerHostBeanImpl" class="nl.darwinit.soasuite.ServerHostBeanImpl"/>

After wiring the context to my BPEL the composite looks like:

Then, deploying and running it, gives the following output:

Nice, isn't it?

No comments:

Post a Comment