Wednesday 15 January 2014

JCA Transport in OSB (JCA Adapter/DB adapter)

JCA Adapter:

The Database Adapter fills one gap of the Oracle Service Bus: there is no OSB transport for accessing a database and accessing the database was previously only possible from an XPath function in read-only mode. JCA transport used for this.


To work with JCA Transport in OSB we need to do:

1.setup osb to work with JCA adapter
2.Create a simple SOA application with DB adapter to get .jca file.
3.Import jca file and its dependencies into Osb.
4.Create Business service and/or Proxy service using jca artifact.
5.Testing services.


1.setup osb to work with JCA adapter

  • Login to weblogic console.
  • Click on datasources in the home page to create new datasource.
  • Click on New-->Generic datasource
  • enter Datasource name and JNDI name as "jdbc/DB/MyDatabase_new" and click next.
  • Select driver as "Oracle's driver (thin) for service connections;versions 9.0.1 and later" and click next.
  • Enter your db details and click next and test connection in next page.(here pwd:Oracle123)
  • In the select targets page select admin server( and osb_server also  if you have installed managed server also while create osb domain) and save it.
  • Click on Deployments in WLS home page.


  • Navigate to DBadapter in that deployments page and click on it.
  • Go to Configuration Tab and click on Outbound connection pools.


  • Click on New to create new connection pool and enable That connectionfactory radio button and click next.



  • Enter JNDI name as " eis/DB/MyDatabase_new".(different from our datasourse JNDI name and click finish.
  • Again click on the Connectionfactory  name which we have just created to add datasource to this connectionfactory.

  • Enter the datasourcename in this text box of XADatasourcename
    (jdbc/DB/MyDatabase_newby double click in that property value field..enter the datasource name which we have created previously and click enter on keyboard and click save.
Note: Make sure that this connection factory has value for any one of XADatasource/datasoursename in this page.otherwise it will raise error.
And also make sure the datasourcename which we have created earlier and this XADatasource value Should be same.

  • Go to deployments again and select the dBAdapter check box and click on update to take this changes effect.
  • Click Finish.
  • Restart the admin server.
2.Create a simple SOA application with DB adapter to get .jca file:

  • Create  a new SOA Application in JDEV.Click next.


  • Enter Project name and click next .select empty composite while prompt.
  • click finish.It will open composite.xml file.In that drag and drop dbadapter from componet pallate to External references as shown.


  • In the configuration wizard enter any name for service name and click next.

  • create a new connection to pull tables or copy any existing connection and click next.
  • Enter the JNDI name value which we have created in the outbound connection pools connectionfactory of WLS console..here “eis/DB/MyDatabase_new”.
  • select the Operations you would like to perform on the table using this db adapter and click next to import table.
Note:Make sure that that updated soa-extention to this jdeveloper is compatible.Otherwise it wont allow us to import tables.go to help-->check for updates and update the compatible soa extension.here E:\OracleServiceBus\soa-jdev-extension (1).zip.We can download the extension and can apply. 


  • Click on import table and select the required table and hit import.Click next .In define selection criteria we can add parameters to our select query if you want as follows.



  • Click finish.It will generate all the files like .jca,.mappings files for this project. We need to import these files into osb console to create business services and using jca transport.
  • Go to that project work space and select the required file and zip them.
  • we need the following 5 files to export into osb console.

C:\JDeveloper\mywork\JCA_New_application\JCA_New_Project

and 

  • Zip all this 5 files.
3.Import these files into OSB console


  • Login to service bus console http://localhost:7001/sbconsole
  • Create a new session using change center.
  • Create a new Project named as JCA_Project using Project explorer


  • Click on the project and in create resource LOV select Zipped resources to import this files in to osb console.



  • Click on choose file and navigate to select our zip file containing the above 5 files and click next.



  • It shows our files and click on import.



  • It will throw 2 conflicts here because the references are mismatching.WE can solve it by using Edit resources of our WSDL file.


  • Click on the WSDL file in the Project.
  • It will open our wsdl file .In that page Click on the Edit references as shown.
  • Click on browse to select our xsd (which we have imported earlier)to map with this wsdl file.
  • Select the XSD file and click submit.
  • Click on save.Observe the change center now.Conflicts get resolved now.

4.Creating Business Service
  • Navigate to Project Explorer and click on your project-->near your jca file-->Click on the Export symbol,it will create Business service and its WSDL using this JCA file with jca transport.

  • It Will open a window ,In that You can Modify Business service name and WSDL name and Click on Generate.I t will create the jca transported Business service.WE can open the business service to see this transport type as jca.

  • Click on the Business service.observe that the  Transport as jca and endpoint url as our JNDI name. 


  • Activate the session.Now we are done with JCA Transport Business service.We can test it using test console to work with database operations.Also we can create proxy service using this Business service.
5.Testing our Business service

Test 1:
  • Click on the bug icon near our business service to launch test console.
  • In the operations select Insert operation to insert a new new row into the table
  • Enter values in the payload click on execute.

  • observe the result.As this is insert operation It wont give response here.Go to Your table data and observe that the new row we have given is being inserted.
  • Query the table.

Test 2:
  • Now Launch the test console and select "serviceSelect"operation and click on execute.We have given Id as a parameter while configure our dbadapter in Jdev.So pass the any id and click on execute.
 


  • observe the result in response document.It will bring the values from db.Hence done with testing.

Done.....

Monday 13 January 2014

EJB and JEJB Transport in OSB

What is EJB/JEJB Transport:

  • The EJB transport is only available for business services whereas the JEJB transport can be used both on a proxy service as well as for business services.
  • EJB protocol enables us to create a business service which doesn’t stands for a SOAP / HTTP of File service, but for a remote EJB. This allows us to let our OSB clients or our own composite proxy services to communicate with EJBs with a simple SOAP xml message.
  • JEJB protocol allows us take POJOs and make them available as they were EJBs. Here, the XML interface we will expose will only contain a reference to a Java object, and not its XML content. Introduced in OSB 11g.
  • EJB Transport Uses Java Webservices Framework to invoke remote EJBs.
  • JEJB Transport uses an RMI serialization /deserialization cycle and passes Plain old Java Objects(POJO)directly through the OSB to the remote EJBs.
  • Using JEJB transport we can export a proxy service as a stateless session bean.
JEJB Transport Advantages:


  • JEJB Transport Supports both Inbound and Outbound whereas EJB supports only Outbound.
  • JEJB doesn't convert Java objects to Xml Representation.

Example::
TO DO.
1.Create an EJB project and sample test client for that session bean.
2.Import Client Jar to Osb.
3.Create JNDI provider in osb.
4.Create Business service.
5.Create Proxy service.


1.Create an EJB Project:

               Note:providing brief notes as most of SOA developers familiar to work with EJBs  

    • Create a new generic application namely”OsbEjbSampleApplication” in JDEV.
    • In Project Page select EJB technology from available to Selected.
    • Select Entities from table
    • And Click finish.Connect to application server datasource connection as we have application server datasource inWLS.
    • Add a new connection with your db credentials to select table.
    • Enter entity name and accept defaults and say finish.
    • Here my jdbc name is “jdbc/DB/MyDatabase_new ” that I have created in WLS.Entity has created.Now go to persistant.xml..modify the jdbc name to correct jdbc name that we have created in WLS.Here my jdbc name is “jdbc/DB/MyDatabase_new ” that I have created in WLS.
    • Create session bean and expose local and remote interfaces with selected methods.
    • Create Deployment profiles:
                        1.Go to project properties -->select deployment ,click new.
                        2.Select Deployment.and create two deployment profiles..as
                           EJB--JAR deployment profile.
                           Client JAR deployment profile. 
                     
                        3..Right click on Project-->Client JARDeploy-->>Deployed to JAR.(we will use this Client jar file later in osb)
                        4.Rightclick on project-->EJBJARdeploy -->Application server
    • Create Sample java client by right clicking on our session bean.
    • open this client file right click on this file and Run it to test our web service.
    • copy the Jndi name from client class.(this is EJB bean JNDI name)
      OsbEjbApp-OsbEjbPro-osbEJbSession#osbejbpro.osbEJbSession”:


    2.Import Client Jar to OSB

    • Create JAR deployment profile for client project.

    • Deploy client Project to JAR profile.


    • click next..observe the archive file output file path of this Jar file..We need to import this Jar file into OSB in next step..

    • Login to sbconsole.Create session -->Project Explorer-->create Anew Project For this EJB transport-->Create Resource->Utility/JAR.
    • Enter Name for Client Jar file in Osb-->click on Choose file-->navigate to Output archive location which we have noted in previous step(Our Jdev Client project JARdeployed path)-->select the Jar file and click on save.
    3.Creating JNDI provider in OSB
    • Login to osb console(if not already logged in) and Create Session.go to SytemAdmistrator.







    • Click on JNDI Providers under Global Resources and to add our new JNDI provider click on Add.It will display new window for JNDI provider
    •                   enter values
                               NAME:MYJNDIProvider(your JNDI name)
                               Provider URL :http://localhost:7001(server URL where your weblogic server is running)
                               Uname/Pwd::weblogic/welcome1
                               enable java cache
    • Save it.
    4.Creating Business service
    •  Go to create resource-->Business services.
    • Enter Name for your business service and select Transport typed service  as Service type and click next.
    • In the Transport Configuration Screen Select Protocal as JEJB and enter END Point URI asjejb:<jndi_provider_name>:service_name ” format.


    Note: Here service name is the JNDI name that we have copied in JDEV for Client Project.

    Here END point URI:(Please don't include any spaces after : (colon).It will raise an error like it is invalid URI)

    jejb:MyJNDIProvider:OsbEjbApp-OsbEjbPro-osbEJbSession#osbejbpro.osbEJbSession
    • click on ADD.

    • click next..It will navigate TO JEJB Transport Configuration.
                      EJB Spec Version:3.0
                      Client Jar:select the client Jar file That we have imported earlier select it and submit.





    • Business interface: remote session bean(here by default it has selected my remote session bean)
    • Methods:I have only one method in my EJB..
    • Finally our BS looks like this..Save it.
    5.Creating Proxy service

    Note:
    We can create Proxy service directly in osb console..Or we can Export that project from Console to local system(whatever the location we want..it exports entire project as a jar file).And in Eclipse IDE create config project and OSB Project.Inside the OsbProject we can import this Jar file and we will create Proxy service for this.
    Eclipse IDE is very easy to develop message flow for Proxy service.So I imported the project into Eclipse and will create Proxy here.

    NOTE:
    While Exporting project from console to local select “Export Resources” instead of“ExportProjects” because Export resources will export all the dependent files for the selected project like with JNDI Provider also.Other wise eclipse will throw error like missing JNDI provider.

    My eclipse looks like this.
    • Right click on Project -->New-->Proxy service.
    • Select Project and enter Proxy service name and click finish.

    • Select Transport Typed Service in service type.


    • Select JEJB and leave the Endpoint URI as it is and click Next.
     

    • JEJB Transport Configuration:
    • select EJB 3.0 spec and select the Same Client Jar file that we have selected for  BS.






    save your proxy and test them to see our ejb methods are working or not