Monday, December 27, 2010

My Year 2010

Share this Post
Hi,

Year 2010 was a great year for me both personally and professionally and i think its a best year for my IT career i have learned a lot and personally i became dad with a cute daughter.

Back in 2009 around at the same time i decided to start writing a blog on Oracle technology and on good response from Google queries i moved to write towards more on Oracle ADF and fusion middleware area.

Some highlights of my achievements in 2010. 
  • I have learned a lot about Oracle ADF and Fusion middleware technologies.
  • Got to know the SOA, BPM suites.
  • I have written 82 blog posts in Year 2010 lets hope i would continue to write helpful topics.
  • I presented 2 day APEX training sessions at Oracle university (Techno-ed) in Karachi, Pakistan.
  • Formed PITUG User group to spread IT awareness in Pakistan.
  • Made lot of friends all over the world.
With Year 2011 (In 2 months) I am migrating to USA and looking forward to work in the field of Oracle ADF and fusion middleware products.

I wish you all a happy new year

Best Regards,
Zeeshan Baig

Wednesday, December 8, 2010

FREE 2 day Oracle APEX training in Karachi, Pakistan.

Share this Post
Hi,

Just to announce that i will be conducting 2 days training sessions  on "Getting started with Oracle APEX" at Oracle University Karachi, Pakistan.

Venue: Oracle University / Ora-Tech Karachi, Pakistan.
Location: Main Nursery Shahrah-e-faisal Karachi
Date: 14 & 15 december 2010
Timings: 6 PM to 9 PM (3 hours)

I would be glad to see you there.

Best Regards,
Zeeshan Baig

Monday, December 6, 2010

How to set Session time out in ADF application

Share this Post
Hi,

Simple tip today but probably most of my friend coming from FORMS background are not familiar with this. Where and how to set the Session time out setting in Oracle ADF application? Answer is with every application there is a file called web.xml file in your ViewController Project WEB-INF folder. The file which contains configuration settings for your web application on run-time. JDeveloper provides a declarative way to modify this settings by default the session timeout is 35 minutes.

Here what documentation says
Session Timeout
(Optional) Enter an integer value of minutes of inactivity are required before you want to force your web application's sessions to expire. Corresponds to the tag of the subelement. Note, this value can be overridden for individual sessions by means of the setMaxInactiveInterval() method of the javax.servlet.http.HttpSession interface.

Here is the setting in Jdeveloper



after deployment you can see the timeout value in the deployment properties of your application as well here the screen shot of weblogic console





On runtime if session expires you will get the similar message



Happy Jdeveloping,
Zeeshan Baig

Saturday, December 4, 2010

Using Database Adapter in BPEL Process in Oracle SOA Suite 11g

Share this Post
Hi,

DB Adapter allows you to read database into SOA composite application from any relational database. before using the service with DB Adapter make sure you have created a JDBC data-source and Connection Factory under  DBAdapter application.

Download the sample code





Have a nice day,
Zeeshan Baig

Creating JDBC datasource in Oracle Weblogic server

Share this Post
Hi,

Before going to work with DB adapter in Oracle SOA suite you have to define the JDBC datasource in WLS and Connection factory under DBadapter in deployments.

Here is the first step how to create JDBC datasource in Weblogic server




Have a nice day,
Zeeshan Baig

Sunday, November 28, 2010

Writing your first BPEL process in SOA Suite 11g

Share this Post
Hi,

I finally managed to setup soa server on another machine so now i can work much faster than running on a 2GB Ram virtual machine on my macbook.

So here in this post we will see how to write a simple BPEL process which will concat the text "Hello Dear" with our input value same as my older post sayHello method.

Download the sample project and instructions in the video



Happy Jdeveloping,
Zeeshan Baig

Friday, November 19, 2010

Calling Webservice in Oracle ADF by Creating Webservice Data control

Share this Post
Hi,
In this post we will call the webservice by creating webservice data control in Oracle fusion application we will call the same webservice that we have created in last post.

More info in this video



Happy Jdeveloping,
Zeeshan Baig

Creating Webservice from Java class in Jdeveloper 11g

Share this Post
Hi,
In this post we will see how to create Webservice from java class, test it using HTTP analyzer and deploy to weblogic server.

Watch this video tutorial



Happy Jdeveloping,
Zeeshan Baig

Monday, November 15, 2010

How to display Videos in ADF Fusion application

Share this Post
Hi,

Simple post but effective by using af:media component we can display or run videos in oracle adf fusion application. af:media just like af:image accept a source parameter to the location of the file.

