Provision Web Services applications using Fabric

In this tutorial we will learn how to provision a blueprint project on Fabric, creating some containers to run the bundle.

In the first tutorial we have covered how to expose Web Services using a Camel Route and proxy the invocation to a legacy Web service running on EAP 6: Proxy Web services request with Camel

In the second tutorial we have exposed the Web service as an OSGi bundle on JBoss Fuse: Mediate Web Services request with JBoss Fuse

Now we can move one step forward by provisioning a child Containers on Fabric8 to run this example.

Fabric8 is an integration platform based on Apache ActiveMQ, Apache Camel, Apache CXF, Apache Karaf, Hawtio and others.It provides automated configuration and deployment management to help make deployments easy, reproducible, and less human-error prone.

By default, Fabric8 starts up with a default admin user with username admin and password admin. This can be changed by editing the etc/users.properties file before starting fabric for the first time.

admin=admin,admin

then start JBoss Fuse as usual:

./fuse

You will need to create a Fabric as first operation

JBossFuse:karaf@root> fabric:create --zookeeper-password admin  

Next you will need to create a Profile, which is a collection of features (such as libraries), configuration files and more. Out of the box some default profiles are included, we will create a custom profile names custom-profile which contains the features needed to run our example. From the karaf shell execute the following commands:

JBossFuse:karaf@root> fabric:profile-create custom-profile
JBossFuse:karaf@root> fabric:profile-edit --features camel-cxf custom-profile
JBossFuse:karaf@root> fabric:profile-edit --features camel-blueprint custom-profile

Done with the profile, we will create a child Container named child1 where we will provision our application. The container will use our custom-profile just created:

JBossFuse:karaf@root> fabric:container-create-child --profile custom-profile root child1

Great. Now let's get back to our project discussed in tutorial 2: Mediate Web Services request with JBoss Fuse

The only change in the blue print XML file will be the Apache CXF Web service facade, which will not be bound to a specific port or IP address, but will inherit this information from your container:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
    xmlns:cxf="http://cxf.apache.org/blueprint/core"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
             http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

  <cxf:bus><!-- interceptor per request/response del ws/rest -->
    <cxf:features>
      <cxf:logging limit="1024"/>
    </cxf:features>
  </cxf:bus>
  <bean id="beanAdapter" class="com.sample.source.ws.BeanAdapter"/>

  <!-- WEB SERVICE FACADE -->
  <camelcxf:cxfEndpoint id="input-cxf" address="/example-input-cxf/"
                        serviceClass="com.sample.source.ws.FuseExampleCXF"/>

  <!-- TARGET WEB SERVICE -->
  <camelcxf:cxfEndpoint id="SimpleWebSevice"
        address="http://localhost:8080/webserviceslegacy/LegacyWebServiceImpl" 
                    wsdlURL="http://localhost:8080/webserviceslegacy/LegacyWebServiceImpl?wsdl"                    
                    serviceClass="com.sample.target.ws.LegacyWebService" />
 
  <camelContext id="example-cxf" xmlns="http://camel.apache.org/schema/blueprint">
    <route id="input-cxf">
      <from uri="cxf:bean:input-cxf"/>
      <transform>
        <simple>
          ${in.body[0]}
        </simple>
      </transform>
      <log message="Message input: ${in.body}"/>
      <transform>
                <method bean="beanAdapter" method="transform"  />
      </transform>
            
      <removeHeaders pattern="*"/>
        <to uri="cxf:bean:SimpleWebSevice" />
      </route>
  </camelContext>

</blueprint>

Now re-build your project and prepare to deploy in on fabric8:

mvn clean install

Move to the karaf shell and upgrade your profile with the maven project:

JBossFuse:karaf@root> fabric:profile-edit -b mvn:it.fuse.demo/fuse-demo/0.0.3-SNAPSHOT custom-profile

You can check from the Web console (located at localhost:8181) for the list of Containers available:

fabric8 tutorial

By clicking on the Container link, you can check the active services:

fabric 8 tutorial

The Container child1 has been assigned the virtual IP address 192.168.1.67:8182, hence the WSDL of the Web service is available at the following address:

http://192.168.1.67:8182/cxf/example-input-cxf?wsdl

You can check out using SOAPUI or any other Web service client that the Web service responds and the route camel forwards the call to the target Web service.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.source.sample.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:count>
         <arg0>
            <a>1</a>
            <b>2</b>
         </arg0>
      </ws:count>
   </soapenv:Body>
</soapenv:Envelope>

You should expect as return a response with the sum of the two parameters of the Wrapper object:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:countResponse xmlns:ns2="http://ws.source.sample.com/">
         <return>3</return>
      </ns2:countResponse>
   </soap:Body>
</soap:Envelope>

 


Advertisement

Cookie Alert