Lab 5 - SOAP Web Services

RH_Icon_Compass_Shiny.png In this lab you will create a SOAP web service that exposes two operations, using CXF (https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.2.1/html/Apache_Camel_Component_Reference/IDU-CXF.html )
general_info_polished.png Apache CXF is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI. (https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.2.1/html/Apache_CXF_Development_Guide/index.html )
  1. Select File->Import.
  2. Select General -> Existing Project into Workspace.
  3. Select “archive file”.
  4. Browse to ~/FuseWorkshop/support/Lab5/Lab5.zip
  5. Click Finish.
  6. Right-click in the src/main/resources folder and select New -> Other
  7. Select General -> Folder, click Next.
  8. Enter wsdl as its name and click Finish.
  9. Right-click in the wsdl folder and select Import
  10. Select General -> File System and click Next.
  11. Browse to ~/FuseWorkshop/support/Lab5 and select JBossBankServices.wsdl
  12. Select menu Run -> External Tools -> WSDL2Java

general_info_polished.png This CXF plugin will generate a group of Java classes that represent a skeleton to implement the web service described by a WSDL file.
  1. Review the generated Java classes under the org.example.jbossbankservices package.
  2. Double-click on the blueprint.xml file to open it in the editor.
  3. Click on the Source tab.
  4. Copy and Paste the following xml lines before the <camelContext>:
<cxf:cxfEndpoint id="ws" address="/JBService" serviceClass="org.example.jbossbankservices.JBossBankServices"/>
general_info_polished.png The first line describes a CXF Endpoint which is associated with the main Java class created by the CXF plugin from the WSDL file. This means that the endpoint will implement the web service described in that file.
  1. Save the file (Ctrl+S).
  2. Click on the Design tab.
  3. Add a CXF component from the Components palette.
  4. Edit its properties and modify the url to: cxf:bean:ws

  1. Add a Choice component from the Routing palette.
  2. Add two When components from the Routing palette.
  3. Link CXF to Choice.
  4. Link Choice to the first When.
  5. Link Choice to the second When.
  6. Edit the first When properties:

  7. ${header.operationName} == ‘getCustomerAccounts’

  8. Edit the second When properties:

  9. ${header.operationName} == ‘getAccountBalance’

  1. Save the file (Ctrl+S).
general_info_polished.png The SOAP operation name of the incoming web service request is parsed by CXF and placed in a header called “operationName”.
  1. Add a SQL component from the Components palette.
  2. Edit its properties:

  3. Advanced -> Path -> Query: select * from accounts

  4. Advanced -> General -> Data Source: JBossBankDB
  5. Advanced -> General -> Output Class: org.example.jbossbankservices.Account

general_info_polished.png The SQL component allows you to work with databases using JDBC queries. Unlike the JDBC component ,this component uses spring-jdbc behind the scenes for the actual SQL handling.
  1. Add a Bean component from the Components palette.
  2. Edit its properties:

  3. Method: setAccount({$body})

  4. Bean Type: org.example.jbossbankservices.Accounts

  5. LInk the first When to the SQL component.

  6. Link the SQL component to the Bean component.
  7. Save the file (Ctrl+S).

general_info_polished.png The bean component binds beans to Apache Camel message exchanges. IT allows you to call methods from or instantiate Java beans.
  1. Go to the org.example.jbossbankservices package under src/main/java and open Accounts.java
  2. Go to the end of the file and add the following method:
public Accounts setAccount(List<Account> accounts){
  1. Save the file (Ctrl+S) and close it.

  1. Add another SQL component from the Components palette.
  2. Edit its properties:

  3. Advanced -> Path -> Query: select * from accounts where accountid=:#${body[0]}

  4. Advanced -> General -> Data Source: JBossBankDB
  5. Advanced -> General -> Output Class: org.example.jbossbankservices.Account
  6. Advanced -> General -> Output Type: SelectOne
general_info_polished.png In this case we selected “SelectOne” because we expect only one row coming back from the DB.
  1. Add a setBody component from the Transformation palette.
  2. Edit its properties:

  3. Expression: ${body.getAccountBalance()}

  4. LInk the second When to the second SQL component.

  5. Link the second SQL component to the setBody component.
  6. Save the file (Ctrl+S).

  1. Go to the Servers tab and start the JBoss Fuse server ()
  2. Right-click on the JBoss Fuse server and click on Add and Remove..

  1. Select Lab5 and click on the Add button.
  2. Click Finish.

general_info_polished.png Now you will test the two operations of the generated web service using an open source tool called SoapUI (https://www.soapui.org )
  1. Start SoapUI by clicking on the icon in the desktop.
  2. Click on the SOAP button

  1. Enter Lab5 as the Project Name.
  2. Enter http://localhost:8181/cxf/JBService?wsdl as the Initial WSDL.
  3. Click OK.

  1. Double-click on the Request1 under the getAccountBalance operation.
  2. Replace the “?” in accountID with a “111”.

  1. Test the webservice by clicking on the submit request button
  2. Double-click on the Request1 under the getAccounts operation.
  3. Replace the “?” in customerID with a “1”.

  1. Test the webservice by clicking on the submit request button
  2. Close SoapUI.
  3. If both tests were successful, go back to JBDS.
  4. Close all the open files.
  5. Right-click on the Lab5 deployment under JBoss Fuse Server, and select Remove.

results matching ""

    No results matching ""