Here is the code snippet



standbyText="Please wait while the movie loads" id="m1"
autostart="true" playCount="0"
innerHeight="500" innerWidth="600"/>


Happy Jdeveloping,
Zeeshan Baig

Tuesday, November 9, 2010

Displaying table data in tool tip style popups in Oracle ADF

Share this Post
Hi,

 A common use case is to display related data in tool-tips style. In this post we will see how to to achieve that in Oracle ADF.

Download the sample code

Details in this video



Happy JDeveloping,
Zeeshan Baig

Wednesday, November 3, 2010

How to execute SQL DML statements in Oracle ADF

Share this Post
Hi,

In some use cases it is required to execute just a simple DML (Insert, Update, Delete) statements in application.  so how to execute those in ADF? I will describe a one way to do this.

The steps are:

1. Create a method in Application Module (using DBTransaction and CallableStatement)
2. Expose that method to client interface
3. Drag and drop the method to your page
4. And optionally you can set the partial triggers and write a code to refresh your iterator bindings.

Here is the sample method in AppModuleImpl.java


  public int increaseSalary(int deptId, int increamentPercent) {
    
      DBTransaction trans = getDBTransaction();

      CallableStatement statement = null;
      int rows = 0;
      
      String plsql =
            " BEGIN " 
          + " UPDATE EMPLOYEES "
          + " SET SALARY = SALARY + (SALARY * ? / 100)"
          + " WHERE DEPARTMENT_ID = ?;"  
          + " END; ";
    
    
      statement = trans.createCallableStatement(plsql, 2);
      try {
          statement.setInt(1, increamentPercent);
          statement.setInt(2, deptId);
  
         rows = statement.executeUpdate();

      } catch (SQLException s) {
          throw new JboException(s);
      } finally {
          try {
              if (statement != null)
                  statement.close();
              return rows;
          } catch (SQLException s) { /* ignore */
          }
      }
  return rows;
  } 


Download the sample code

Watch this video for more info



Happy JDeveloping,
Zeeshan Baig

Monday, November 1, 2010

Performing logical delete in Oracle ADF

Share this Post
Hi,

In some use cases it is required not to physically delete the row from database but instead update a FLAG e.g delete_FLAG = 'Y'  to hide rows from user. So, if you are not familiar with the framework then you might take a long route to do the task which could easily be done by declarative steps.

In this post we will do the following.
  1. We will add history columns in entities.
  2. We will have a view criteria to display only DELETE_FLAG = 'N' rows.
  3. On deletion in detail table we will delete logically.
  4. We will update the History columns of Master entity as modified by and modified_date.

Download the sample code

More info in this video




Happy JDeveloping,
Zeeshan Baig

Avoiding JBO-26048 during commit in a master detail transaction

Share this Post
Hi,

You might face error JBO-26048 while performing COMMIT in a master detail transactions. This error occurs because by default your Association is not configured to perform optimized DMLs (Both Master and Detail same time) and you might see something similar.


(oracle.jbo.DMLConstraintException) JBO-26048:
Constraint "TAB_DET_TAB_MST_FK" is violated during post
operation "Insert" using SQL statement
"BEGIN INSERT INTO TAB_DET(DET_ID_SEQ,ID_SEQ,
DET_DESC,DELETE_FLAG) VALUES (:1,:2,:3,:4)
RETURNING DET_ID_SEQ INTO :5; END;".


You can simply avoid this checking the "Cascade update key attributes" and Composition Association in Association > Relationship



Happy JDeveloping,
Zeeshan Baig

Sunday, October 24, 2010

Customizing database error messages in Oracle ADF

Share this Post
Hi,

One blog reader asked me how to customize error messages. Its a lucky day i am posting the same topic. You can easily customize the database error messages in any language. In this post i will demonstrate how to customize the error messages. I am customizing error messages of primary key and unique constraint.

You can find the error messages code on the following links.
  1. ADF common error codes
  2. ADFBC JBO messages

Download the sample code

More in this video



Happy Jdeveloping,
Zeeshan Baig

Thursday, October 21, 2010

Skipping Validation in Oracle ADF

Share this Post
Hi,

In my previous post i have mentioned about skipping validation on the page definition and i have found a very useful blog post by Jobinesh.

do check this out 

Have a nice day,
Zeeshan Baig

Wednesday, October 20, 2010

Creating Train flows in Oracle ADF

Share this Post
Hi,

You must've seen the wizard driven registration forms on the web which provides pretty useful approach break the whole tasks into limited screens. In ADF you can do the same by using Train flows in bounded task flow in simple words Train is one type of bounded task flows.

