Pages

Friday 26 October 2012

Fuse ESB Installation

In Fuse ESB Installation ,I am going to show the setup of  Fuse ESB (apache-servicemix-4.4.1-fuse-06-03). for getting to deploy the bundle,Apps,etc.


Fuse ESB: Fuse ESB is an open source integration platform based on Apache ServiceMix that supports JBI and OSGi for use in enterprise IT organizations.

Setup and Installation:
 Prerequisite
Ø  JDK 1.6+
Ø  Apache-servicemix-4.4.1-fuse-06-03
Ø  apache-maven-3.0.4
                    
Structure of Fuse ESB: FuseESB Zip has folder this folder structure.
Ø  {fuseESB_Install}/bin à  executable files
Ø  {fuseESB_Install}/deployà Used to deploy bundles
Ø  {fuseESB_Install}/data à  runtime files
Ø  {fuseESB_Install}/etc à configuration  files

Step of setup:
  •       Download FuseESB Zip (http://www.redhat.com/fusesource/downloads/)
  •       Unzip Fuse ESB apache-servicemix-4.4.1-fuse-03-06
  •       Run the fuse esb server from command prompt of {fuseESB_Install}/bin/servicemix.bat folder. Then you can see the shown screen shot succes  fully start FuseESB server.

  •      Create App,OSGI bundle ,WAR or JBI bundle.
  •       Copy the osgi/jbi bundle in the {fuseESB_Install}/deploy folder of the fuse esb.
  •       Bundle will be deployed.
  •       If you deployed the OSGI http service then you can see the services in http://{host}:{port}/cxf(http://localhost:8181/cxf)
       Using the Web Console:
  Apache Karaf web console provides a graphical overview of deployed bundle and services on Fuse ESB.
 For the Web Console of Apache karaf we need to do some step:

Run the command on karaf:  features:install webconsole

Accessing the web console
By default, the console runs on port 8181. You can change the port number by creating the properties file, etc/org.ops4j.pax.web.cfg, and adding the following property setting (changing the port number to whatever value you want):

org.osgi.service.http.port=8181


To access the console for an instance of Fuse ESB running locally, enter the following address in your web browser:


http://localhost:8181/system/console( http://{host}:{port}/system/console
).




Log in with the username smx and the password smx.


  

Also, We can manage the life cycle of bundle and feature management through web console.We can use these thing from apache karaf web console.
  •       Install and uninstall features
  •       Stop, start, and uninstall bundles
  •     Create new instances of Fuse ESB
  •     Configure your Fuse ESB instance
  •     View logging information


Fuse ESB Command:
Fuse ESB provide the command for feature installation, managing deployed bundle,monitoring  and View logging information, etc.
Example:
features:list
features:uninstall [name]
osgi:uninstall [id]
osgi:list -->list all bundles

We can see all the command of fuse esb by click the TAB on Karaf Console.
Also, you can see in the screen shot below.



       

Thursday 25 October 2012

Contract First or WSDL First Web Service (Top-Down Approach)

In the Contract first approach, we take first like schema, wsdl contract creation and followed by business logic of service in code, therefore in the contract first approach, the focus is creating schema associated with wsdl. WSDL and Schema has to define message format, operations, interface name and other information for the web service. After creating the WSDL and schema, we can create service from wsdl/schema using some web service framework. All major Web service frameworks allow service generation from WSDLs, and the all Service code is generated by the service framework, only the necessary business logic would need to be writing in Implement Class.

Contract First Web Service:
Contract first web Service,we need to follows the step

1-First write a schema  xsd and wsdl file.
2-Generate Interface and other code using service engine from wsdl.
3-Add business logic of service interface Implementation.
4- Expose interface with business logic as web services.
5-Service would be available for client,We can use Soap UI tool or other tools for client.

POC of Contract First Web Service:
I have been going to be create Contract first web service using Eclipse IDE and Apache CXF Service Framework.
So we need eclipse with Apache CXF engine.
For setup of eclipse for web service creation, you can refer my previous blog "Code First",URL is http://dtechtalkcenter.blogspot.in/2012/10/creating-code-first-web-service-bottom.html

Create a Dynamic Web Project:

