Java Web Services Interview Questions and Answers: Overview
Q. What are the different application integration styles?
A. There are a number of different integration styles like
1. Shared database
2. batch file transfer
3. Invoking remote procedures (RPC)
4. Exchanging asynchronous messages over a message oriented middle-ware (MOM).
Q. How does a Java EE application integrates with other systems?
A. Using various protocols like HTTP(S), SOAP, RMI, FTP, proprietary, etc.
Q. What are the different styles of Web Services used for application integration?
A. SOAP WS and RESTful Web Service
Q. What are the differences between both SOAP WS and RESTful WS?
A.
A. There are a number of different integration styles like
1. Shared database
2. batch file transfer
3. Invoking remote procedures (RPC)
4. Exchanging asynchronous messages over a message oriented middle-ware (MOM).
Q. How does a Java EE application integrates with other systems?
A. Using various protocols like HTTP(S), SOAP, RMI, FTP, proprietary, etc.
Q. What are the different styles of Web Services used for application integration?
A. SOAP WS and RESTful Web Service
Q. What are the differences between both SOAP WS and RESTful WS?
A.
- The SOAP WS supports both remote procedure call (i.e. RPC) and message oriented middle-ware (MOM) integration styles. The Restful Web Service supports only RPC integration style.
- The SOAP WS is transport protocol neutral. Supports multiple protocols like HTTP(S), Messaging, TCP, UDP SMTP, etc. The REST is transport protocol specific. Supports only HTTP or HTTPS protocols.
- The SOAP WS permits only XML data format.You define operations, which tunnels through the POST. The focus is on accessing the named operations and exposing the application logic as a service. The REST permits multiple data formats like XML, JSON data, text, HTML, etc. Any browser can be used because the REST approach uses the standard GET, PUT, POST, and DELETE Web operations. The focus is on accessing the named resources and exposing the data as a service. REST has AJAX support. It can use the XMLHttpRequest object. Good for stateless CRUD (Create, Read, Update, and Delete) operations.
GET - read()
POST - create()
PUT - update()
DELETE - delete()
- SOAP based reads cannot be cached. REST based reads can be cached. Performs and scales better.
- SOAP WS supports both SSL security and WS-security, which adds some enterprise security features like maintaining security right up to the point where it is needed, maintaining identities through intermediaries and not just point to point SSL only, securing different parts of the message with different security algorithms, etc. The REST supports only point-to-point SSL security. The SSL encrypts the whole message, whether all of it is sensitive or not.
- The SOAP has comprehensive support for both ACID based transaction management for short-lived transactions and compensation based transaction management for long-running transactions. It also supports two-phase commit across distributed resources. The REST supports transactions, but it is neither ACID compliant nor can provide two phase commit across distributed transactional resources as it is limited by its HTTP protocol.
- The SOAP has success or retry logic built in and provides end-to-end reliability even through SOAP intermediaries. REST does not have a standard messaging system, and expects clients invoking the service to deal with communication failures by retrying.
- Does the service expose data or business logic? (REST is a better choice for exposing data, SOAP WS might be a better choice for logic).
- Do the consumers and the service providers require a formal contract? (SOAP has a formal contract via WSDL)
- Do we need to support multiple data formats?
- Do we need to make AJAX calls? (REST can use the XMLHttpRequest)
- Is the call synchronous or asynchronous?
- Is the call stateful or stateless? (REST is suited for statless CRUD operations)
- What level of security is required? (SOAP WS has better support for security)
- What level of transaction support is required? (SOAP WS has better support for transaction management)
- Do we have limited band width? (SOAP is more verbose)
- What’s best for the developers who will build clients for the service? (REST is easier to implement, test, and maintain)
- The contract-first approach, where you define the contract first with XSD and WSDL and the generate the Java classes from the contract.
- The contract-last approach where you define the Java classes first and then generate the contract, which is the WSDL file from the Java classes.
- Clients are decoupled from the server, hence the implementation logic can be revised on the server without affecting the clients.
- Developers can work simultaneously on client and server side based on the contract both agreed on.
- You have full control over how the request and response messages are constructed -- for example, should "status" go as an element or as an attribute? The contract clearly defines it. You can change OXM (i.e. Object to XML Mapping) libraries without having to worry if the "status" would be generated as "attribute" instead of an element. Potentially, even Web service frameworks and tool kits can be changed as well from say Apache Axis to Apache CXF, etc
- More upfront work is involved in setting up the XSDs and WSDLs. There are tools like XML Spy, Oxygen XML, etc to make things easier. The object models need to be written as well.
- Developers need to learn XSDs and WSDLs in addition to just knowing Java.
- Developers don't have to learn anything related to XSDs, WSDLs, and SOAP. The services are created quickly by exposing the existing service logic with frameworks/tool sets. For example, via IDE based wizards, etc.
- The learning curve and development time can be smaller compared to the Contract-first Web service.
- The development time can be shorter to initially develop it, but what about the on going maintenance and extension time if the contract changes or new elements need to be added? In this approach, since the clients and servers are more tightly coupled, the future changes may break the client contract and affect all clients or require the services to be properly versioned and managed.
- In this approach, The XML payloads cannot be controlled. This means changing your OXM libraries could cause something that used to be an element to become an attribute with the change of the OXM.
Q. How would you decide what style of Web Service to use? SOAP WS or REST?
A. In general, a REST based Web service is preferred due to its simplicity, performance, scalability, and support for multiple data formats. SOAP is favored where service requires comprehensive support for security and transactional reliability.
The answer really depends on the functional and non-functional requirements. Asking the questions listed below will help you choose.
Q. What tools do you use to test your Web Services?
A. SoapUI tool for SOAP WS and the Firefox "poster" plugin for RESTFul services.
Q. What is the difference between SOA and a Web service?
A.
SOA is a software design principle and an architectural pattern for implementing loosely coupled, reusable and coarse grained services. You can implement SOA using any protocols such as HTTP, HTTPS, JMS, SMTP, RMI, IIOP (i.e. EJB uses IIOP), RPC etc. Messages can be in XML or Data Transfer Objects (DTOs).
Web service is an implementation technology and one of the ways to implement SOA. You can build SOA based applications without using Web services – for example by using other traditional technologies like Java RMI, EJB, JMS based messaging, etc. But what Web services offer is the standards based and platform-independent service via HTTP, XML, SOAP, WSDL and UDDI, thus allowing interoperability between heterogeneous technologies such as J2EE and .NET.
Q. Why not favor traditional style middle-ware such as RPC, CORBA, RMI and DCOM as opposed to Web services?
A.
The traditional middle-wares tightly couple connections to the applications and it can break if you make any modification to your application. Tightly coupled applications are hard to maintain and less reusable. Generally do not support heterogeneity. Do not work across Internet. Can be more expensive and hard to use.
Web Services support loosely coupled connections. The interface of the Web service provides a layer of abstraction between the client and the server. The loosely coupled applications reduce the cost of maintenance and increases re-usability. Web Services present a new form of middle-ware based on XML and Web. Web services are language and platform independent. You can develop a Web service using any language and deploy it on to any platform, from small device to the largest supercomputer. Web service uses language neutral protocols such as HTTP and communicates between disparate applications by passing XML messages to each other via a Web API. Do work across internet, less expensive and easier to use.
Q. What are the different approaches to developing a SOAP based Web service? A. 2 approaches.
Note: The WSDL describes all operations that the service provides, locations of the endpoints (i.e.e where the services can be invoked), and simple and complex elements that can be passed in requests and responses.
Q. What are the pros and cons of each approach, and which approach would you prefer?
A.
Contract-first Web service
PROS:
CONS:
Contract-last Web service
PROS:
CONS:
So, which approach will you choose?
The best practice is to use "contract-first", and here is the link that explains this much better with examples --> contract-first versus contract-last web services In a nutshell, the contract-last is more fragile than the "contract-first". You will have to decide what is most appropriate based on your requirements, tool sets you use, etc.
JAX pack technologies | |
<<Previous Next>>Java web service - Feb 08, 2009, 17:00 pm by Vidya SagarExplain the technologies included within JAX pack, i.e. JAXP, JAXB, JAXM, JAX-RPC, JAXR.
JAXP: Java API for xml processing. It provides the validation capability and parsing XML documents. There are three basic parsing interfaces in JAXP are DOM, SAX and Straming API for XML STAX.
JAXB: Java Architecture for XML Binding: The java classes are mapped to XML representations. The two main features of JAXB are the ability to marshal Java objects into XML and unmarshal XML back to Java objects.
The Java API for XML Messaging (JAXM) enables distributed software applications to communicate using XML (and SOAP). JAXM supports both asynchronous and synchronous messaging.
JAX-RPC: Java API for XML based RPC. Allows a java based web service that is to be invoked by a Java application provided the description, still being consistent with WSDL description. This can resemble as Java RMI over web services.
Allowing a web service to be implemented at server side as a servlet/jsp or EJB container is the advantage of JAX-RPC.
Java web service - Aug 09, 2009, 13:00 pm by Amit SatputeExplain the technologies included within JAX pack, i.e. JAXP, JAXB, JAXM, JAX-RPC, JAXR.
Included in the bundle are
Java API for XML Processing (JAXP)
JAXP enables applications to parse, transform, validate and query XML documents. It uses an API that is independent of a particular XML processor implementation.
JAXP enables vendors to provide their own implementations without introducing dependencies in application code.
Java Architecture for XML Binding (JAXB)XML is a standard for exchanging data across heterogeneous systems.
Java provides a platform for building portable applications.
A combination of these two enables users and application developers to program Web based functionality on an platform.
Java API for XML Messaging (JAXM)JAXM is a SOAP 1.1 based standard to send XML documents over the Internet from the Java platform.
JAXM can be extended to work with higher level messaging protocols by adding the protocol's functionality on top of SOAP.
Java API for XML-based RPC (JAX-RPC)JAX-RPC project provides the code base for the Reference Implementation of JAX-RPC, the Java APIs for XML based RPC. JAX-RPC RI is a production-quality implementation that is used directly in a number of products by Sun and other vendors.
Java API for XML Registries (JAXR). JAXR gives you a uniform way to use business registries that are based on open standards (ebXML) or industry consortium-led specifications (UDDI).
Explain the web services architecture.
The operations between different software applications, which are running on a variety of platforms and frameworks are supported by a standard called Web services. The web services architecture provides the concepts, model and understanding web services and relationships among the components.
The WSA specifies the minimal characteristics that are very common for all web services and a number of characteristics to the needed web services. WSA is called interoperability architecture that means the global elements of a global web service network are identified by this architecture in order to perform the interoperability between the web services.
Explain the web services architecture.
Web Services are based on three operations: publish, find, and bind.
Service providers publish services to a service broker.
Service requesters find required services using a service broker and bind to them.
Usage of document/literal wrapped pattern in WSDL design |
No comments:
Post a Comment