In this post we will see how to create Train flows in Oracle ADF and we will also calling another bounded task flow in between.

There is a little trick when you are creating a Train flow based on same entity you need to skip validations on the page definition to avoid errors.

Download the sample code

More details watch in this video





Check this great Oracle ADF book
















Happy JDeveloping,
Zeeshan Baig

Saturday, October 9, 2010

Display images in Carousel item in Oracle ADF

Share this Post
Hi,

af:carousel is a cool component in Oracle ADF which provides a gallery view of images (or others components) and enhance the user experience on the web.

In this post i enhanced my old post "Storing and reading images from BLOB in Oracle ADF". In this post i have added a new button Show all which displays all images stored in Table BLOB Column in Carousel on Page 2

Download the sample code

More info in this video




Happy JDeveloping,
Zeeshan Baig

Sunday, October 3, 2010

Creating Shuttle Component in Oracle ADF

Share this Post
Hi,

In this post we will see how to create select many Shuttle component in Oracle ADF.

af:selectManyShuttle component requires leading and trailing values  as java.util.List you can create a List from your iterator or static values.

Download sample code

More info in this video




Happy Jdeveloping,
Zeeshan Baig

Wednesday, September 29, 2010

Using af:autoSuggestBehavior in Oracle ADF

Share this Post
Hi,

You must be familiar with this feature while Googling when you type partial text in search box and you get lot of similar text suggestions. The same feature you can use in ADF application as well with af:autoSuggestBehaviour tag

You can use the same technique for LOVs as well

Download the Sample workspace 

More info in this video





Happy Jdeveloping,
Zeeshan Baig

Saturday, September 25, 2010

Filter table records using af:InputRangeSlider in Oracle ADF

Share this Post
Hi,

After couple of weeks of absence i am back :) . In this post we will see how to filter table records using Range slide component. I m using af:InputRangeSlider component to define the minimum and maximum range and these range uses to setup the values of bind variables in employee table to display records between these salary ranges.

The idea inspired by Oracle fusion applications screen shots :)

Download the sample workspace





Happy Jdeveloping,
Zeeshan Baig

Sunday, September 19, 2010

ADF Essentials Series at OTN

Share this Post
Hi,

This post to introduce the great ADF essentials series articles at OTN by Chris Muir and John Stegeman. Don't Miss it

Oracle ADF Development Essentials

Series: Adapting Oracle Application Development Framework and Subversion to Your Enterprise's Needs

Happy Jdeveloping,
Zeeshan Baig

Wednesday, September 8, 2010

Store Images in BLOB in Oracle ADF

Share this Post
Hi,
In this post we will see how to store images in BLOB type database column instead of server OS. This post also shows how to read images later from BLOB column using Image servlet.

Download the sample code

Summary of steps as follows:

1) Create table with BLOB column.

2) Create Business Components as usual make sure the type is BlobDomain is selected.

3) Create Managed Bean which process image to store in BLOB  (request scope level)

4) Create Image Servlet to read Images from database table.

Details in this video.





Happy JDeveloping,
Baig

Monday, August 30, 2010

Uploading and Downloading Images in Oracle ADF

Share this Post
Hi,

In this post we will see how to upload and download images in Oracle ADF application.

Note: this example does not store images in BLOB column it just copy the image from client machine to server directory.

Download the sample workspace





Happy JDeveloping,
Zeeshan Baig

Monday, August 23, 2010

How to setup Custom Authentication in Oracle APEX

Share this Post
Hi,
Recently on ODTUG mailing list one fellow asked about using custom authentication schemes in APEX. i thought it would be good idea for my blog post :)

In this video i will demonstrate how to create login page which authenticates username and passwords from database tables in Oracle APEX.

Note: The purpose of this post is just to show the setting up custom authentication therefore i have used a very simple db table with passwords stored as text.
In real world this password approach in not recommended you must store passwords in encrypted columns or use any procedure to convert passwords into encrypted form.

Database structure

 create table my_users
(user_name varchar2(10),
 user_pwd varchar2(10));

insert into my_users
values('Tom','Secret');

insert into my_users
values('Baig','oracle');

commit;

Authentication Function

create or replace function 
validate_user_from_db (p_username in varchar2, p_password in varchar2)
return boolean
as
    v_pw_check varchar2(1);
begin
    select 'x'
    into v_pw_check
    from my_users
    where upper(user_name) = upper(p_username)
    and user_pwd = p_password;
    
    apex_util.set_authentication_result(0);
    return true;