Project Name:  ContractFirstService
Target Runtime:  tomcat 7          
Configuration:  Click on modify button and select check box of Apache CXF.


Designing XSD schema:
I create a simple xsd schema(productservice_schema.xsd) with two requests like addProduct and getProduct with respective response addProductResponse and getProductResponse.Also define the Product object in xsd.

<?xml version="1.0" encoding="utf-8"?>
<!--Define the document element first -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://service.dtechtalkcenter.com/" elementFormDefault="unqualified" targetNamespace="http://service.dtechtalkcenter.com/" version="1.0">
<!--Define the element first like addProduct,addProductResponse and getProducts,getProductsResponse -->
<xs:element name="addProduct" type="tns:addProduct"/>
<xs:element name="addProductResponse" type="tns:addProductResponse"/>
<xs:element name="getProducts" type="tns:getProducts"/>
<xs:element name="getProductsResponse" type="tns:getProductsResponse"/>

<!-- getProducts complex type -->
<xs:complexType name="getProducts">
    <xs:sequence/>
  </xs:complexType>

  <!-- getProductsResponse complex type and return type is product-->
<xs:complexType name="getProductsResponse">
    <xs:sequence>
      <xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="tns:product"/>
    </xs:sequence>
  </xs:complexType>
  
 <!-- product complex type and The element of product object type are cast,productCategory,productDetails and productName are double,-->
<xs:complexType name="product">
    <xs:sequence>
      <xs:element name="cast" type="xs:double"/>
      <xs:element minOccurs="0" name="productCategory" type="xs:string"/>
      <xs:element minOccurs="0" name="productDetails" type="xs:string"/>
      <xs:element minOccurs="0" name="productName" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

  <!-- addProduct complex type -->
<xs:complexType name="addProduct">
    <xs:sequence>
      <xs:element minOccurs="0" name="product" type="tns:product"/>
    </xs:sequence>
  </xs:complexType>

    <!-- addProductResponse complex type and there is no return -->
<xs:complexType name="addProductResponse">
    <xs:sequence/>
  </xs:complexType>
</xs:schema>

Service Contract OR WSDL Designing:
WSDL file is generally defined as service contract.So I have created a wsdl document(productserviceimpl.wsdl) with two operation getProducts and addProducts.

<?xml version="1.0" encoding="UTF-8"?>
<!--DOCTYPE wsdl:definitions PUBLIC "  give serviceName,targeNameSpace and diffrent nameSpace like wsdl,soap,schema etc.-->
<wsdl:definitions name="ProductServiceImplService" targetNamespace="http://service.dtechtalkcenter.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://service.dtechtalkcenter.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">

  <!-- import the schema in the wsdl:type tag -->
  <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://service.dtechtalkcenter.com/" schemaLocation="productservice_schema.xsd"/>
</schema>
  </wsdl:types>

  <!-- We define the addProduct request message, which gets used in the portType(ProductService) and The addProduct request type is defined in the schema. -->
  <wsdl:message name="addProduct">
    <wsdl:part name="parameters" element="tns:addProduct">
    </wsdl:part>
  </wsdl:message>

  <!-- We define the getProducts request message, which gets used in the portType(ProductService) and The getProducts request type is defined in the schema. -->
  <wsdl:message name="getProducts">
    <wsdl:part name="parameters" element="tns:getProducts">
    </wsdl:part>
  </wsdl:message>

  <!-- We define response of respective request -->
  <wsdl:message name="getProductsResponse">
    <wsdl:part name="parameters" element="tns:getProductsResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="addProductResponse">
    <wsdl:part name="parameters" element="tns:addProductResponse">
    </wsdl:part>
  </wsdl:message>

  <!-- We define the ProductService Interface port type, which gets used in the binding. -->
  <wsdl:portType name="ProductService">
    <wsdl:operation name="getProducts">
      <wsdl:input name="getProducts" message="tns:getProducts">
    </wsdl:input>
      <wsdl:output name="getProductsResponse" message="tns:getProductsResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="addProduct">
      <wsdl:input name="addProduct" message="tns:addProduct">
    </wsdl:input>
      <wsdl:output name="addProductResponse" message="tns:addProductResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  
  <!-- We use a document/literal style and The literal http://schemas.xmlsoap.org/soap/http signifies a HTTP transport. -->
  <!-- We define the ProductServiceImplServiceSoapBinding binding, which gets used in the port.. -->  
    <wsdl:binding name="ProductServiceImplServiceSoapBinding" type="tns:ProductService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getProducts">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="getProducts">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="getProductsResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="addProduct">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="addProduct">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="addProductResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

  <!-- The http://localhost:8080/ContractFirstService/services/ProductServiceImplPort address is the URL where the Web service can be invoked. -->
  <wsdl:service name="ProductServiceImplService">
    <wsdl:port name="ProductServiceImplPort" binding="tns:ProductServiceImplServiceSoapBinding">
      <soap:address location="http://localhost:8080/ContractFirstService/services/ProductServiceImplPort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Generate Service From WSDL Document:
