Wednesday, July 27, 2016

Java Web services interview questions

What are web services?
Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). Web services provide a standard means of inter operating between software applications running on a variety of platforms and frameworks.

Main characteristics of the Web Services are:

1. Interoperability 
2. Extensibility
3. Machine process able descriptions.

What is the difference between SOA and a web service?
SOA (Service-Oriented Architecture) is an architectural pattern that makes possible for
services to interact with one another independently. 
Web Services is a realization of SOA concept, that leverages XML, JSON, etc. and common Internet protocols such as HTTP(S), SMTP, etc. 
SOA is a system-level architectural style that tries to expose business. WOA is an interface-level architectural style that focuses on the means by which these service capabilities are exposed to consumers.

What is SOAP?
SOAP (Simple Object Access Protocolis a transport protocol for sending and receiving requests and responses on XML format, which can be used on top of transport protocols such as HTTP, SMTP, UDP, etc. 

What is REST?
REST (REpresentational State Transfer) is an architectural style by which data can be transmitted over transport protocol such as HTTP(S).

What is the difference between a REST web service and a SOAP web service?
Below are the main differences between REST and SOAP web service
1.      REST supports different formats like text, JSON and XML; SOAP only supports XML;
2.      REST works only over HTTP(S) on a transport layer; SOAP can be used different protocols on a transport layer;
3.      REST works with resources, each unique URL is some representation of a resource; SOAP works with operations, which implement some business logic through different interfaces;
4.      SOAP based reads can’t be cached, for SOAP need to provide caching; REST based reads can be cached;
5.      SOAP supports SSL security and WS-security (Web Service-security); REST only supports SSL security;
6.      SOAP supports ACID (AtomicityConsistencyIsolationDurability); REST supports transactions, but it is neither ACID compliant nor can provide two phase commit.
How to decide which one of web service to use REST or SOAP? 
“REST vs SOAP” we can have rephrased to "Simplicity vs Standard". Of course, "Simplicity" with REST at most cases wins, it wins in performance, scalability and support for multiple data formats, but SOAP is favoured where service requires comprehensive support for security (WS-security) and transactional safety (ACID).

  What is WSDL?
WSDL (Web Services Description Language) is an XML format for describing web services and how to access them. 

  What is JAX-WS?
JAX-WS (Java API for XML Web Servicesis a set of APIs for creating web services in XML format.

 What is JAXB?
JAXB (Java Architecture for XML Binding) is a Java standard that defines how Java objects are converted from and to XML. It makes reading and writing of XML via Java relatively easy.

 Can we send soap messages with attachments?
Yes, we can send different formats such as PDF document, image or other binary file with soap messages as an attachment. Messages send using the binary data. SOAP messages is attached with MIME extensions that come in multipart/related.  
An example:
MIME-Version: 1.0
Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml;
        start=" javahungry.com>"
Content-Description: This is the optional message description.
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
..
..
--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: binary
Content-ID:

...binary TIFF image...
--MIME_boundary—

 What is MTOM?
MTOM (Message Transmission Optimization Mechanism) is a mechanism for transmitting large binary attachments with SOAP messages as raw bytes, allowing for smaller messages.

 What is XOP?
XOP (XML-binary Optimized Packaging) is a mechanism defined for the serialization of XML Information Sets that contain binary data, as well as deserialization back into the XML Information Set.

 What is a SOAP envelope element?
SOAP envelop element is the root element of a SOAP message which defines the XML document as a SOAP message.
An example:
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  ...
  Message information
  ...
 What does a SOAP namespace defines?
SOAP namespace defines the Envelope as a SOAP Envelope.
An example:
xmlns:soap=http://www.w3.org/2001/12/soap-envelope

 What is the SOAP encoding?
SOAP encoding is a method for structuring the request which is suggested within the SOAP specification, known as the SOAP serialization.

 What does SOAP encodingStyle attribute defines?
SOAP encodingStyle defines the serialization rules used in a SOAP message. This attribute may appear on any element, and is scoped to that element's contents and all child elements not themselves containing such an attribute. There is no default encoding defined for a SOAP message.
An example: 
SOAP-ENV:encodingStyle="http://www.w3.org/2001/12/soap-encoding"

 What are 2 styles web service’s endpoint by using JAX-WS?
1.      RPC (remote procedure call) style web service in JAX-WS; 
2.      document style web service in JAX-WS. 

 What is encoding rules for header entries? 
1.      a header entry is identified by its fully qualified element name, which consists of the namespace URI and the local name. All immediate child elements of the SOAP Header element must be namespace-qualified. 
2.      the SOAP encodingStyle attribute may be used to indicate the encoding style used for the header entries. 
3.      the SOAP mustUnderstand attribute and SOAP actor attribute may be used to indicate how to process the entry and by whom. 

 What is the wsimport tool? 
The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files (JAX-WS portable artifacts) for web service client to access the published web services: https://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

 What is the wsgen tool?
The wsgen tool is used to parse an existing web service implementation class and generates required files (JAX-WS portable artifacts) for web service deployment: http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsgen.html

 What is the difference between SOAP and other remote access techniques?
1.      SOAP is simple to use and it is non - symmetrical unlike DCOM or CORBA is highly popular and usually have complexity in them.
2.      SOAP provides greater platform independent with the language independence unlike DCOM or CORBA doesn't provide any of these.
3.      SOAP uses HTTP as its transport protocol and the data are being saved in XML format that can be ready by human, whereas DCOM or CORBA have their own binary formats that are used to transport the data in complicated manner.
4.      SOAP identify the object other than URL endpoint. SOAP objects are stateless and it is hard to maintain that. Whereas, it is not hard to maintain in case of other remote access techniques.

 What is a resource in a REST?
      A resource is a unique URL with representation of an object which we can get contents via GET and modify via PUT, POST, DELETE.

 What are HTTP methods supported by REST?
                  GET, POST, PUT, DELETE, OPTIONS, HEAD.

Whether can use GET request instead of POST to create a resource?
It is not possibly, because GET can’t change a resource.

 What is the difference between PUT and POST?
Need to use PUT when can update a resource completely through a specific resource. . If do not know the actual resource location for instance, when add a new article, can use POST. 
PUT is idempotent, while POST is not. It means if use PUT an object twice, it has no effect.

 What is WADL?
WADL (Web Application Description Language) is a XML description of a deployed RESTful web application. 

 What are frameworks available to implement REST web services? 
Jersey, Restlet, EasyRest, etc.

What is the Restlet framework?
Restlet is a lightweight, comprehensive, open source RESTful web API framework for the Java platform.
It has advantages such as
websocket and server-sent events support;
HTTP/2 support;
transparent HTTP PATCH support;
client cache service;
fluent APIs.

Q29 What is the Jersey framework?
Jersey is open source framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation. It has advantages such as 
1. contains support for Web Application Description Language (WADL); 
2. contains Jersey Test Framework which lets run and test Jersey REST services inside JUnit;   
3. supports for the REST MVC pattern, which would allow to return a View from Jersey services rather than just data.

 What is the RESTeasy framework?
RESTeasy is a JBoss project, which implements of the JAX-RS specification. It has benefits such as 
fully certified JAX-RS implementation; supports HTTP 1.1 caching semantics including cache revalidation; 
JAXB marshalling into XML, JSON, Jackson, Fastinfoset, and Atom as well as wrappers for maps, arrays, lists, and sets of JAXB Objects; 
OAuth2 and Distributed SSO with JBoss AS7; 
rich set of providers for: XML, JSON, YAML, Fastinfoset, Multipart, XOP, Atom, etc. 


What is the difference between AJAX and REST?
1.      Ajax, the request are sent to the server by using XMLHttpRequest objects; REST have a URL structure and a request/response pattern the revolve around the use of resources;
2.      Ajax eliminates the interaction between the customer and server asynchronously; REST requires the interaction between the customer and server;
3.      Ajax is a set of technology; REST is a type of software architecture and a method for users to request data or information from servers.

What tool are required to test REST services?
Firefox “poster” plugin for RESTFUL services. https://addons.mozilla.org/en-us/firefox/addon/poster/




No comments:

Post a Comment