exception when no_data_found then
    apex_util.set_authentication_result(4);
    return false;
end validate_user_from_db;


Authentication messages

0: Normal, successful authentication
1: Unknown User Name
2: Account Locked
3: Account Expired
4: Incorrect Password
5: Password First Use
6: Maximum Login Attempts Exceeded
7: Unknown Internal Error

A little code to test our authentication function( This function for only test in SQL prompt)

declare
 vresult varchar2(10);
begin 
 if validate_user_from_db ('baig','oracle') then 
    dbms_output.put_line('OK');
 else
     dbms_output.put_line('ERROR');
 end if;
end;


And finally a video tutorial steps



Happy learning,
Zeeshan Baig

Sunday, August 22, 2010

Using Page Templates in ADF Fusion application

Share this Post
Hi,
I will continue my last topic which is related to building resuable components in ADF. In this post i will demonstrate how to create and use page templates to provide common look and feel in ADF application.

More info in this video and download the sample workspace



Happy JDeveloping,
Zeeshan Baig

Saturday, August 14, 2010

Sharing Business Components and Task flows between ADF Application

Share this Post
Hi,

Lot of my friends those are coming the Oracle Forms background and new to ADF asks this question "How to share components of one application with another" well the answer is simple by using "ADF Library Jar" deployment profiles.

Explore more in this video



Happy JDeveloping,
ZB

Monday, August 9, 2010

Configuring APEX Listener with GlassFish Server

Share this Post
Hi,

Currently i am developing one application with APEX and today i configured APEX listener with Glassfish server in my development environment to evaluate Glassfish with Oracle HTTP server..so far i faced an issue with Interactive reports are not working properly with Glassfish.

APEX Listener currently not working with ORACLE XE (as far as i know, waiting for patch)

Here are the configuration steps





You can check the installation guide for more info

Have a nice day,
ZB

Saturday, August 7, 2010

How to get Client IP Address in ADF Fusion Application

Share this Post
Hi,

One of the most common requirement is to get the IP Address of the client. You can use the following methods in a session scope bean.


public String getClientIpAddress() {
        String clientIpAddress =
         ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemoteAddr();
            return clientIpAddress;
    }


Happy JDeveloping,
ZB

Thursday, August 5, 2010

Using af:switcher component in Oracle ADF Faces

Share this Post
Hi,
     As i explained in my last video working with Router activity in Task flows the same functionality can be achieved using ADF Faces af:switcher component on JSF page. This example will also quickly shows how to use DVT components on JSF page.

Here is the example hope you like it




Download the example

Happy JDeveloping,
ZB

Saturday, July 31, 2010

Using Router Activity in Task flows

Share this Post
Hi,
As a general use case when you are required to conditionally navigate between pages, Router activities comes into action.

Here is an example how to use Router activities in task flows




Download the workspace 

Happy JDeveloping,
ZB

Tuesday, July 27, 2010

Using Framework Buffer classes in Oracle ADF

Share this Post
Hi,

Its a good practice before starting any new project in Oracle ADF to setup framework buffer classes. which acts as a layer between your code and framework.

What JDeveloper Handbook says about it

"Adding your own buffer classes between the application and the framework provides two
benefits. First, as the application evolves, you will identify certain bits of reusable functionality or
functionality that modifies the default way that the framework operates. These can be moved into
the buffer class with a minimum of disruption and immediately become available to all your
classes, since your classes will extend this framework buffer class. Second, the buffer class
provides a good patching point. If you encounter a problem in the way that the base framework
works, you can patch workarounds into the single buffer class, rather than having to make the
change in every implementation"



More details in this video




Happy JDeveloping,
ZB

Sunday, July 25, 2010

Passing Parameters between Bounded Task flows

Share this Post
Hi,

In this Video post i will show how to pass parameters between bounded task flows. for this i've created 2 bounded task flows in the example called FlowA and FlowB respectively. I am calling FlowA from "main.jspx" page available in the un-bounded task flow called adfc-config.xml

This is my first try for Video blogging so your comments would be helpful



Download the sample workspace

Happy JDeveloping,
ZB

Sunday, July 18, 2010

Sample code - Quiz Application in Oracle ADF

Share this Post
Hi,

I finally got time to finalize the installation script (was 3 months overdue) of my sample application which i created in Oracle ADF using JDeveloper 11g PS2.

Feel free to play with it identify bugs and report to me :) and I hope it would help you to learn ADF as well.

Download Application : Quiz Application version 1.0
also download Readme

