You are on page 1of 9

24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse

http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 1/9
F R I D A Y, J UL Y 8 , 2 0 1 1
Getting Started - XQuery Dev inside OSB Eclipse
Prerequisite
Should have installed OSB
Basics understanding of middleware technology.
Introduction
We can use XQuery/XSL in OSB to do the message
transformation. But XQuery is preferred over the XSL because of
the performance advantage. In this post I will show how to
develop an xquery using the osb workshop eclipse.
XQuery - Introduction
XQuery is a light weight language which has got an xml like
syntax. XQuery has 3 important parts as below
1. Namespace declaration
2. Set of function with their implementations
3. Declaration of variables
4. Mentioning the function with which the execution begins.
For further understanding of the XQuery you can refer
http://www.w3schools.com/xquery/xquery_intro.asp
Sample XQuery
Listing-1 xquery version "1.0" encoding "Cp1252";
Listing-2 (:: pragma parameter="$anyType1" type="xs:anyType"
::)
Listing-3 (:: pragma type="xs:anyType" ::)
Listing-4 declare namespace xf =
"http://tempuri.org/OSB%20Project%203/sample/";
Listing-5 declare namespace ns1 =
"http://tempuri.org/OSB%20Project%203/sample/inputaddress";
Listing-6 declare namespace ns2 =
B L O G A R C HI V E
2012 (2)
2011 (4)
July (3)
Weblogic JMS Basics
Getting Started - XQuery Dev
inside OSB Eclipse
OSB Dev using Eclipse -
Getting Started
June (1)
P O P UL A R P O S T S
OSB Dev using Eclipse -
Getting Started
Introduction I hope that
you have installed OSB
11g and created domain.
Now it is the time to make your
hands dirty. I will explain to ...
Getting Started - XQuery
Dev inside OSB Eclipse
Prerequisite Should have
installed OSB Basics
understanding of
middleware technology.
Introduction We can use
XQuery/XSL in OSB t...
Attachment Handling using Oracle
Service Bus (OSB)
1. Introduction Oracle
0

More

Next Blog Create Blog

