Professional Documents
Culture Documents
Yuvaraj G
Yuvaraj G 1 yuvashan21@gmail.com
Web services are XML-based information exchange systems that use the Internet for direct
application-to-application interaction. Web services are application components which communicate
using open protocols. In simple terms a Web Service is an application or business logic that is
accessible using standard Internet protocols.
Let us assume 2 applications App1(Consumer 1) and App2(Producer2). App13, where the client
resides, requests information or services from App2. App2, in turn, sends the info/services back to
App1, who displays the information to the Client.
Note: Server side implementations of App1(Consumer) & App2(Producer) can exist in the same or
diff. technologies(ie. Java, VB.net, Asp.net with C# code ,between Java and Python ,etc).
SOAP (Simple Object Access Protocol), REST (Representation State Transfer) are two Web Services
concepts.
SOAP RESTful
1)Traditional More Recent.
2)Protocol Independent (Can interact with SMTP, FTP, Protocol dependent(Only work with HTTP )
etc)
6)JAX-WS : Need web.xml and sun-jaxws.xml entry JAX-RS : Need only web.xml that also only one entry
for each service . for all services.
WSDL:
As it describes the complete contract for Application Communication. Web services are
widely approachable by using WSDL definitions to generate code(stub) that precisely knows how
to interact with the Web service(App2). It specifies that how web services(App2) are declared,
and the operations (or methods) the service exposes( ie. to know the objects, its methods, accessing
procedures which are required to call from client to Consume). For example, assuming the service
provides a single publicly available method, called sayHello. This method expects a single string
parameter and returns a single string that can be known from WSDL.
Yuvaraj G 2 yuvashan21@gmail.com
Fig 1.1: Web service
Application-to-Application Interaction(in Detail):
On receiving xml as response,To automatically bind XML data to objects (that xml tag value
should be set into the corresponding java class setters) is called as Unmarshalling((See (b) in Fig. 1.2))
, so that can be used further inside App1(Consumer) for process it or databases that store it. Converting
java files(objects) setter values into xml format is known as Marshaling((See (c) in Fig. 1.2)) that can
be done in App2(Producer) when produce the response.
Using JAXB (Java and XML Binding compiler) to generate java(JAXB) classes from
XSD(used as Input) which needed for Unmarshalling. ( See (a) in Fig. 1.2)
XSD (XML Schema Definition) is used to define a "data contract" between producers and
consumers of XML data so that each knows what to do and expect and also used to validate that a
specific XML data message meets the contract but the validation done only at debugging time in a
high-volume system since validation is expensive (See (d) in Fig. 1.2). Using XML Spy editor to
generate XSD from XML.
Yuvaraj G 3 yuvashan21@gmail.com
API:
JAX-WS,SAAJ,JAX-RS are APIs implemented for SOAP and REST respectively.
JAX-WS: JAX-WS is the successor to JAX-RPC. It requires Java 5.0, and is not backwards-
compatible to JAX-RPC .Uses RPC(Remote Procedure Call), create Stub and interact directly with the
skeleton methods and supports asynchronous communication. .The Configuration is managed by
annotations therefore Java 5 or higher is required.
JAX-RS : The Java API for RESTful Web Services. Jersey, the reference implementation of JAX-RS,
implements support for the annotations.
SAAJ: Uses SOAP Messages: Interact in terms of these msgs. SAAJ API is used to create/send/receive
SOAP msgs. It operates on a lower level than JAX-RPC or JAX-WS, both of which will use SOAP
envelopes based on SAAJ if needed. Another specification/API for using SOAP envelopes with or
without attachments.
(WADL in REST) , Apache CXF tool is using to create corresponding java files for
WSDL files. WSImport in java\bin also used to create the corresponding java files for WSDL files
without using any editors like Eclipse ,Netbeans , etc.
Note: Another need to get WSDL is to ensure that App -Web services deployed successfully in server.
How to create WSDL to java(Using your WSImport - To create Stub, which is needed
for App1 to interact with App2):
Open your command line, and enter the wsimport command(ensure that to set the java path):
i).CD %CLIENT_PROJECT_HOME%\src
ii).wsimport –s . http://ip:portno/contextpath/url-pattern?wsdl
Yuvaraj G 4 yuvashan21@gmail.com
How to create WSDL to JAVA.bat(Using Apache CXF tool):
i)JAXBContext jc =null;
ii)Unmarshaller u = null;
iii)Reader reader =null;
iv)ClassName(PurchaseOrderXml) obj = null;
v)String xml_file_content =
“<PurchaseOrderXml><ordId>123<ordId><ordQty>20<ordQty><PurchaseOrderXml>”;
|----------------> Corresponding class name for the xml root element
JAXBContext jc = null;
Marshaller m = null;
String xml_file_content = null;
StringWriter sw = new StringWritter();
jc = JAXBContext.newInstance(“package name”);
m = jc.createMarshaller();
synchronized(m)
{
m.marshall(className,sw)
|-------------> Corresponding class name for the xml root element
}
xml_file_content =sw.toString();//write the string(xml_file_content) to one xml file.
Yuvaraj G 5 yuvashan21@gmail.com
WSDL Elements mapping to Java
Yuvaraj G 6 yuvashan21@gmail.com
Best Web Service Testing tools:
I would say SoapUI, it is perfectly for installation and implementation. Now if you know some
about Web Service, you can start practice with SoupUI and xmethods.net. To test App2 without App1
use SoapUI.
The four types of JAXB binding declarations(XML-to-Java datatype binding and the customization
namespace prefix):
i)Global Binding Declarations
ii)Class Binding Declarations
iii)Schema Binding Declarations
iv)Property Binding Declarations
Note:
(1)-Consumer-consumes the data
(2)-Producer -Produce the data.
(3)-App1 can be Stand Alone App or Web Application
Yuvaraj G 7 yuvashan21@gmail.com