Introduction:
Quiz application allows the logged in users to take random quiz from the list questions stored in the database, No of questions to ask the Admin user can set in the profile after completion of the quiz it displays the score report.





Installation:
  • Open the Quiz Application in JDeveloper PS2.
  • Expand the Database project.
  • Right click the install.sql and run in SQL*Plus.
  • Enter sys account password. 
  • Change your database settings in the Application Resource connection settings.

Running the Application:
  • Run the main.jspx file in the ViewController Project.
  • Log in as demo or admin (default user created in ADF security).
  • Mark your choices you feel is correct (only one choice supported).
  • Press “End Quiz” button on the last question.
  • See the report and “Try Again” to go back to home page.

User Roles
  • “Demo” user can only take part in quiz.
  • “Admin” user can enter, modify the quiz questions and mark the correct choices.
  • “Admin” can also take quiz

Known limitations (would enhance in next update):
  • Currently only one correct choice per question supported.
  • There is no time limit on per question (option available to set in the quiz profile).
  • No history review of the quiz takers.
  • Register as new user option (you can create more users in ADF security)

Happy JDeveloping,
Baig

Saturday, July 17, 2010

Implementing Drag and Drop functionaly in Oracle ADF

Share this Post
Hi,

Drag and Drop is one of the core feature of Oracle ADF. In this post we will see how simple is to achieve this functionality.


Example Use Case:
We need to select few employee to visit Oracle Open world 2010, but management will choose only their favorite employees :) so they will drag employees images from left pane (Drag from) to the Selected employees List box. Employee Id can also be seen under the Image.


I will just shortly summarized the technical expect in the example. Rest you can explore by downloading the workspace.  

Components and Methods used in this example:
  • af:attributeDragSource :  Under Image component allows to drag the image to dropTraget area.
  • af:clientAttribute : Under Image component sets as employee full name as its value.
  • af:dropTarget: Sets the drop target area on the List box and allows to call Drag and Drop handler method.
  • af:attributeDropTarget: set its value as source's value if dropped on it.
  • DnDHandler class has a
  • Private variable called choices of type List which binded into the List Box
  • Drop event handler method called handleItemDrop which returns DnDAction type adds an element in the list box component.
Explore more in the example

feel free to comment

Happy JDeveloping,
Baig

Wednesday, July 14, 2010

Error 403--Forbidden when calling Bounded Task flow

Share this Post
Hi,

When invoking bounded task flow and your method activity is the default activity in that flow as shown in the slide (JDeveloper 11g PS2) the parameter "URL Invoke" under visibility section in your Task flow you have to keep in mind to avoid HTTP 403 exception.


The parameter URL Invoke has 3 choices which defaults to calculated
  1. select url-invoke-allowed from the dropdown list if you want to allow a URL to invoke the bounded task flow. 
  2. Select url-invoke-disallowed if you do not want to allow a URL to invoke the bounded task flow. Selecting this value returns a HTTP 403 status code if a URL attempts to invoke the bounded task flow. 
  3. The default value (calculated) allows a URL to invoke the bounded task flow if the bounded task flow does not specify an initializer and it has a view activity as its default activity. If the bounded task flow does not meet these conditions, a HTTP 403 status code is returned. Selecting url-invoke-allowed or url-invoke-disallowed overrides the default behavior.

Simple set the value of URL Invoke according to your use case



Download the sample workspace 

Happy JDeveloping,
Baig

Saturday, July 10, 2010

Deleting existing weblogic server domain things to keep in mind

Share this Post
Hi,

I recently setup a All-in-One AdminServer  to save some resources of my laptop for Oracle SOA Suite 11g, before i was running AdminServer and other Managed Servers as separate engines which eats up all the memory. So by googling and asking experts thanks to Edwin Biemond he suggested me the solution is to merge all ManagedServers into the a single AdminServer.

Steps can be found at this blog and Oracle wiki

so, to end the story i created a new domain with the configuration but was unable to start the new domain i thought problem with existing domain so i deleted my existing old domain that i created before.

We will look at the deleting domain step as well as the fix later.


Deleting a Oracle Weblogic Server Domain:
  • Deleting a WLS domain is not a rocket science its just a configuration files so for this only delete the directories exists on your machine.
e.g

\user_projects\domains\domain_name

In my case i deleted the directory soa_domain11g 
E:\Oracle\Middleware\user_projects\domains\soa_domain11g

  • Delete the  domain name from the "nodemanager.domains"  file, the file exists on the following location

