In this tutorial I’ll show you, how to implement your first webservice in Oracle SOA Suite using Mediator component. Additionaly you will learn how to create XSD files, deploy SOA Composite Application to SOA Server and test it.
Create SCA (SOA Composite Application)
To create new SOA Application project go to Menu->File->New From Gallery->SOA Application.
Choose the application name and package prefix and click next.
Enter project name and go next.
On the last step choose Empty Composite and click Finish.
After the completion of processing you see SOA Project(if not, double click ST03HelloWorldProject from project tree).
The left side “Exposed Services” is what our service expose. It might be WebService, JMS or Database QA Adapter, listening on directory, Event and much more. In other words it’s entry point/trigger/external interface of composit.
The right site “External References” is what external resources our composit may use ie. other service, database adapter, directory.
In the middle is a place for internal logic Components.
Create contract
There is unwritten principle in SOA – “contract first”. It means first define the contract of your service then implement it.
The first step is to create XML Schema (XSD) describes input and output of the service. Create XML Schema file HelloWorld.xml in Schemas directory.
Enter the file name “HelloWorld.xsd” , namespace “http://better-coding.com/soa/tutorial03” and prefix “bcst3”.
Click OK.
Now using “complexType”, “sequence” and “element” try to design request and response structure as below.
In case of trouble just past inside source tab.
<?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:bcst3="http://better-coding.com/soa/tutorial03" targetNamespace="http://better-coding.com/soa/tutorial03" elementFormDefault="qualified"> <xsd:element name="helloWorldRequest" type="bcst3:THelloWorldRequest"> <xsd:annotation> <xsd:documentation>A sample element</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="helloWorldResponse" type="bcst3:THelloWorldResponse"/> <xsd:complexType name="THelloWorldRequest"> <xsd:sequence> <xsd:element name="firstName" type="xsd:string"/> <xsd:element name="lastName" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="THelloWorldResponse"> <xsd:sequence> <xsd:element name="message" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:schema>
Create Mediator component
Mediator is a compotent that allows routing and transforming messages. We use it to implement HelloWorld service.
Go to project diagram. Drag Mediator component and drop into Components diagram.
Enter “HelloWorldMediator” as name and select “Interface Definition from WSDL” then click “Generate…” icon.
Enter “helloworld_ptt” (1) as Port Type and “hello” as operation name(2). Then add input message(3). Enter “request” as part name (4) and choose helloWorldRequest Type from schema (5,6,7).
Do the same for response and click ok.
As you can see our composite exposes HelloWorldMediator web service with hello operation.
Service implementation using mediator
Edit mediator component. Double click on it, choose from project structure od right click and edit.
Click Add and the “Echo Reply”. Click OK.
Click “Assign icon”, then “Assign Source Expression…” and enter the expression:
concat('Hello ', $in.request/inp1:helloWorldRequest/inp1:firstName, ' ', $in.request/inp1:helloWorldRequest/inp1:lastName, '!')
Click OK, and connect expression value to output message:
Click ok and save All. Out service is ready for deploy and test.
Deploy SCA to SOA Server
Ensure your SOA Server is running.
Right click on project -> Deploy -> ST03HelloWorldProject. Deploy to Application Server. Next.
Mark “Overwrite any existing composites…” and click next.
Choose CompactDomain and click Next. Then select AdminServer and click Next and Finish.
If everything was ok, you will see “Deployment Finished” message.
Testing
In this part I’ll show you how to test deployed Web Service from Oracle Enterprise Manager. If you want you can do this using ie SoapUI.
LogIn into Oracle EM: http://localhost:7001/em using weblogic/welcome1 as user and password.
Go to ST03HelloWorldProject SCA(1,2,3) and click Test(4).
As you can see the WSDL is:
http://localhost:7001/soa-infra/services/default/ST03HelloWorldProject/HelloWorldMediator_ep?WSDL
Fill the request message and click “Test Web Service”.
Check the response.
Our first service works fine. In the next parts of this tutorial I’ll show you how to create complex services, BPEL processes and debugging.