Sign In
ORAC L E S E RVI C E B US
T HI S I S A B L O G D E D I C A T E D T O O R A C L E S E R V I C E B US R E L A T E D C O NC E P T S WHI C H WI L L B E
HE L P F UL F O R E V E R YO NE T O UND E R S T A ND A ND I M P L E M E NT T HE V A R I O US F E A T UR E S I T
P R O V I D E S .
24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse
http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 2/9
"http://tempuri.org/OSB%20Project%203/sample/outputaddress
";
Listing-7
Listing-8 declare function xf:sample($requestDoc as element(*))
Listing-9 as element(*)
Listing-10 {
Listing-11 <ns2:Address>
Listing-12 <ns2:name>
Listing-13 {
Listing-14 $requestDoc/ns1:FirstName/text()
Listing-15 }
Listing-16 </ns2:name>
Listing-17 <ns2:phone>
Listing-18 {
Listing-19 $requestDoc/ns1:PhoneNumber/text()
Listing-20 }
Listing-21 </ns2:phone>
Listing-22 </ns2:Address>
Listing-23 };
Listing-24
Listing-25 declare variable $requestDoc as element(*) external;
Listing-26
Listing-27 xf:sample($requestDoc)
Explanation
Listing 1 - declaration of xquery
Listing 2 to 3 - comments
Listing 4 to 6 - Namespace declarations
Listing 8 to 9
This is the code snippet for the function 'sample' which takes
'requestDoc' which is of type element(*), that is the xml. It
returns the type element(*) which is also an xml.
Listing 10 - shows the start of the xquery function
Listing 23 - shows the end of the xquery function
Listing 11 to 22 - the body of the function 'sample'
Here we are doing the transformation. What ever we write it in
these lines will be the final output of the
xquery tranformation
Listing 14 or 19 - Here we are assigning the data obtained from
request xml to the output response xml.
Listing 25 - declaring the request variable 'requestDoc' as 'external'
as type 'element(*)'. So when we test this xquery from the OSB
Fusion 11g is an
enterprise ready family
of integration products
from Oracle. ...
Oracle Fusion Middleware PPT
This will give an introduction to
Oracle Fusion Middleware and
spots where the Oracle Service Bus
stands in the Oracle Middleware
products. ...
Oracle Service Bus (OSB) Performance
Tuning tips
Once you are comfortable with
developing and deploying
applications in OSB, the next thing
that comes for you will be how fast
yo...
Weblogic JMS Basics
Slide 28 l Introduction
The Java Messaging
Service (JMS) is a Java
Message Oriented
Middleware (MOM) API for sending
messages between t...
F O L L O WE R S
Join this site
with Google Friend Connect
Members (10)
Already a member? Sign in
A B O UT M E
24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse
http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 3/9
flow, we will bind the request xml with 'requestDoc' variable and
we can transform the request xml to the response xml.
Listing 27 - This is the last line of the xquery where the execution
of the xquery begins. Suppose if we have multiple functions, what
ever function is given in the last line of xquery will be the entry
point of execution.
Development of XQuery in OSB Workshop - Eclipse
Open the eclipse and create a project . Right click on the
project and create a new xquery
Give some name
Now give the request binding variables.
Here I have added only one variable.
Give the 'Parameter Name' as 'requestDoc' and click on 'Add' so
that we can add the request binding variable.
SAJEEV RAMAKRI SHNAN
Like yours, I also wear the hat of
many roles, like son, uncle,
brother,friend,lover,employee,
technologist,guide, instrumentalist
and so one. But I don't know who I
am I.
V I EW MY COMPLETE PROFI LE
24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse
http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 4/9
Similarly mention the response also
Now we have created the xquery. It will be now opened in the osb
eclipse editor. The editor has 3 parts.
1. Design
2. Source
3. Test
We can use 'Design' part if we have the source and destination
schemas.
24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse
http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 5/9
Now click on 'Source' and you can see the xquery source code.
Now modify the xquery as below
xquery version "1.0" encoding "Cp1252";
(:: pragma parameter="$anyType1" type="xs:anyType" ::)
(:: pragma type="xs:anyType" ::)
declare namespace xf =
"http://tempuri.org/OSB%20Project%203/sample/";
declare namespace ns1 =
"http://tempuri.org/OSB%20Project%203/sample/inputaddress";
declare namespace ns2 =
"http://tempuri.org/OSB%20Project%203/sample/outputaddress
";
declare function xf:sample($requestDoc as element(*))
as element(*)
{
<ns2:Address>
<ns2:name>
{
$requestDoc/ns1:FirstName/text()
}
</ns2:name>
<ns2:phone>
{
$requestDoc/ns1:PhoneNumber/text()
}
24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse
http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 6/9
</ns2:phone>
</ns2:Address>
};
declare variable $requestDoc as element(*) external;
xf:sample($requestDoc)
Sample request xml for Testing
<ns1:AddressDetails
xmlns:ns1="http://tempuri.org/OSB%20Project%203/sample/in
putaddress">
<ns1:FirstName>Sajeev</ns1:FirstName>
<ns1:PhoneNumber>09962551082</ns1:PhoneNumber>
</ns1:AddressDetails>
Testing the application
Now Click on the 'Test' tab inside the xquery editor for testing
Now we have successfully created an xquery and tested it.
Testing the XQuery inside OSB Message Flow
Create a new sample osb project. If you are a beginner you can
refer the below post
Create a Sample HTTP-HTTP flow in OSB
In the request flow drag one 'replace' node
24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse
http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 7/9
Click on 'XPath' and enter the value as '*'
In Variable : body
Now click on 'Expresssion' and click on 'XQuery Resource' and
browse to the sample xquery
and enter $body/* into the 'requestDoc'.
Now you can deploy the application and test it.
Conclusion
This topic is intended to give an introduction to Xquery
development and using the same inside the osb message flow. You
can better explore more.
Queries?
please contact Sajeev Ramakrishnan
@ sajurrk@gmail.com
@ saju_rrk@yahoo.com
24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse
http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 8/9
Newer Post Older Post


POSTED BY SAJEEV RAMAKRI SHNAN AT 11: 51 PM
NO C OMME NT S:
POST A C OMME NT
Enter your comment...
Comment as:
Google Account
Publish

Preview
Home
Recommend this on Google
24/7/2014 Oracle Service Bus: Getting Started - XQuery Dev inside OSB Eclipse
http://osb-soa.blogspot.in/2011/07/getting-started-xquery-dev-inside-osb.html 9/9
Subscribe to: Post Comments (Atom)

F O L L O W B Y E M A I L
Email address... Submit

You might also like