\\common\nodemanager\
In my case it is
E:\Oracle\Middleware\wlserver_10.3\common\nodemanager

Problem table verify failed for table 'WL_LLR_ADMINSERVER'

  • Still i was unable to run the AdminServer by looking at the log file following error was appearing

javax.transaction.SystemException:
weblogic.transaction.loggingresource.LoggingResourceException:
java.sql.SQLException: JDBC LLR, table verify failed for table 'WL_LLR_ADMINSERVER', row
'JDBC LLR Domain//Server' record had unexpected value 'soadev//AdminServer' expected
'soa_domain11g//AdminServer'*** ONLY the original domain and server that creates an LLR table
may access it ***

After googling found a easy fix

  • Connect to DEV_SOAINFRA schema and update the name to new domain name.                 Note: The prefix DEV depends on your prefix while you installed SOA Suite repository
update WL_LLR_ADMINSERVER
set    RECORDSTR = 'soadev//AdminServer'
where  XIDSTR    = 'JDBC LLR Domain//Server';

commit;

Hope it helps,
Baig

Sunday, July 4, 2010

Creating Webservice from WSDL and Testing in HTTP Analyzer - Part 3 of Creating your own Webservices in JDeveloper11g

Share this Post
Hi,

As you can see in my last 2 posts i have created a XML Schema, WSDL document and we have defined the operations that our webservice will perform,

Now its time to implement the business logic in the webservice.


Creating a Webservice from WSDL
  • Right click the WSDL document that we have created and choose Generate Webservice. Follow the slides for basic webservice setups with No Policies defined.






  • Press Finish and wait for Jdeveloper to finish his magical things.

  • Now you can see Jdeveloper generated lot of Java classes and code in automatically, as you can see as well that myPortTypeImpl.java file create which provides the basic implementation of the webservice and Jdeveloper created all related Java classes on the types we have defined in the XML Schema so we can use them as a Java objects.


Retrieving Status from Oracle table via JDBC call
  • Next it to retrieve the status of credit cards from database table for this we will use a simple JDBC statement to retrieve the values from the table but for his we have to add a JDBC library to our project
  • To add a JDBC driver into your Project, Right click the project choose Project Properties go to Libraries and Classpath press Add Library and choose Oracle JDBC and press OK

  • Now for code separation we will add the JDBC realated code to another Java Class, Right click the packages.types i.e baigsorcl.types package in application navigator and choose New, Select Java Class and enter name "OraJdbc" press OK
  • Copy and paste the following code to the OraJdbc class (the purpose of this class is to create a connection via JDBC to oracle database and execute a query and return the status of credit card) and compile it (right click choose Make)

