95-843 Service Oriented Architecture Carnegie Mellon University
Assigned: Tuesday, April 16, 2013 Homework 4
Due: Friday, May 3 2013, 11:59:00 PM
When you have completed this project, notify your TA by email.
In your email, provide your machine name and your application and
project names and any instructions that may be useful. You will need
to provide your password as well.
Since Parts 1 - 3 of this project build on itself, you need only submit
the last part that you complete. In other words, if you are unable to
complete Part 3 but have completed Parts 1, and 2, then only submit
Part 2. You will automatically receive credit for Part 1.
Part 4 is independent of the others and needs to completed separately.
This project has been adapted from the course text "Oracle SOA Suite 11g
R1 Developer's Guide" and is found in chapter 5. The example from chapter 5 uses
web services that exist on the web. In replace of those services, we will be using
the two services shown below. These are meant to act as simpler examples of the same
functionality as described in Chapter 5. You will build a BPEL process that interacts
with these two web services.
One service will provide stock price information for exactly
two stocks, IBM and USX. The java code for this service is shown
here:
package stockquote;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.Endpoint;
@WebService
public class StockQuote {
@WebMethod
public double getQuote(String stockSymbol) {
System.out.println("Returning quote for " + stockSymbol);
if(stockSymbol.equals("IBM")) return 103.24;
if(stockSymbol.equals("USX")) return 34.56;
return 0.0;
}
public static void main(String[] args){
StockQuote la = new StockQuote();
Endpoint endpoint =
Endpoint.publish(
"http://128.2.144.170:8082/stockquote",
la);
}
}
The other service will provide a currency conversion rate for a few countries.
It is shown here:
package currencyconvertor;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.xml.ws.Endpoint;
@WebService
public class CurrencyConvertor {
@WebMethod
public double convertFromTo(String from, String to) {
System.out.println("Returning rate for " + from + " to " + to);
if(from.equals("USD") && to.equals("CAD")) {
return 1.03;
}
if(from.equals("USD") && to.equals("AUD")) {
return 0.97;
}
if(from.equals("USD") && to.equals("YEN")) {
return 99.38;
}
return 0.0;
}
public static void main(String[] args){
CurrencyConvertor la = new CurrencyConvertor();
Endpoint endpoint =
Endpoint.publish(
"http://128.2.144.170:8080/currencyconvertor",
la);
}
}
Parts one and two describe the construction of a synchronous BPEL process. Part
three asks that you add switch and flow statements to your work in part two.
Part 1. Build a simple BPEL process that interacts with these two services.
0) In order to use the currency converter service, you will save the WSDL
located at http://128.2.144.170:8080/currencyconvertor?wsdl to the file
C:\OracleSOASuite11gDevelopersGuide\Chapter05\CurrencyConvertor.wsdl.
1) In order to use the stock quote service, you will need the WSDL found here:
http://128.2.144.170:8082/stockquote?wsdl. Save this stock quote WSDL file
to the virtual machine's C: drive under the name
C:\OracleSOASuite11gDevelopersGuide\Chapter05\StockQuotes.wsdl.
2) We will use the following XSD file from the course text. Save it to
C:\OracleSOASuite11gDevelopersGuide\Chapter05\StockService.xsd. You
may copy and paste this xsd file from this document.
3) Our web service, the one we are writing in BPEL, will use the XSD above. The
stock quote service is defined in the stock quote WSDL. We will need to
build a mapping from our service vocabulary to the external service's
vocabulary.
4) In JDeveloper, create a new SOA Application. Its name is
StockQuoteApplication.
The Project name is StockQuoteProject. Create an empty composite.
5) Drag a BPEL component onto the composite. Its name is StockQuoteBPEL. It will
be a SOAP based synchronous service and we want the input to this BPEL process and
the output from this BPEL process to be defined based upon the vocabulary
expressed in the XSD above. Use the magnifying glass icon to the right of the
input and output text boxes to browse the file system. The Type Chooser has
an Input Schema button on the top right. On the Input Schema File wizard use
the magnifying glass icon again to browse to the StockService.xsd. We can
now select from this vocabulary. Use the GetQuote for the input to the
BPEL process and use the GetQuoteResponse for the output.
6) Right click and add a partner link to the right on the BPEL process (not the composite).
Its name will be stockquoteservice and it will be based on the wsdl that we retrieved.
Use the magnifying glass icon to browse for the StockQuote.wsdl. Choose
OK to prompts asking if it's OK to extend or move the file. Choose the
partner role as StockQuote_role. Leave the My Role selection as
unspecified (this is a synchronous call and only one interface is required.)
7) Place an invoke activity onto your BPEL diagram. Name the invoke "CallStockQuote".
Connect the invoke to the partner link by clicking and dragging an arrow. From the
wizard, choose the GetQuote operation. We want to name the input and output variables of
this service. Use the green plus sign on the wizard to name the variables
StockQuoteInput and StockQuoteOutput respectively. Note that the types of these
variables are already defined in the WSDL.
8) The inputs and the outputs of the BPEL process are defined with a different
vocabulary than the inputs and outputs of the StockQuote service. Use the assign
activity to perform a mapping from the BPEL variables to the StockQuote variables.
Drag two assign activities onto the BPEL diagram - one before the invoke and
one after. Name the first "prepareToCall" and name the second "gatherResponse".
This is done by double clicking the assign activity and choosing the General tab.
Use the assign wizard to connect the correct BPEL input to the correct StockQuote
input. The input variable to the BPEL process has a stockSymbol variable and the
input to the StockQuoteService has a variable named arg0. Note that two different
namespaces are being used.
In the GatherResponse assign we want to map the output of the StockQuote service to
the output of our BPEL process. You may also use the original BPEL process input
variable to supply
data for the final output variable. To add the currency string 'USD' to the
output drag the function symbol onto the currency output variable.
Enter the string constant 'USD' in the expression box. Include the single quotes.
9) Deploy the StockQuoteProject to the application server. This is done by right
clicking the project, choosing deploy and specifying an existing connection.
10) Visit the Enterprise Manager web application. This is located at
http://localhost:7001/em. Log on with your username and password.
Part 2. Access a web service that performs currency conversion.
1) Create a new partner link and name it CurrencyConvertor. Associate the new
partner link with the currency convertor WSDL. This will be a synchronous
SOAP based web service with My Role set to not specified.
2) Create a new Invoke activity that uses the new partner to convert from USD
to the currency specified in the original request from the originating client.
Perform this invoke before returning the converted price to the client.
3) Add two assign activities. One just prior to and another just after the call
to the currency convertor. The first will prepare to call the currency convertor
and the second will be used to compute a stock price based on the value returned
by the currency convertor and the value returned by the StockQuote service.
To create the second assign activity, drag the function symbol to the
output variable. (This is the output variable for the entire BPEL process.)
This will open up an expression builder. You may then build XPath expressions
and use multiplication to compute the final result.
4) When deploying the new service be sure to select the "Overwrite" check box
so that you overwrite the previous composite on the administration server.
Test the new service by looking up IBM's stock price in Canadian currency
"CAD'.
Part 3. Add a test condition to your process so that the currency conversion service
is not used when the visitor requests currency in US Dollars. Assume that the
StockQuoteService already returns the stock price in US dollars, so, in this case,
the conversion step is not needed. If currency conversion is required then, of course,
both services need to be called. At a minimum, call these services sequentially.
For full credit, call them in parallel.
Part 4. Write a simple asynchronous BPEL process. The grader will come to visit your VM. Be
sure that AsynchronousExampleProject is ready for deployment and testing.
1) Create a new SOA Application named AsynchronousExampleApplication. Name the
project AsynchronousExampleProject.
2) Add an asynchronous BPEL component named AsynchronousExampleBPELProcess.
3) Add an assign activity that takes the input string and copies it to the output.
4) After the assign activity, add a wait activity that causes the process to pause
for 2 minutes before making a callback on the client (with an invoke).
5) Deploy and test this service. Try launching the flow trace under the response tab.
Select flow next to audit trail. Double click on call back client.