Just we need to right click on the project and select web service from eclipse wizard.
Web Service Type:  Top down Java Bean web service
Service definition : Select wsdl document like productserviceimpl.wsdl
Select Service runtime : apache CXF
then click next.


Select Apache CXF here and click on ok default Axis is selected.


Then Click on next button of web services wizard and select different option
Output directory :  \ContractFirstService\src
Package Name :  com.dtechtalkcenter.service
select the check box of Specify  wsdl.....and click finish button.



Now service is generated with java code from wsdl and deployed service.

Add business logic:
Generated code through the wsdl in show screen shot below.


Added business logic of service interface implementation 


/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package com.dtechtalkcenter.service;

import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 * This class was generated by Apache CXF 2.6.2
 * 2012-10-25T10:46:28.508+05:30
 * Generated source version: 2.6.2
 * 
 */

@javax.jws.WebService(
                      serviceName = "ProductServiceImplService",
                      portName = "ProductServiceImplPort",
                      targetNamespace = "http://service.dtechtalkcenter.com/",
                      wsdlLocation = "http://localhost:8080/ContractFirstService/services/ProductServiceImplPort?wsdl",
                      endpointInterface = "com.dtechtalkcenter.service.ProductService")
                      
public class ProductServiceImpl implements ProductService {

    private static final Logger LOG = Logger.getLogger(ProductServiceImpl.class.getName());

