Professional Documents
Culture Documents
com/practicalbpm/entry/creating_a_web_service_proxy
1 of 22
Oracle
Blogs Home
Products & Services
Downloads
Support
Partners
Communities
About
Login
Oracle Blog
Solving Business Challenges with Oracle's BPM Suite
tidbits of knowledge from frontline implementers of Oracle's BPM Suite
Abstract
There is more than one way to design your ADF application to consume web services. One example is to use the ADF
wizards to create data controls to access the web service. Another example is to use the ADF wizards to create a proxy to
the web service you want to consume. This article is an example of the proxy development process.
Introduction
Oracle has made it extremely easy to quickly develop a body of customizable code that can consume a web service. If there
are complexities, they will be involved in the creation of the object that is transported as a SOAP message in the web
service transmissions. Otherwise, the wizard gets you to a place very quickly where you can utilize the targeted web
service.
There are a large number of public web services you can use to practice creating ADF code to consume the web service.
Just query on the Internet for "public web services". One site is www.service-repository.com. The web service I have
selected for this example is Top Movies.
This development example is completed using JDeveloper 11g Release 1 (11.1.1.4.0).
Overview
The following summarizes what is accomplished in this article.
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
2 of 22
Construction
Create the Application
Start the Create Application Wizard
Open up JDeveloper. Click on the Application Menu > New.
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
3 of 22
The wizard will add an additional step > Project Java Settings.
You will see that 2 technologies were added to the selected window: Java and Web Services.
Click Next
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
4 of 22
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
5 of 22
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
6 of 22
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
7 of 22
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
8 of 22
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
9 of 22
Accept the default selection "Generate asynchronous methods where specified by the JAX-WS binding"
Click Next
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
10 of 22
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
11 of 22
Project View
Numerous class files and supporting files such as the WSDL file are generated. Below is a screenshot of the WebServices
Project structure that is generated with the proxy web service wizard.
WSDL Location
wsdl:service name="TopMovies"
TopMovies.java
You will always have one class file generated for your service
with the name "serviceName.java"
wsdl: portType name="TopMoviesSoap"
TopMoviesSoap.java
Also contains the methods used to invoke the web service
wsdl: binding name="TopMoviesSoap12Client"
TopMoviesSoap12Client.java
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
12 of 22
TopMoviesProxy
Types Section
WSDL Location
ArrayOfString.java
s:complexType name="ArrayOfString"
GetMovieAtNumber.java
s:complexType name="GetMovieAtNumber"
GetMovieAtNumberResponse.java
GetTop10.java
s:element name="GetTop10"
GetTop10Response.java
s:element name="GetTop10Response"
ObjectFactory.java
package-info.java
Notice that there are two bindings. The binding with name "TopMoviesSoap12" is a SOAP 1.2 binding
element. The binding with name "TopMoviesSoap" is a SOAP 1.1 binding. You can find additional information
about the two supported formats with a search on the Internet. Many WSDL files provide both bindings for
backward compatibility. There are three key differences of SOAP 1.2 over SOAP 1.1:
1) A new namespace: http://schemas.xmlsoap.org/wsdl/soap12/
2) The encodingStyle attribute is now a single URI, instead of a list of URIs
3) There is a new attribute: soapActionRequired, which is used to indicated that the server needs the
SOAPAction value.
2. The binding element provides a container for information such as the protocol and the operation of the Web
service. The transport attribute is the protocol.
In the binding element you can identify the operations that can be executed when consuming the web service and these
become the methods used within the Java template code with "Client" in the class name (e.g. TopMoviesSoapClient.java).
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
13 of 22
Create a Driver
The next step is to create our code that will execute the newly created methods and consume the Top Movies web service.
The job of accomplishing this is made easier by reviewing either the TopMoviesSoapClient.java or
TopMoviesSoap12Client.java class files. Each of these serve as a starting point to writing your own code to execute the
operations you want to target.
Below is a segment of the TopMoviesSoapClient.java:
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
14 of 22
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
15 of 22
package webservices;
import com.topmovie.TopMovies;
import com.topmovie.TopMoviesSoap;
import com.topmovie.types.ArrayOfString;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
import oracle.xquery.parser.Qname;
public class TopMovieWS {
private static TopMovies topMovies;
public TopMovieWS() {
super();
}
public static void main(String[] args) {
int movieRank = 1;
// sample from TopMoviesSoapClient.java
topMovies = new TopMovies();
QName serviceName = topMovies.getServiceName();
System.out.println("Service Name: " + serviceName + "\n");
URL wsdlDocumentLocation = topMovies.getWSDLDocumentLocation();
System.out.println("WSDL Location: " + wsdlDocumentLocation);
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
16 of 22
Sample of Output
Below is a sample of the output produced by the code.
Service Name: {http://www.kirupafx.com}TopMovies
WSDL Location: http://www.kirupafx.com/WebService/TopMovies.asmx/#%7Bhttp%3A%2F%2Fwww.kirupafx.com%7DTopMovies?wsdl
WSDL Location without URL Escape codes: http://www.kirupafx.com/WebService/TopMovies.asmx/#{http://www.kirupafx.com}TopMovies?wsdl
Note that the WSDL location is a combination of the WSDL URL plus the Service Name.
SOAP 1.1 binding - Movie at number 2 is The Godfather: Part II (1974)
SOAP 1.2 binding - Movie at number 2 is The Godfather: Part II (1974)
1. Top 10 Movie: The Godfather (1972)
2. Top 10 Movie: The Shawshank Redemption (1994)
3. Top 10 Movie: The Godfather: Part II (1974)
4. Top 10 Movie: The Lord of the Rings: The Return of the King (2003)
5. Top 10 Movie: Casablanca
6. Top 10 Movie: Schindler's List
7. Top 10 Movie: Shichinin no samurai (1954)
8. Top 10 Movie: Buono, il brutto, il cattivo, Il (1966)
9. Top 10 Movie: Pulp Fiction (1994)
10. Top 10 Movie: Star Wars: Episode V - The Empire Strikes Back (1980)
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
17 of 22
As developers we will most likely be working in a setting that has the traditional division of environments (e.g.
Development, Testing, QA, PreProduction, Production). When this is your setting you will most likely have a separate
WSDL file for the web service(s) to be consumed. If this is your case, then you must also prepare your code to make
migrations easier.
The code generated by the wizard is very specifically tied to the addresses provided in your WSDL file. Consequently, if
you migrate your code from a development environment to a test environment, your code will be calling the development
web service by default. This needs to be corrected for the migration process.
There are at least four ways that I know about to accomplish this:
1. Hard code your changes for each migration
2. Make references to each environment's WSDL in the connections.xml file
3. Use the BindingProvider Interface
4. Use one of the additional constructors provided in the generated Java code where the class file name is the
ServiceName.java (our example is TopMovies.java)
For this discussion I will illustrate using one of the additional constructors for the TopMovies.java class file.
You must supply the wsdlLocation and the serviceName. One way you can use this in multiple environments is to store
your WSDL location for that corresponding environment in a file (topMovies.properties for example). You write your code
to read the targeted properties file and retrieve the designated WSDL location.
Below is my sample code with the new code (in yellow) needed to call the constructor with two parameters. I have hard
coded the wsdlLocation but in a multi-environment setting you will use another means to supply the wsdlLocation based
upon the current environment.
package webservices;
import com.topmovie.TopMovies;
import com.topmovie.TopMoviesSoap;
import com.topmovie.types.ArrayOfString;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Iterator;
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
18 of 22
import java.util.List;
import javax.xml.namespace.QName;
import oracle.xquery.parser.Qname;
public class TopMovieWS {
private static TopMovies topMovies;
public TopMovieWS() {
super();
}
public static void main(String[] args) {
int movieRank = 1;
URL topMoviesURL = null;
try {
topMoviesURL = new URL("http://www.kirupafx.com/WebService/TopMovies.asmx?wsdl");
} catch (MalformedURLException e) {
System.out.println("An error occurred creating the URL: " + e.toString());
}
QName qualifiedName = new QName("http://www.kirupafx.com", "TopMovies");
topMovies = new TopMovies(topMoviesURL, qualifiedName);
QName serviceName = topMovies.getServiceName();
System.out.println("Service Name: " + serviceName + "\n");
URL wsdlDocumentLocation = topMovies.getWSDLDocumentLocation();
System.out.println("WSDL Location: " + wsdlDocumentLocation);
URLDecoder decoder = new URLDecoder();
String decodedURL = null;
try {
decodedURL = decoder.decode(wsdlDocumentLocation.toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
System.out.println("Error");
}
System.out.println("WSDL Location without URL Escape codes: " + decodedURL);
// consume the web service with SOAP 1.1 binding
TopMoviesSoap topMoviesSoap = topMovies.getTopMoviesSoap();
movieRank = 2;
String movieAtNumber = topMoviesSoap.getMovieAtNumber(movieRank);
System.out.println("SOAP 1.1 binding - Movie at number " + movieRank + " is " +
movieAtNumber + "\n");
// consume the web service with SOAP 1.2 binding
TopMoviesSoap topMoviesSoap12Client = topMovies.getTopMoviesSoap12();
movieAtNumber = topMoviesSoap12Client.getMovieAtNumber(movieRank);
System.out.println("SOAP 1.2 binding - Movie at number " + movieRank + " is " +
movieAtNumber + "\n");
// also execute the Top 10 Movie operation
TopMoviesSoap top10MoviesSoap = topMovies.getTopMoviesSoap();
ArrayOfString top10MoviesArrayOfString = top10MoviesSoap.getTop10();
List listOfTop10Movies = top10MoviesArrayOfString.getString();
Iterator iterator = listOfTop10Movies.iterator();
int iMovieCount = 0;
while (iterator.hasNext()) {
String movieDesc = (String)iterator.next();
iMovieCount++;
System.out.println(iMovieCount + ". Top 10 Movie: " + movieDesc);
}
}
}
The qualified name logic used in the code above was found by referring to line 67 in TopMovies.java (shown in yellow
below).
public TopMovies()
{
super(wsdlLocationURL,
new QName("http://www.kirupafx.com", "TopMovies"));
}
The URL is simply the place where the WSDL file is located. If you add this code to your previous TopMovieWS.java you
and run it you will notice a slight difference in the display of the wsdlDocumentLocation:
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
19 of 22
The display now reflects the URL assignment you made in your code.
Summary
Once you know how, ADF development to support consuming web services becomes a very simple and straight forward
task. The heavy lifting has already been done for you. You only need to provide the parameter values needed to execute
your targeted operations and when necessary, make adjustments to allow for code migration from one environment to
another.
Additional Resources
Harvard Lecture by Prof. David J. Malan about Web Services, SOAP 1.2, and WSDL 1.1
W3C: From SOAP/1.1 to SOAP Version 1.2 in 9 points
Oracle: Integrating Web Services Into a Fusion Web Application
JDeveloper Tutorial - Developing an ADF Client Using a Web Service Data Control
Oracle: Calling a Web Service from an Application Module
Category: ADF
Tags: adf bindingprovider proxy webservice ws
Permanent link to this entry
Source Code Control... | Main | Writing Human Task...
Comments:
Hi, This is very informative blog. I have a question here.
Can we refer wsdl stored in MDS repository while creating a proxy?
Also in ADF we can expose AM methods as webservice. How can we push wsdl generated to MDS repository.
Thanks
Sanjeev.
Posted by Sanjeev on March 20, 2012 at 11:16 PM PDT #
Great tutorial , i have a question can i consume a data from a normal web page , i mean like in the old fashin ( parsing
external web page extractin the needed information and provide it as datacontrol to UI in our application ) i know it can be
done by programming the methond in normal way and then expose the method as service , my question is exist an easier
way ??
thnx in advance
Posted by Chaddy on July 16, 2012 at 01:38 PM PDT #
Post a Comment:
Name:
E-Mail:
URL:
Notify me by email of new comments
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
20 of 22
Remember Information?
Your Comment:
HTML Syntax: NOT allowed
Please answer this simple math question
0 + 11 =
About
This blog was created to share bite sized bits of information picked up in the field by Oracle's team of solution consultants
.net
11g
adf
albpm
bindingprovider
bpm
c#
code
composer
content
control
deployment
human
identity
integration
jdev
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
21 of 22
mds
obpm
portlet
propagation
proxy
source
svn
task
tasklist
ubpm
ucm
version
versioning
webcenter
weblogic
webservice
ws
Categories
101
ADF
Best Practices
Design Patterns
Integration
Oracle
Personal
Archives
October 2014
SunMon Tue Wed Thu Fri Sat
1
2 3 4
5 6
7 8
9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Today
Bookmarks
Events
Oracle Technology Network
Oracle Technology Network Blog
Recent Articles
Technology Newsletters
Menu
Blogs Home
Weblog
Login
Feeds
RSS
All
/101
/ADF
22-10-2014 22:47
Creating a Web Service Proxy in ADF to Consume a Web Service (Solv... https://blogs.oracle.com/practicalbpm/entry/creating_a_web_service_proxy
22 of 22
/Best Practices
/Design Patterns
/Integration
/Oracle
/Personal
Comments
Atom
All
/101
/ADF
/Best Practices
/Design Patterns
/Integration
/Oracle
/Personal
Comments
The views expressed on this blog are those of the author and do not necessarily reflect the views of Oracle. Terms of Use |
Your Privacy Rights | Cookie Preferences
22-10-2014 22:47