package baigsorcl.types;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class OraJdbc {
    public OraJdbc() {
        super();
    }
    public String getCreditCardSatus(int ccNo) throws SQLException {
      
      //Return variable
      String result = "INVALID";
      
      //Connecting to DB
      Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
      conn.setAutoCommit(false);
      
      //executing query
      Statement stmt = conn.createStatement();
      ResultSet rset = stmt.executeQuery 
            ("SELECT creditcard_status FROM CreditStatus where Creditcard_number = " + ccNo );
      
      //retreiving resultset
      while (rset.next ())
      {
      result = rset.getString(1).toString();
      }  
      return result;
}
}

  • Now call method of OraJdbc class in the myPortImpl class, Your getCreditCardStatus method should look like this

      public CreditCardResponse getCreditCardStatus(CreditCardRequest part) {
        CreditCardResponse response = new CreditCardResponse();
        OraJdbc callDb = new OraJdbc();
        String result = "INVALID";

        try {
          result =  callDb.getCreditCardSatus(part.getCcNumber().intValue());
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
      
        response.setCcStatus(result);
        
        return response;
    }


Thats all you are ready to Test your service.

Testing the Webservice
  • Right click the myPortTypeImpl.java and choose Test Webserivce, an integrated WLS will start and opens a HTTP Analyzer tool which is available within JDeveloper to test the webservices.

  • Enter the Credit Card number 1234 and press Submit Request, as you can see the result on the right side is appearing as VALID (because in our table this number has a as VALID status)


  • Enter 9999 and you would see the result INVALID



Click the HTTP Context tab at the bottom to see the payload info in HTTP Format



Hope you have found the series useful, feel free to comments and ask questions i am always available to response your queries.

Download the complete workspace of Part 1,2 and 3

Happy JDeveloping,
Baig

Creating a WSDL Document - Part 2 of Creating your own Webservices in JDeveloper11g

Share this Post
Hi,

I will continue the topic of Creating your own webservices in JDeveloper and extend my last post "Creating XML Schema" in this post we will look how to create a WSDL Document, define the operations that our webservice will perform  and bind it with the XML Schema.

  • Right click the same project and choose New go to Webservices > WSDL document as shown in the slide, enter the name of the WSDL document.


  • You will see the screen similar to this



  • Now here is the little tricky part we are required to work with XML schema and WSDL at the same time and actually we can work as well so, open the XML Schema and open WSDL Document, switch to wsdl and drag the WSDL to the center bottom of the screen and drop your screen will split into 2 documents as shown in the slide.


  •  Now we can see both documents, now we have to define operations of the webservice but for this we need to have a PORT so, now press the green plus sign on the Port Type section and give it a name myPortType and press OK


  • To define operations drag the "operation" from the component palette to the port type and give a name  "getCreditCardStatus" and press OK. the operation we have defined will be  available to the consumer of the webservice you can define as many as required for simple case we are keeping to one operation.


  • Now expand the port type section as you can see the Input and output parameters are available, to link them with the XML Schema types, drag the "CreditCardRequest" element from XML Schema and drop into the INPUT parameter of getCreditCardStatus Operation.
  • Repeat the same for CreditCardResponse as OUTPUT in our operation.


  • Now drag the myPortType as a whole and drop into the Bindings sections, dialog box will appear ask you to define the type of Binding choose Soap12 leave others as default.

  • Now drag and drop the Bindings into the Services section.


Thats all for Part 2 we have succesfully completed the WSDL document.

Next Step: Generate a webservice code from WSDL document.

Happy JDeveloping,
Baig

Creating your own Webservices in JDeveloper11g Part 1 - Creating XML Schema

Share this Post
Hi,

These days my mind is in webservices mode so i will show how to create your own webservices in JDeveloper.

Creating your own webservies is a 3 step process as follows Note: You can also create webservices from Java class directly
  1. Create a XML Schema (XML schema define the structure of the webserivces)
  2. Create WSDL Document (Define the operations of Webservices)
  3. Generate Webservice from WSDL and implement code (the logic behind) and of course Test and deploy the Webservice (Output) 
You can download the sample workspace for all 3 parts 
     This post will cover the first step which is Creating XML schema

    Use case example
    • We will have a webservice which takes a input of credit card number and return the status of creadit card VALID or INVALID from the database table column "creditcard_status"
    • Following script to create sample table with data which we will use in this example (you can run the script.sql available in the project file)

    create table CreditStatus
    (creditCard_number Number,
     creditCard_status varchar2(15 char));
    
     insert into creditstatus
     values(1234,'VALID');
    
    insert into creditstatus
     values(9999,'INVALID');
      
    insert into creditstatus
     values(1111,'VALID');
    
    commit;
    

      Enough talking lets cook the Hot and Spicy webservice dish :)

      • Create an application with Generic Template as shown in the slide


      •  Create a project inside named validateCreditCard

      • Right click choose New on the Project, Go to page All Technologies >  XML > XML Schema and Press OK
      • Enter the Schema name as shown in the slide Make sure to extend the path by \public_html\WEB-INF\xsd

      • According to our scenario we need to define what will come as Input and what would be the output, so we will create a request parameter and response as CreditCardReques and CreditCardResponse.
      • Rename the first element to "CreditCardRequest", drag a sequence element from the component pallete to the CreditCardRequest element, drag a "element" component to the sequence component as shown in the slide, change the name to "ccNumber" and type to xsd:integer
      • This will act as our Input request parameter


      • Now do the same for output as well, drag the element component to the top schema element, drag a sequence, drag a element on sequence and renamed to "ccStatus" and type as "xsd:string" 
      • Your schema would look like this

      This is end of part 1

      Next Step: We will create a WSDL document, define the operation that webservice will perform and bind our XML schema with that WSDL.

      Happy JDeveloping,
      Baig

      Sunday, June 27, 2010

      Integrating external webserives into ADF fusion application

      Share this Post
      Hi,

      One of the use cases always comes to desk is to validate that user has entered a valid email address or not? now question is how to verify that the email address is valid? so answer is with the power of webservices we can verify that the email address is valid or not so again....


      How to Integrate WebServices in Fusion application? As far as i know there are 2 methods.
      1) By creating webservice data control on WSDL document provided by producer.
      2) By creating webservice proxy.

      Download the completed example 

      In this example we will look at the first method Webservice data control:
      - We will integrate external web-service which will return result TRUE or FALSE based on email input parameter.
      - When user will enter email address in a field the appropriate message will appear with the field.
      - On Commit we will also verify the output of the  the method to take further action.


      Getting the Web service 
      Visit http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=22 and get the address of WSDL document thats all you need to integrate.
       (This can be any site who provides web service)


      Test the webservice on the site by entering any email address and press invoke

      Webservice will return the boolean value based on input

      Lets integrate this webservice into out ADF fusion application

      Create a table in HR schema to use in example

      create table person_emails
      (person_name varchar2(60),
       person_email varchar2(30));
      

      Create Fusion application and Data control
      Create Business components from table for person_emails table with application module
      Right click Model project and select new follow the slides

      Copy and paste the WSDL location and paste into URL field and press Service button to validate.

      Select the methods you need to integrate in this service we have only one method


      Next Next Next Press Finish

      Now we have created a Data control so we can use it on JSF Page

      Create a JSF Page
      - Drag a collection of PersonEmail1 from data control panel to the page as ADF Form
      - Now expand EmailWSDC data control and drag the Boolean Return below the Email field and Formatted output text

      - Binding dialog will appear asking you to provide value from email parameter.
      expand the expression builder and choose PersonEmail input value as shown in the slide.


      as you can see the method is appearing in Page binding section as well

      Set AutoSubmit = TRUE of PersonEmail field
      Add a partial triggers property of Output text linking to the Email field 


      Calling Web service Method
      Choose edit from the property inspector in the ValueChangeListener of Email field and create a Managed Bean



      Define Bean method by pressing New


      In backing bean write code similar to this
      The code is executing the Action method which is already linked in the page binding by passing the current value in the email field to the parameter called "Email"


      package baigsorcl.view;
      
      import java.util.Map;
      
      import javax.faces.application.FacesMessage;
      import javax.faces.context.FacesContext;
      import javax.faces.event.ValueChangeEvent;
      
      import oracle.adf.model.BindingContext;
      
      import oracle.binding.AttributeBinding;
      import oracle.binding.BindingContainer;
      import oracle.binding.OperationBinding;
      
      
      public class Page1Bean {
      
          public Page1Bean() {
          }
          
          String emailResult;
      
          //Method to call webservice Action Method
          public boolean verifyEmail(String email) {
              BindingContainer bindings = getBindings();
              OperationBinding method = bindings.getOperationBinding("IsValidEmail");
              Map paramsMap = method.getParamsMap();
              
              //assigning parameter
              paramsMap.put("Email", email);
              Object result = method.execute();
              
              if (result.equals(true)) {
                  emailResult = "Thank you for providing valid email address";
                  return true;
              } else {
                  emailResult = "Please provide valid email";
                  return false;
              }
          }
      
          //value change listener
          public void verifyEmail(ValueChangeEvent valueChangeEvent) {
              if (valueChangeEvent.getNewValue() != null) {
                 boolean result =
      verifyEmail(valueChangeEvent.getNewValue().toString());
              }
          }
      
          public BindingContainer getBindings() {
              return BindingContext.getCurrent().getCurrentBindingsEntry();
          }
      
          //On commit Action
          public String commit_action() {
            
             //Retreive Attribute value of email id
             BindingContainer attrbindings = getBindings();  
             AttributeBinding attr =
             (AttributeBinding)attrbindings.getControlBinding("PersonEmail");  
             boolean emailExists = verifyEmail(attr.getInputValue().toString());
            
             //if method returns TRUE then commit else error message
             if (emailExists){
              BindingContainer bindings = getBindings();
              OperationBinding operationBinding =
                  bindings.getOperationBinding("Commit");
              Object result = operationBinding.execute();
              if (!operationBinding.getErrors().isEmpty()) {
                  return null;
              }
              return null;
             }
             else {
               FacesMessage msg = new
      FacesMessage(FacesMessage.SEVERITY_ERROR, "Error" , "Please provide valid email to continue...record not saved");
               FacesContext.getCurrentInstance().addMessage(null, msg);
               return null;
             }
        
          }
      
          public void setEmailResult(String emailResult) {
              this.emailResult = emailResult;
          }
      
          public String getEmailResult() {
              return emailResult;
          }
      }

      Assign the emailResult Variable to the Result output text we create for proper message

      
      

      - Run the Page enter invalid email address and tab out message will appear about invalid email address enter any valid email address and tab out or press commit

      Press Commit you will see the alert error if email is invalid


      finally enter valid email and all is well


      Explore more detail in the example

      More reading about Integrating webserives check here

      Happy JDeveloping,
      Baig