A Java Web service uses one or more of the following components:
The following sections discuss these components in brief.
Servlets are special Java programs that enhance the existing functionality of a Web site. These programs are deployed on the Web server that supports Java. You can include servlets in your Web site to make it dynamic. For example, you can include a Java servlet to display a welcome message to a user who logs on to a Web service. Servlets created by using Java offer several benefits:
To invoke a servlet, a client application needs to send in a request by using the HTTP GET or the HTTP POST methods. Then, the Web server processes the request and sends the result to the Web browser or the client application.
Java Server Pages
Java Server Pages (JSP) is another technology that is used to create dynamic Web pages. JSP provides encapsulation of the code of the Web page by separating the code written using Java from the interface of the Web page.
A JSP page contains HTML and JSP constructs. When a request is sent for a JSP page for the first time, the HTML and the JSP constructs in a JSP source file are compiled and converted into a servlet. After that, the servlets are loaded to handle any further request. Therefore, whenever a request for a JSP file is made, the Web server executes the respective servlet.
As discussed, a JSP source file contains JSP constructs. These constructs enable you to include code written in Java in a JSP page and provide the business logic or the programming code for the JSP page. The following list discusses the categories of JSP constructs:
The JSP directives contain several attributes that store the information about a JSP page. These attributes are defined in Table.
Attributes of JSP Directives
Types of JSP Comments
Types of JSP Actions
As already discussed, the Java platform provides you with several APIs that you can use to create Web services and Web applications with the Java programming language. Java API for XML Processing (JAXP) is one such API that is used to process and transform XML documents.
JAXP, developed by JavaSoft and the JCP community, is a Java API that is used to easily and efficiently process XML documents. To do this, JAXP uses several parsers and applications that are created using the Java programming language. JAXP is a standard available in the Java XML Pack (JAX-Pack) and Java WSDP.
JAXP supports the industry standards, such as SOAP, UDDI, and WSDL. As you know, these industry standards are based on XML; therefore, it becomes important to have an API that processes an XML document. As a result, JAXP specifications were developed that allow you to access, convert, and process XML documents.
The latest version of JAXP specifications is version 1.2. You can download this version from the official Web site of JCP (http:// java.sun.com/ aboutJava / communityprocess /jsr /jsr_063_jaxp.html) as a JSR 63 document.
This version of JAXP includes support for XSLT and XML schema. The following list discusses the versions of specifications that are included in JAXP 1.2:
As discussed, Java APIs are flexible. This flexibility of JAXP is achieved because of the pluggability layer, which allows you to use XML parsers from your Web application. In addition, this layer allows you to plug an XSLT processor so that you can serialize XML data into various formats.
However, it is important to note that JAXP does not parse the XML documents. To do so, JAXP uses already-existing industry specifications. These specifications include Simple API for XML Parsing (SAX) and Document Object Model (DOM), as explained in the following sections.
The SAX specifications provide means to serially access an XML document. To do so, SAX uses a data stream; therefore, it's an event-based parser. The data stream serially reads data from top to bottom in an XML document and notifies the application about syntax construction. To notify the running application, the SAX API uses the ContentHandler interface. This interface contains several methods that are called whenever the SAX parser comes across a tag.
For example, the startElement() method is called for the < (start of element) tag, and the endElement() method is called for the /> (end of element tag). To understand the working of a SAX parser, consider the following example of an XML document:
To parse the previous XML document, the XML parser performs the following steps:
Note?/td>The characters() method parses character data. This method also lies in the ContentHandler interface.
The previous steps are used to parse the XML document according to the SAX specifications. However, it is important to note that the SAX parsers do not explicitly parse an XML document. To do so, you need to perform the following steps:
The W3C DOM Working Group developed the DOM API to access an XML document in the form of an object tree. The DOM API contains several interfaces that contain methods, such as insert() and remove(). These methods allow you to modify an object tree by adding or deleting elements, respectively.
As a result of the tree-like structure, a user can randomly acces data by using the DOM API. In addition, by using a SAX parser, you can only read data from an XML document. However, in contrast, a DOM API allows you to add or delete elements from the XML document. Therefore, a DOM parser is used when a user needs to modify the existing XML document. On the other hand, the SAX parser is used when you need to access small pieces of data. This is because a DOM parser requires the tree object of the whole XML document to be placed in the memory. As a result, if the document is large enough, the search for a small piece of data will be time consuming and, therefore, less efficient.
The steps to access a DOM parser are the same as for that of the SAX parser, as explained in the previous section.
Java API for XML Binding
Java API for XML Binding (JAXB) is another Java API. In fact, it is an architecture that maps a Java object to an XML document. To do this, a Java object is created that is bound to the XML document. This process is called data binding. It is essential to incorporate data binding of Java objects with XML documents because the industry standards for transferring data over the Web are mainly XML based.
In the process of data binding, a class hierarchy is created that is similar to the structure of an XML document that allows you to access or modify data in this class hierarchy without actually considering the structure of the XML document. To do this, a DTD and an XML schema are required as inputs. From there, the elements of the XML document are mapped to the values or Java classes. For example, an XML element that contains subelements is mapped to Java classes, and the XML elements that do not contain subelements are mapped to the Java values.
Then a Java source file is created by using the schema compiler. Finally, the Java compiler compiles these Java source files to Java classes. JAXB uses the process of unmarshalling and marshalling. Unmarshalling is the process of creating applications that contain classes required to convert an XML document to a tree object. Marshalling is the process of converting a tree object back to an XML document.
Components of the JAXB API
The following list discusses the components of the Java API:
These components work together to bind an XML document to the corresponding Java classes. The following section discusses the working of these components.
Working of the JAXB API
To work with the JAXB API, you need to perform the following steps:
Advantages of the JAXB API
The JAXB API has several advantages, as discussed in the following list:
Limitations of the JAXB API
In addition to the previously listed advantages, JAXB has certain limitations:
Java API for XML Messaging
As you know, the data that is transferred over the network is in XML format. The Java API for XML Messaging (JAXM) is an API used to transfer these XML messages. JAXM is based on industry standards, such as SOAP 1.1. Therefore, it is a standard used to exchange SOAP messages between the service provider and the service requestor applications.
In the e-business scenario, messages are exchanged between various applications or members of the value chain. To allow a smooth exchange of messages over the network, JAXM defines a framework that consists of the following types of messages:
The Asynchronous Message
The Asynchronous Message with Acknowledgement
The Synchronous Message
The Synchronous Message with Acknowledgement
The One-Way with No Reply Message
JAXM might use a messaging provider service to exchange or transfer messages between applications. This service routes the messages from one application to another. Therefore, when a message is sent from a client application (a service provider application in the case of Web services), the message goes to the messaging provider of the client application. The messaging provider then routes the message to the messaging provider of the receiving application, or the service provider application in the case of Web services. Finally, the messaging provider of the receiving application forwards the request to the receiving application—the ultimate destination of the request.
It is important to note that JAXM can be used in all business scenarios that require transfer of data. This implies that JAXM is not limited to the Web services scenario. Figure shows the transfer of messages by using the JAXM API.
Transfer of Messages by using the JAXM API
In today's business world, RPC-based Web services are used extensively. An RPC-based Web service contains Web methods that can be called remotely over the network. For example, a weather forecast Web service is an example of an RPC-based Web service that accepts the name of a place as a parameter and uses the SOAP message to return the temperature for the specified place.
Java API for XML-based RPC (JAX-RPC) is a set of APIs that allow you to develop a Web service that you can call remotely from a Java client application. The packages contained within the JAX-RPC are client-side API packages, as shown in the following list:
JAX-RPC hides the complexities of making calls to remote Web services from client applications. To do this, JAX-RPC uses the concepts of stubs, ties, and configuration files. In fact, JAX-RPC uses the SOAP-based XML messaging framework to invoke Web methods remotely. This framework is built on the concepts of SOAP, XML RPC, RMI, CORBA, and Messaging.
You can install the latest version, JAX-RPC 0.8, from the official site of 303 JCR The URL for this site is http:// jcp .org/ jsr /detail /101.jsp.
The JAX-RPC framework includes the Java initiative, which you can use to create Web services that can be accessed remotely from a client application. The creation of Web services by using the Java initiative includes the following stages:
Figure shows the JAX-RPC framework.
The JAX-RPC Framework
Advantages of JAX-RPC
As discussed earlier, JAX-RPC allows you to remotely invoke the Web methods that a Web service exposes. To do this, JAX-RPC allows you to create client applications in Java and other platforms that can remotely access a Web service. In addition, JAX-RPC offers several advantages, as discussed in the following list:
Note?/td>JAX-RPC is based on the standards defined in the SOAP specifications 1.1. These standards act as guidelines or rules for remotely accessing a Web service.
Java APIs for XML Registries
Java APIs for XML Registries (JAXR) provide APIs that allow you to conveniently and quickly access a business registry. As you know, a Web service needs to be registered with the business registries where the users can search for the required Web service. This search is facilitated by the JAXR APIs. To do this, JAXR supports a pluggable architecture, which allows you to connect to various business registries, such as the registries based on ebXML or UDDI registries. These registries are collectively called XML registries. We discussed the components of Java Web services that included a layer called the service broker in the section titled "Roles in the Java Service Model." These XML registries perform the role of a service broker in the Web services scenario.
Registries that ebXML or OASIS develop are open standards registries that derive from existing registry standards. In contrast, a consortium of industry leaders develop and maintain UDDI registries. As a result, UDDI registries are more widely used.
APIs in JAXR
JAXR, developed by the JCP organization, is currently in version 1.0. You can download this version from http:// jcp.org/ jsr /detail /93.jsp, where the jsr of the JAXR API is 93. The 0.9 version of JAXR contains several interfaces, which are further contained within APIs. The APIs in the JAXR API package are broadly categorized into two categories, as discussed in the following list:
JAXR is an API that allows a Java client application to access various registry standards. This is the limitation of JAXR; only Java client applications can access the registries. This feature is illustrated in Figure.
The Interoperability Feature of JAXR
As you know, JAXR allows a client application to access registries that are based on XML. This implies that JAXR supports the feature of interoperability. In fact, XML-based registries aim to integrate various Web services developed on different standards, enabling these Web services to interoperate using a common standard, XML. Therefore, any communication that takes place between the components of a Web service uses XML messaging technology. Due to support for interoperability of Web services, JAXR API is extensively used in a B2B scenario. To understand the feature of interoperability that JAXR supports, it is important for you to understand the working of the JAXR API The following section discusses this.
Working of JAXR API
The following steps show the working of JAXR in the B2B scenario:
The working of the JAXR API is illustrated in Figure
The Working of the JAXR API
XML Related Interview Questions
|Soap Tool Interview Questions||HTML Interview Questions|
|PHP Interview Questions||ASP.NET Interview Questions|
|PHP5 Interview Questions||Java Interview Questions|
|CSS Interview Questions||XSLT Interview Questions|
|Java XML Interview Questions||XMLHttpRequest (XHR) Interview Questions|
|ebXML Interview Questions||XML DOM Interview Questions|
|XML-RPC Interview Questions||XSD Interview Questions|
|Soap Web Services Interview Questions||XSL Interview Questions|
|Xml Publisher Interview Questions|
Basics Of Xml
Basics Of Web Services
Introduction To Soap
Introduction To Uddi
Introduction To Wsdl
Creating A Web Service Using The Microsoft Soap Toolkit
Building Web Applications On The .net Platform
Creating An Asp.net Web Service
Creating A Web Service From An Interface
Introduction To The Atl Server
Creating A Web Service Using The Atl Server Library
Design And Creation Of The Knowledge Share Web Service
Introduction To Java Xml Technologies
Developing Java Web Services
Design And Creation Of A Web Service Using The Ibm Toolkit
Introduction To Mobile Applications
Creating A Mobile Application That Consumes A Web Service
Web Services Development With Jdeveloper
Creating Web Services Using Perl
Integration Of Xml Web Services With The Office Xp And Sql
Server 2000 Toolkits
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.