    /* (non-Javadoc)
     * @see com.dtechtalkcenter.service.ProductService#getProducts(*
     */
    public java.util.List<com.dtechtalkcenter.service.Product> getProducts() { 
        LOG.info("Executing operation getProducts");
        try {
            java.util.List<com.dtechtalkcenter.service.Product> retproducts = new java.util.ArrayList<com.dtechtalkcenter.service.Product>();
            com.dtechtalkcenter.service.Product product = new com.dtechtalkcenter.service.Product();
           /* _returnVal1.setCast(0.7524456455666023);
            _returnVal1.setProductCategory("ProductCategory1751630664");
            _returnVal1.setProductDetails("ProductDetails1256153209");
            _returnVal1.setProductName("ProductName1328378982");
            _return.add(_returnVal1);*/
            
            //We need to write business logic of service interface."Here i have written the sample business logic //for getProduct opertaion"
            product.setCast(200);
            product.setProductCategory("OS");
            product.setProductDetails("Linux server");
            product.setProductName("Linux");
            retproducts.add(product);
            
            com.dtechtalkcenter.service.Product product1 = new com.dtechtalkcenter.service.Product();
            product1.setCast(2000);
            product1.setProductCategory("Database");
            product1.setProductDetails("oracle data for production");
            product1.setProductName("Oracle10");
            retproducts.add(product1);

            
            return retproducts;
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

    /* (non-Javadoc)
     * @see com.dtechtalkcenter.service.ProductService#addProduct(com.dtechtalkcenter.service.Product  product )*
     */
    public void addProduct(com.dtechtalkcenter.service.Product product) { 
        LOG.info("Executing operation addProduct");
        System.out.println(product);
        try {
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }
}

 Expose Interface as web services:
After addition of the business logic the interface would be deployed as service on the web server.
Wsdl url is for that service 

Client of Service using Soap UI:
If you can view WSDL and XSD, you are finish to deploy Web Service on application server. We can use soapUI to simulate Web Service Client

Download address: http://sourceforge.net/projects/soapui/files/

Please select installable file to download. When you installed sopaUI, please follow below step to simulate Web Service Client.

    File -> New soapUI Project
    Project name : ContractFirstService
 and click ok button.

Now, you can see two web service function name in the tree. Open addProduct and getProducts to get request 1. Left window will display below XML content:


click on the request of service and just submit the request through soap ui to service.


In this screen shot you can see the response of the service in the red box.


Saturday 20 October 2012

Fuse ESB Development,Setup and Installation Step

Fuse ESD Development,First we need to plugin the Fuse IDE in Eclipse.

Fuse ESB Development Setup:
Fuse ESB setup for development, we need prerequisite.
  • JDK 1.6 or above
  • Eclipse: Eclipse Indigo 3.7.x, which has Maven m2e embedded in it.
  • Maven:  
Also you can download the prerequisite Software from this site.

Fuse IDE: Fuse IDE provides the ability to work with Fuse and Apache ActiveMQ, Camel, CXF, Karaf and ServiceMix.
You can view, create and edit Enterprise Integration Patterns, browse endpoints and routes, drag and drop messages, trace message flows etc.
Fuse IDE Version: 2.1.747

Adding Fuse Source for Installation:
To add the update site:
  1.  Select (Help → Install New Software) to open the Install wizard.
  2.  Enter (http://repo.fusesource.com/ide/) in the Work with field.

  1. Click Add to open the Add Repository dialog.
  2.  Enter a name Fuse ESB.
  3.   Click OK.
  4.  The Add Repository editor closes.



          5. Select Fuse IDE check box and click next button.

  6.  Click Next and Select I accept the terms of the license agreement.
          7.  Click Finish to finish installing the software.
          8.  When prompted, click Restart Now.
          9.  Create Fuse ESB project in eclipse.


Create Fuse ESB Project in Eclipse: After the plugin of Fuse IDE ,we can create fuse esb project of Eclipse wizard
1-Select Fuse ESB project on eclipse wizard


2-Select Type of module and create the project like camel,osgi,jbi bundle sample.

3-Sample project Created on eclipse with camel and maven build.



Sunday 14 October 2012

Creating Code First Web Service (Bottom-UP Approach)

Creating Code First(Bottom-UP approach) Web Service:
I have been talking about bottom up approach for creating web services in this post with using eclipse.
Bottom up we need to write first java code like beans or enterprise beans where as In contract first ,
We need to define contract like XSD,Schema  and wsdl.

Setup Eclipse for developing web services in java:
We need to different software setup like JDK,Web Server or App Server,WTP,etc.  

Prerequisite Installation:
Install JDK
Install Web Server or App Server like Tomcat, boss.
Install Eclipse like Indigo, Helios, etc.

Setup:
1-When Eclipse is installed then you can check your eclipse preferences (Windows -> Preferences) where Web Service preference is present in the list or not.

 If Web Service preference is not there then you need to plugin WTP (Web Tools Platform) after plugin Web Services link would be available in the eclipse. Link for Helios plugin http://download.eclipse.org/webtools/repository/helios/




2-Configure installed JRE in eclipse (Windows -> Preferences -> Java -> Installed JREs)


3-Setup CXF or Axis2 runtime: In eclipse go to Windows -> Preferences
 And select CXF or Apache Axis2 as per runtime adds runtime to eclipse for creating web services.

I have taken Apache CXF for creating service so I select the CXF preference.






Click on Add button and browse the Apache CXF runtime.



Click Finish button and get the added CXF runtime.then apply and ok




Creating a Web service: Now, we can start to create web service on eclipse using Apache CXF runtime.

Steps:
1-Create a dynamics web project in Eclipse.


  a-      project name ex. StandardWebService
 b-     Select Runtime like apache tomcat v7.0
 c-      Click on modify button for setting facts.

2-Select Apache CXF runtime
Click on modify button, you can select the CXF check box for this project.


Here we can select Apache cxf or apache axis as engine for creating service. Now i am using apache cxf engine for creating service.

3-Write the Java classes which you want create as service:


I have written these classes as sample like

a-      Product

b-      ProductService (it is interface, it has two methods)

c-      ProductServiceImpl (it is implementation of product service)