WebServicesUpdated2017 Madhu
WebServicesUpdated2017 Madhu
Web Services work on client-server model where client applications can access web services
over the network. Web services provide endpoint URLs and expose methods that can be
accessed over network through client programs written in java, shell script or any other
different technologies.
Web services are stateless and doesn’t maintain user session like web applications.
Just like SOAP (Simple Object Access Protocol), which is used to develop web services by
XML method, RESTful web services use web protocol i.e. HTTP protocol method. They
have the feature like scalability, maintainability, help multiple application communication
built on various programming languages etc.
RESTful web service implementation defines the method of accessing various resources
which are required by the client and he has sent the request to the server through the web
browser. The important aspects of this implementation include:
Resources
Request Headers
Request Body
Response Body
Status codes
RESTful web services use a famous web protocol i.e. HTTP protocol. This serves as a
medium of data communication between client and server. HTTP standard methods are used
to access resources in RESTful web service architecture.
Just like we require address with postal code to reach any person, in the same way,
‘Addressing’ locates resources that are present on the server for the purpose of hosting web
services. This is usually done with URI i.e. Unified Resource Identifier.
Every RESTful web services should have following features and characteristics that are
enlisted below:
Use of HTTP protocol for performing functions like fetching data from the web service,
retrieving resources, execution of any query, etc.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
The communication between the server and client is performed through the medium known
as ‘messaging’.
Based on the concept of statelessness where every client request and the response is
independent of the other with complete assurance of providing required information.
Messages are the mode of exchanging data for any type of communication to take place. In
the same way, HTTP protocol plays the role of message communication between the client
and server through HTTP Request and Response methods. HTTP request is sent by the client
who contains information about the data and in turn, receives HTTP Response from the
server.
Messages are the collection of information about the data i.e. Metadata.
What are the core components of HTTP request and HTTP response?
Uniform Resource Identifier for identifying the resources available on the server.
HTTP Version for specifying the HTTP version.
HTTP Request header for containing the information about the data.
HTTP Request body that contains the representation of the resources in use.
Request Code: This contains various codes which determine the status of the server response.
In REST, ST itself defines State Transfer and Statelessness means complete isolation. This
means, the state of the client’s application is never stored on the server and is passed on. In
this process, the clients send all the information that is required for the server to fulfill the
HTTP request that has been sent. Thus every client request and the response is independent of
the other with complete assurance of providing required information.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Every client passes a ‘session identifier’ which also acts as an identifier for each session.
In the above question, we have understood the meaning of statelessness with respect to the
client-server communication. Now, let us see some of its advantages and disadvantages.
Advantages:
Disadvantages:
In every HTTP request from the client, the availability of some information regarding
the client state is required by the web service.
Every constraint has positive as well as negative impacts and to produce an overall
architecture, there should be the balance between both of them. Below mentioned are some
important constraints for RESTful web service:
There should be separate concerns for each server and client which will help to
maintain the modularity within the application. This will also reduce the complexity
and increase the scalability.
The client-server communication should be stateless, which means no previous
information is used and the complete execution is done in isolation. In cases of
failure, it also helps the client to recover.
In client-server communication, the HTTP response should be cacheable so that when
required cached copy can be used which in turn enhances the scalability and
performance of the server.
The fourth constraint is the uniform interface which allows client-server interaction to
be easily understood. This constraint is further divided into four sub-constraints as:
Resource Identification
Resource manipulation
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Hypermedia, which is defined as the text with hyperlinks and when clicked it moves to
another application state.
Client-server communication should be done on a layered system and thus the client should
only have knowledge about the intermediate level with which communication is being done.
What is a ‘Resource’?
Just like the ‘Object’ instance, we have learned in object orient programming Language, in
the same way, ‘Resource’ is defined as an object of a type which can be an image, HTML
file, text data, and any type of dynamic data. There are varieties of representation formats
available in order to represent a resource.
JSON
YAML
XML
HTML
Enlist some important points that should be kept in mind while designing Resources
representation for RESTful web services.
As there are no restrictions on the format in which the resource representation is done but just
that the main requirement is the format of the representation should be as per the client
requirement. A good resource representation is designed by considering the following main
points:
The resource representation format should be easily understood by the client and server.
The representation should be complete regardless of its format structure, which may be
complex or simple.
In the case of the link of the resources to other resources, such cases should also be
considered and handled.
What is Caching?
Caching is the process in which server response is stored so that a cached copy can be used
when required and there is no need of generating the same response again. This process not
only reduces the server load but in turn increase the scalability and performance of the server.
Only the client is able to cache the response and that too for a limited period of time.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Mentioned below are the header of the resources and their brief description so that they can
be identified for the caching process:
Time and date of resource modification that usually stores the last detail.
The age which determines the time from when the resource has been fetched.
A standard Cache control header can help in attaining cache ability. Enlisted below is the
brief description of various cache control header:
Public: Resources that are marked as the public can be cached by any intermediate
components between the client and server.
Private: Resources that are marked as private can only be cached by the client.
No cache means that particular resource cannot be cached and thus the whole process is
stopped.
What are the best practices that are to be followed while designing RESTful web
services?
To design a secure RESTful web service, there are some best practices or say points that
should be considered. These are explained as follows:
What is Payload?
The request data which is present in the body part of every HTTP message is referred as
‘Payload’. In Restful web service, the payload can only be passed to the recipient through
POST method.
There is no limit of sending data as payload through POST method but the only concern is
that more data with consuming more time and bandwidth. This may consume much of user’s
time also.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
GET: This is a read only operation which fetches the list of users on the server.
PUT: This operation is used for the creation of any new resource on the server.
POST: This operation is used for updating an old resource or for creating a new resource.
DELETE: As the name suggests, this operation is used for deleting any resource on the
server.
OPTIONS: This operation fetches the list of any supported options of resources that are
available on the server.
The major difference between the PUT and POST method is that the result generated with
PUT method is always same no matter how many times the operation is performed. On the
other hand, the result generated by POST operation is always different every time.
What is your understanding about JAX-RS?
JAX-RS is defined as the Java API for RESTful web service. Among multiple libraries and
framework, this is considered as the most suitable Java programming language based API
which supports RESTful web service.
Jersey
RESTEasy
Apache CFX
Play
Among these, Jersey is the most popular framework.
HTTP status codes basically are the representation of the status of the task that has been
performed on the server, with the mode of some codes. Every code has their own meaning.
Some of the HTTP status codes with their meaning are as follows:
There are few more such codes that indicate the status.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
There are a set of architectural constraints (we will discuss them shortly) called Rest Style
Constraints. Any service which satisfies these constraints is called RESTful Web Service.
There are a lot of misconceptions about REST Web Services : They are over HTTP , based
on JSON etc. Yes : More than 90% of RESTful Web Services are JSON over HTTP. But
these are not necessary constraints. We can have RESTful Web Services which are not using
JSON and which are not over HTTP.
Richardson Maturity Model defines the maturity level of a Restful Web Service. Following
are the different levels and their characteristics.
Level 0 : Expose SOAP web services in REST style. Expose action based services
(http://server/getPosts, http://server/deletePosts, http://server/doThis, http://server/doThat etc)
using REST.
Level 1 : Expose Resources with proper URI’s (using nouns). Ex: http://server/accounts,
http://server/accounts/10. However, HTTP Methods are not used.
Level 2 : Resources use proper URI's + HTTP Methods. For example, to update an account,
you do a PUT to . The create an account, you do a POST to . Uri’s look like
posts/1/comments/5 and accounts/1/friends/1.
Level 3 : HATEOAS (Hypermedia as the engine of application state). You will tell not only
about the information being requested but also about the next possible actions that the service
consumer can do. When requesting information about a facebook user, a REST service can
return user details along with information about how to get his recent posts, how to get his
recent comments and how to retrieve his friend’s list.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
While designing any API, the most important thing is to think about the api consumer
i.e. the client who is going to use the service. What are his needs? Does the service uri
make sense to him? Does the request, response format make sense to him?
In Rest, we think Nouns (resources) and NOT Verbs (NOT actions). So, URI’s should
represent resources. URI’s should be hierarchical and as self descriptive as possible.
Prefer plurals.
Always use HTTP Methods. Best practices with respect to each HTTP method is
described in the next question.
What are the best practices in using HTTP methods with Restful Web Services?
GET : Should not update anything. Should be idempotent (same result in multiple
calls). Possible Return Codes 200 (OK) + 404 (NOT FOUND) +400 (BAD
REQUEST)
POST : Should create new resource. Ideally return JSON with link to newly created
resource. Same return codes as get possible. In addition : Return code 201
(CREATED) is possible.
PUT : Update a known resource. ex: update client details. Possible Return Codes :
200(OK)
DELETE : Used to delete a resource.
JAX-RS is the JEE Specification for Restful web services implemented by all JEE compliant
web servers (and application servers).
Important Annotations:
Useful methods:
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Most Restful services use HTTP protocol : Entire web is based on HTTP and is built for
efficiency of HTTP. Things like HTTP caching enable Restful services to be effective.
High Performance : Less xml & soap overhead and More caching enable Restful services to
be highly performant.
First of all, REST is a set of architectural principles defining how a RESTful service should
look look like. SOAP is a message exchange format. SOAP defines the structure of message
to exchanged. How should the header be? How should the request content be? So, there is no
real comparison between REST and SOAP.
All comparison is between the Sample Restful and SOAP implementations described above.
REST is built over simple HTTP protocol. SOAP services are more complex to
implement and more complex to consume.
REST has better performance and scalability. REST reads can be cached, SOAP
based reads cannot be cached.
REST permits many different data formats (JSON is the most popular choice) where
as SOAP only permits XML.
SOAP services have well defined structure and interface (WSDL).
SOAP is based on well defined standards (WS-Security, WS-AtomicTransaction and
WS-ReliableMessaging).
“PUT” puts a file or resource at a particular URI and exactly at that URI. If there is already a
file or resource at that URI, PUT changes that file or resource. If there is no resource or file
there, PUT makes one
POST sends data to a particular URI and expects the resource at that URI to deal with the
request. The web server at this point can decide what to do with the data in the context of
specified resource
PUT is idempotent meaning, invoking it any number of times will not have an impact on
resources.
However, POST is not idempotent, meaning if you invoke POST multiple times it keeps
creating more resources
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
JSON and XML are the two markup language that can be used in restful web api
Mention what is the difference between RPC or document style web services? How you
determine to which one to choose?
In document style web services, we can transport an XML message as part of SOAP request
which is not possible in RPC style web service. Document style web service is most
appropriate in some application where XML message behaves as document and content of
that document can alter and intention of web service does not rely on the content of XML
message.
Both JAX-WS and JAX-RS are libraries (APIs) for doing communication in various ways in
Java. JAX-WS is a library that can be used to do SOAP communication in JAVA, and JAX-
RS lets you do the REST communication in JAVA.
List out the tools or API for developing or testing web api?
Jersey API
CFX
Axis
Restlet
GET: It requests a resource at the request URL. It should not contain a request body
as it will be discarded. Maybe it can be cached locally or on the server.
POST: It submits information to the service for processing; it should typically return
the modified or new resource
PUT: At the request URL it update the resource
DELETE: At the request URL it removes the resource
OPTIONS: It indicates which techniques are supported
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Mention whether you can use GET request instead of PUT to create a resource?
No, you are not supposed to use POST or GET. GET operations should only have view
rights
Resources are identified by logical URLs; it is the key element of a RESTful design. Unlike,
SOAP web services in REST, you view the product data as a resource and this resource
should contain all the required information.
Restlet is leading RESTful web framework for Java applications is used to build RESTFul
web services it has two part Restlet API and a Restlet implementation much like Servlet
specification. There are many implementation of Restlet framework available you just need
to add there jar in your classpath to use them. By using Restlet web framework you can write
client and server.
it represent a "resource" in REST architecture. on RESTLET API it has life cycle methods
like init(), handle() and release() and contains a Context, Request and Response
corresponding to specific target resource. This is now deprecated over ServerResource class
and you should use that. see Restlet documentation for more details.
Yes, Restlet framework provide default server which can be used to handle service request in
web container is not available.
This REST web service interview questions is open for you all, post you answer in comment
section.
What is RESTEasy ?
What are the tools used for creating RESTFull web services ?
You can use AJAX(Asynchronous JavaScript with XAML) and Direct Web Removing to
consume web serives in web application. Both Eclipse and NetBeans also supported
development of RESTFul services.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
In top-down approach first WSDL document is created and than Java classes are developed
based on WSDL contract, so if WSDL contract changes you got to change your Java classes
while in case of bottom up approach of web service development you first create Java code
and then use annotations like @WebService to specify contract or interface and WSDL field
will be automatically generated from your build.
What happens if RestFull resources are accessed by multiple clients ? do you need to
make it thread-safe?
Since a new Resource instance is created for every incoming Request there is no need to
make it thread-safe or add synchronization. multiple client can safely access RestFull
resources concurrently.
What is differences between RESTful web services and SOAP web services ?
Though both RESTful web series and SOAP web service can operate cross platform they are
architecturally different to each other, here is some of differences between REST and SOAP:
2) REST uses HTTP protocol for producing or consuming web services while SOAP uses
XML.
3) REST is lightweight as compared to SOAP and preferred choice in mobile devices and
PDA's.
4) REST supports different format like text, JSON and XML while SOAP only support XML.
Interoperability: Web services are accessible over network and runs on HTTP/SOAP
protocol and uses XML/JSON to transport data, hence it can be developed in any
programming language. Web service can be written in java programming and client
can be PHP and vice versa.
Reusability: One web service can be used by many client applications at the same
time.
Loose Coupling: Web services client code is totally independent with server code, so
we have achieved loose coupling in our application.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
SOAP Web Services: Runs on SOAP protocol and uses XML technology for sending
data.
Restful Web Services: It’s an architectural style and runs on HTTP/HTTPS protocol
almost all the time. REST is a stateless client-server architecture where web services
are resources and can be identified by their URIs. Client applications can use HTTP
GET/POST methods to invoke Restful web services.
What is SOAP?
SOAP stands for Simple Object Access Protocol. SOAP is an XML based industry standard
protocol for designing and developing web services. Since it’s XML based, it’s platform and
language independent. So our server can be based on JAVA and client can be on .NET, PHP
etc. and vice versa.
SOAP web services have all the advantages that web services has, some of the additional
advantages are:
WSDL document provides contract and technical details of the web services for client
applications without exposing the underlying implementation technologies.
SOAP uses XML data for payload as well as contract, so it can be easily read by any
technology.
SOAP protocol is universally accepted, so it’s an industry standard approach with
many easily available open source implementations.
Web services are ways of communication between two application over network. It allows
you to expose business logic using API.
For example:
Lets say you are java developer, you can create web service and expose API over internet and
any other developer (lets say .net developer ) can access it.
Interoperability
Reuse already developed(old) functionality into new software:
Loosely Coupled
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Extensibility
SOAP
Restful web services
What is SOAP?
SOAP stands for Simple object access protocol. It is protocol to exchange information using
request and response in XML format over transport protocol such as HTTP, SMTP etc.
SOAP means Simple Object Access Protocol is a type of communication protocol, a way to
structure data prior to transmitting it and is based on XML standard. It is developed to enable
communication between applications of different platforms and programming language via
internet. It can use the range of protocols such as FTP, HTTP, SMTP, Post office protocol
3(POP3) to carry documents. In other words, it is an XML based protocol to transfer between
computers.
JSON is standard to represent human readable data. SOAP is a protocol requirement for
transmitting information and calling web-services using XML.
Mention what is the major obstacle faced by the users using SOAP?
The major obstacle faced by the users using SOAP is a firewall security mechanism. This
lock all the ports leaving few like HTTP port 80 and the HTTP port used by SOAP that
bypasses the firewall. The technical complaints against SOAP is that it mixes the
specification for message transport with the specification for message structure.
Message format is written by using the XML language. The message format is standard, and
it is widely used. The message format is like
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
POST/InStock HTTP/1.1
SOAPAction:http://www.guru99.org/2003/05/soap-envelop>
<soap:Header>
</soap:Header>
<soap:Body>
<m:CareerName>Guru99</m:CareerName>
</soap:Body>
</soap:Envelope>
HTTP/1.0 200 OK
Content-Length: nnn
<SOAP-ENV:Envelop
<m:GetQuotationResponse>
</m:QuotationRequest>
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
</SOAP-ENV:Body>
</SOAP-ENV: Envelope>
HTTP works over TCP/IP. The HTTP client links to an HTTP server using TCP. SOAP
HTTP is a method that conforms with the SOAP encoding rules.
The HTTP POST request mentions atleast two HTTP headers: Content-Type and Content-
Length
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Explain how user use the facilities that are provided by SOAP?
PutListing(): It is used to enable the insertion of a complete XML document into the
webpage. It receives the XML file as an argument and transport the XML file to XML parser
liason, which reads it and puts it as a parameter in the SOAP call
GetAddress(): It is used to determine a query name and retrieves the result that is best
matched with a query. In the form of text string, the name is sent to the SOAP call
Application layer and transport layers of a network are used by SOAP. HTTP and SMTP are
the valid application layer protocol used as transport for SOAP. HTTP is more preferable as
it works well with current internet infrastructure especially with firewalls.
The SOAP requests can be sent via an HTTP GET method while the specification includes
details on HTTP POST only.
IP address of the server where the web services are running is the end point in web services.
A SOAP envelop indicates the start and end of the message, so that the receiver knows when
an entire message has been received. In other words, a SOAP envelop is a packaging
mechanism.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
SOA is a software design principle and an architectural pattern for implementing loosely
coupled, reusable and coarse grained services. Using any protocols such as HTTP, HTTPS,
JMS, SMTP, etc. you can implement SOA. The message can be in Data Transfer Objects or
in XML.
What is WSDL?
WSDL stands for Web Service Description Language. It is an XML file that describes the
technical details of how to implement a web service, more specifically the URI, port, method
names, arguments, and data types. You can understand following details using WSDL
What is UDDI?
UDDI stands for Universal Description, Discovery and Integration.It is a directory service.
Web service provider can register themselves with a UDDI and make themselves available
through it for discovery.
What is JAX-WS?
JAX-WS stands for Java API for XML Web Services. JAX-WS is standard XML based Java
API which is used to create SOAP web services.
Report Ad
@WebService
@WebMethod
@SOAPBinding
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
End point is nothing but URL which other application can use to access it.
for example:
end point:http://localhost:8080/WS/HelloWorld
You just need to put ?wsdl at the end of end point URL.
for example:
end point:http://localhost:8080/WS/HelloWorld
What is wsimport?
wsimport is utility which generates java classes from WSDL. It is part of JDK 6.
This file provides endpoint details about JAX-WS web service which is deployed on
tomcat.It is available at WEB-INF directory.
For example:
<endpoint
name="HelloWorldWS"
implementation="org.arpit.javapostsforlearning.webservice.HelloWorldImpl"
url-pattern="/HelloWorldWS"/>
</endpoints>
<endpoint
name="HelloWorldWS"
implementation="org.arpit.javapostsforlearning.webservice.HelloWorldImpl"
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
url-pattern="/HelloWorldWS"/>
</endpoints>
What is JAX-RS?
Java API for RESTful Web Services (JAX-RS), is a set if APIs to create web service which
supports REST architecture. JAX-RS is part of the Java EE6, and help developers to create
REST web application easily.
What are some important annotations which you use to create Restful web services?
Some of important annotations which are used for creating web services are:
@Path : This is used to set path for URI at class level or method level
@PathParam: Used to inject values from the URL into a method parameter.
SOAPUI
Only XML can be used, JSON and other lightweight formats are not supported.
SOAP is based on the contract, so there is a tight coupling between client and server
applications.
SOAP is slow because payload is large for a simple string message, since it uses XML
format.
Anytime there is change in the server side contract, client stub classes need to be
generated again.
Can’t be tested easily in browser
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
What is WSDL?
WSDL stands for Web Service Description Language. WSDL is an XML based document
that provides technical details about the web service. Some of the useful information in
WSDL document are: method name, port types, service end point, binding, method
parameters etc.
xsd:import namespace and schemaLocation: provides WSDL URL and unique namespace for
web service.
What is UDDI?
UDDI is acronym for Universal Description, Discovery and Integration. UDDI is a directory
of web services where client applications can lookup for web services. Web Services can
register to the UDDI server and make them available to client applications.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Web services are stateless so we can’t maintain user sessions in web services.
What is SOAP?
SOAP (Simple Object Access Protocol) is 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 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 Services) is 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.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
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
start="<claim061400a.xml@ javahungry.com>"
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
..
<theSignedForm href="cid:[email protected]"/>
..
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--MIME_boundary
Content-Type: image/tiff
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
--MIME_boundary—
What is MTOM?
What is XOP?
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
SOAP envelop element is the root element of a SOAP message which defines the XML
document as a SOAP message.
An example:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
...
Message information
...
</soap:Envelope>
An example:
xmlns:soap=http://www.w3.org/2001/12/soap-envelope
SOAP encoding is a method for structuring the request which is suggested within the SOAP
specification, known as the SOAP serialization.
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"
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
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.
the SOAP encodingStyle attribute may be used to indicate the encoding style used for the
header entries.
the SOAP mustUnderstand attribute and SOAP actor attribute may be used to indicate how to
process the entry and by whom.
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
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
Need to use PUT when can update a resource completely through a specific resource. For
example, if know that an article resides at http://javahungry.blogspot.com/article/123, can
PUT a new resource representation of this article through a PUT on this URL. 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?
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Restlet is a lightweight, comprehensive, open source RESTful web API framework for the
Java platform.
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
contains Jersey Test Framework which lets run and test Jersey REST services inside JUnit;
supports for the REST MVC pattern, which would allow to return a View from Jersey
services rather than just data.
in 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;
Ajax eliminates the interaction between the customer and server asynchronously;
REST requires the interaction between the customer and server;
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
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.
@PathParam annotation injects the value of URI parameter that defined in @Path expression.
put @Produces(“?”) on service method, with a Response return type. Instead “?” write a type
text/plain, image/png, etc.
set “Content-Disposition” in Response header to tell browser pop up a download box for user
to download.
Web Services can be thought of as Services in SOAP architecture and providing means to
implement SOA pattern.
These are important headers in Restful web services. Accept headers tells web service what
kind of response client is accepting, so if a web service is capable of sending response in
XML and JSON format and client sends Accept header as “application/xml” then XML
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
response will be sent. For Accept header “application/json”, server will send the JSON
response.
Content-Type header is used to tell server what is the format of data being sent in the request.
If Content-Type header is “application/xml” then server will try to parse it as XML data. This
header is useful in HTTP Post and Put requests.
How would you choose between SOAP and REST web services?
Web Services work on client-server model and when it comes to choose between SOAP and
REST, it all depends on project requirements. Let’s look at some of the conditions affecting
our choice:
JAX-WS stands for Java API for XML Web Services. JAX-WS is XML based Java API to
build web services server and client application. It’s part of standard Java API, so we don’t
need to include anything else which working with it. Refer to JAX-WS Tutorial for a
complete example.
We can create SOAP web services using JAX-WS API, however some of the other
frameworks that can be used are Apache Axis and Apache CXF. Note that they are not
implementations of JAX-WS API, they are totally different framework that work on Servlet
model to expose your business logic classes as SOAP web services. Read more at Java SOAP
Web Service Eclipse example.
@WebService
@SOAPBinding
@WebMethod
Endpoint class provides useful methods to create endpoint and publish existing
implementation as web service. This comes handy in testing web services before making
further changes to deploy it on actual server.
WSDL document can be accessed by appending ?wsdl to the SOAP endoint URL. In above
example, we can access it at http://localhost:8888/testWS?wsdl location.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
This file is used to provide endpoints details when JAX-WS web services are deployed in
servlet container such as Tomcat. This file is present in WEB-INF directory and contains
endpoint name, implementation class and URL pattern.
Java API for RESTful Web Services (JAX-RS) is the Java API for creating REST web
services. JAX-RS uses annotations to simplify the development and deployment of web
services. JAX-RS is part of JDK, so you don’t need to include anything to use it’s
annotations.
Jersey: Jersey is the reference implementation provided by Sun. For using Jersey as our
JAX-RS implementation, all we need to configure its servlet in web.xml and add required
dependencies. Note that JAX-RS API is part of JDK not Jersey, so we have to add its
dependency jars in our application.
We can use wsimport utility to generate the client stubs. This utility comes with standard
installation of JDK. Below image shows an example execution of this utility for one of JAX-
WS project.
@Path: used to specify the relative path of class and methods. We can get the URI of
a webservice by scanning the Path annotation value.
@GET, @PUT, @POST, @DELETE and @HEAD: used to specify the HTTP
request type for a method.
@Produces, @Consumes: used to specify the request and response types.
@PathParam: used to bind the method parameter to path value by parsing it.
XmlRootElement annotation is used by JAXB to transform java object to XML and vice
versa. So we have to annotate model classes with this annotation.
What is WSDL?
WSDL stands for Web Services Description Language. It is a xml document containing
information about web services such as method name, method parameter etc. More details...
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
What is UDDI?
UDDI stands for Universal Description, Discovery and Integration. It is a XML based
framework for describing, discovering and integrating web services. It contains a list of
available web services. WSDL is the part of UDDI. More details...
Web services facilitate various applications to communicate with each other and share data
and services among themselves. Other applications can also use the web services. For
example, a VB or .NET application can communicate with a Java web services and vice
versa. Web services are used to make the application platform and technology independent.
A consumer of a web service is not tied to that web service directly. The web service
interface can change over time without compromising the client's ability to interact with the
service. A tightly coupled system implies that the client and server logic are closely tied to
one another, implying that if one interface changes, the other must be updated. Adopting a
loosely coupled architecture tends to make software systems more manageable and facilitates
simpler integration between different systems.
Using XML eliminates any networking, operating system, or platform binding. So Web
Services based applications are highly interoperable application at their core level.
Synchronicity is used to bind the client to the execution of the service. In synchronous
invocations, the client blocks and waits for the service to complete its operation before
continuing. On the other hand, synchronous operations facilitate a client to invoke a service
and then execute other functions.
What is the usage of Service Transport Layer in Web service protocol stack?
This layer includes Hyper Text Transport Protocol (HTTP), Simple Mail Transfer Protocol
(SMTP), File Transfer Protocol (FTP), and newer protocols like Blocks Extensible Exchange
Protocol (BEEP).
What is the usage of Service Description layer in Web Service Protocol Stack?
The Service Description layer is used to describe the public interface to a specific web
service. Currently, service description is handled via the Web Service Description Language
(WSDL).
What is the usage of Service Discovery layer in Web Service Protocol Stack?
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
The Service Discovery layer is used for centralizing services into a common registry and
providing easy publish/find functionality.
Currently, service discovery is handled via Universal Description, Discovery, and Integration
(UDDI).
For setting HTTP status code other than 200, we have to use javax.ws.rs.core.Response class
for response. Below are some of the sample return statements showing it’s usage.
return Response.status(422).entity(exception).build();
Enlisted below are some common HTTP methods along with their functions that are
supported by RESTful web services
Resource is said to be a fundamental concept having a type and relationship with other
resources. In REST architecture, each content is considered as the resource and they are
identified by their URIs.
Resources are represented with the help of XML, JSON, text etc in RESTful architecture.
What are the core components of HTTP request and HTTP response?
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Request Header Contains metadata like client type, cache settings, message body
format, etc for HTTP request message.
Status/Response code Indicates the status of the server for requested resource.
Response Header Consists of metadata like content length, content type, server length,
etc for HTTP response message.
Purpose of URI is to locate resources on the server that are hosting web services.
Safe REST operations are HTTP methods that do not modify resources. For example, using
GET or HEAD on a resource URL, should NEVER change the resource. But it is still
possible, that safe operations do change things on a server or resource. For example: GET
http://localhost:8080/api/employees/1111/delete HTTP/1.1 but it is incorrect, this would
actually delete the employee i.e. Safe methods are methods that can be cached, prefetched
without any repercussions to the resource.
Idempotent operations are those HTTP methods that can be called repetitively many times
without different outcomes. It would not matter if the method is called only once, or many
times over. The result should be the same. Again, this only applies to the result, not the
resource itself.
In Spring REST client, The RestTemplate is the core class for client-side access to Spring
RESTful web services. It communicates HTTP server using RESTful constraints. It is very
similar to other template classes in the Spring like JdbcTemplate and HibernateTemplate etc.
In Spring, RestTemplate provides higher level implementation of corresponding HTTP
methods such as GET, POST, PUT, DELETE, HEAD etc. It provides the methods to
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
communicate by using these HTTP methods with URI template, URI params, request object
and response type as arguments. Read More about RestTemplate.
What is an HttpMessageConverter?
HttpMessageConverter is a strategy interface that specifies a converter that can convert from
and to HTTP requests and responses. Internally Spring MVC uses it to convert the Http
request to an object representation and back. Message converters are used to marshall and
unmarshall Java Objects to and from JSON, XML, etc – over HTTP. Read More about
HttpMessageConverter in Spring.
Yes.
@RequestMapping can be applied to the controller class as well as methods. This annotation
for mapping web requests onto specific handler classes and/or handler methods. Read more
about @RequestMapping annotation.
Yes.
The key difference between a traditional Spring MVC @Controller and the RESTful web
service @RestController is the way the HTTP response body is created. While the traditional
MVC controller relies on the View technology, the RESTful web service controller simply
returns the object and the object data is written directly to the HTTP response as JSON/XML
by registered HttpMessageConverters.
When you use the @ResponseBody annotation on a method, Spring converts the return value
and writes it to the http response automatically. Each method in the Controller class must be
annotated with @ResponseBody.
@PathVariable is used to pass parameter along with the url, sometimes we need to pass
parameters along with the url to get the data. Spring MVC provides support for customizing
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
the URL in order to get data. To achieving this purpose @PathVariable annotation is used in
Spring mvc framework.
What is the HTTP status return code for a successful DELETE statement?
Either we can return HTTP status 204 (NO CONTENT) with no response body or return
HTTP status 200 (OK) along with a response body with representation of the deleted item.
In Spring REST, the primary or most-commonly-used HTTP verbs are POST, GET, PUT,
PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD)
operations, respectively.
REST is nothing but it architectural desgin or paradigms to design restful web service. So
REST does not provide any security constraints by default but we can implement it in the
RESTful web services by using security layers like transport layer security (TLS), auth token
security.
@EnableWebMvc- It used for enabling spring mvc behavior i.e. it is responsible for
registering Spring MVC required Bean Post Processors in the application as like
Jackson2JsonMessageConverter etc.
Name some common http response codes. When do you need @ResponseStatus?
2xx Success
200 OK
201 Created
204 No Content
3xx Redirection
304 Not Modified
4xx Client Error
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
409 Conflict
5xx Server Error
500 Internal Server Error
503 Service Unavailable
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Yes. Transport Layer Security can encrypt the communication to a RESTful Webservice and
authenticate the server to a client.
Yes, Spring REST uses the Spring MVC annotations like @RestController, @RequestBody
and @ResponseBody etc.
Format of URI
<protocol>://<service-name>/<ResourceType>/<ResourceID>
In REST architecture, there is a restriction where a REST web service is not allowed to keep
a client state on the server. Such condition is known as ‘Statelessness’. In such situation, the
client passes its context to the server and in turn, the server stores the context in order to
process client’s further requests.
Every time client interaction takes place, web services are to be provided with extra
information about each request so that they can interpret the client’s state.
For designing a secure RESTful web service, what are the best factors that should be
followed?
As HTTP URL paths are used as a part of RESTful web service, so they need to be
secured. Some of the best practices include the following
Perform validation of all inputs on the server from SQL injection attacks.
Perform user’s session based authentication whenever a request is made.
Never use sensitive data like username, session token password, etc through URL.
These should be passed via POST method.
Methods like GET, POST, PUT, DELETE, etc should be executed with proper
restrictions.
HTTP generic error message should be invoked wherever required.
SOAPUI Web Services
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
What are the various approaches available for developing SOAP based web services?
There are basically 2 different approaches available for developing SOAP-based web
services. These are explained as follows
Contract-first approach: In this approach, the contract is defined first by XML and WSDL
and then java classes are derived from the contract.
Contract-last approach: In this approach, java classes are defined first and then the contract
is generated which is usually the WSDL file from the java class.
One of the major hindrance observed by users of SOAP is the ‘Firewall security mechanism’.
In this case, all the HTTP ports except those which bypass firewall are locked. In some cases,
a technical issue of mixing specification of message transport with message structure is also
observed.
SOAP is just like other XML document and has following elements
Envelope: This element is defined as the mandatory root element. It translates the
XML document and determines the start and end of the SOAP message.
Header: This element contains the optional header attributes of the message that
contains specific information of the application. This element can occur multiple
times and are intended to add new features and functionalities.
Body: This element is mandatory and contains the call and response messages. It is
also defined as the child element of the envelope containing all the application
derived XML data that has been exchanged as a part of SOAP message.
Fault element: Errors that occur during processing of the messages are handled by the
fault element. If the error is present, then this element appears as a child element of
the body. However, there can only be one fault block.
We have seen the basic work of a SOAP envelope element in the previous answer, now let us
see some of its characteristics
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
A namespace and an optional encoding style are used in case of optional SOAP
encoding.
Enlisted below are some important syntax rules that are applicable for SOAP message
A SOAP message
Must be encoded using XML.
Must use the SOAP envelope namespace.
Must use the SOAP encoding namespace.
Must not contain the DTD reference.
Must not contain XML processing instructions.
Define SOA?
Some of the key principles on which SOA is based are mentioned below
The service contract should be standardized containing all the description of the
services.
There is loose coupling defining the less dependency between the web services and
the client.
It should follow Service Abstraction rule, which says the service should not expose
the way functionality has been executed to the client application.
Services should be reusable in order to work with various application types.
Services should be stateless having the feature of discoverability.
Services break big problems into little problems and allow diverse subscribers to use
the services.
This REST web service interview questions is open for you all, post you answer in comment
section.
What is RESTEasy ?
RESTEasy is another REST framework introduced in JBoss Application Server. This was
rather easy REST interview questions. you can answer in detail only if you have used this or
working in JBoss.
What are the tools used for creating RESTFull web services ?
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
You can use AJAX(Asynchronous JavaScript with XAML) and Direct Web Removing to
consume web serives in web application. Both Eclipse and NetBeans also supported
development of RESTFul services.
Another common REST interview questioning RESTFul web service each Resource supports
GET, POST, PUT and DELETE http methods.GET is mapped to represent(), POST -
acceptRepresentation(), PUT- storeRepresentation and DELET for rmeoveRepresentation.
In top-down approach first WSDL document is created and than Java classes are developed
based on WSDL contract, so if WSDL contract changes you got to change your Java classes
while in case of bottom up approach of web service development you first create Java code
and then use annotations like @WebService to specify contract or interface and WSDL field
will be automatically generated from your build.
What happens if RestFull resources are accessed by multiple clients ? do you need to
make it thread-safe?
Since a new Resource instance is created for every incoming Request there is no need to
make it thread-safe or add synchronization. multiple client can safely access RestFull
resources concurrently.
It can help create functional, security and load testing test suites.
Data driven testing and scenario based testing is also performed.
It has the ability to impersonate web services as well as has got built-in reporting
abilities.
Web Services Security
To ensure reliable transactions and secure confidential information, web services requires
very high level of security which can be only achieved through Entrust Secure Transaction
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Platform. Security issues for web services are broadly divided into three sections as described
below
1) Confidentiality: A single web service can have multiple applications and their service
path contains a potential weak link at its nodes. Whenever messages or say XML requests are
sent by the client along with the service path to the server, they must be encrypted. Thus,
maintaining the confidentiality of the communication is a must.
Client certificates
3) Network Security: This is a serious issue which requires tools to filter web service traffic.
Integration
Authentication
Authorization
Digital Signatures
Encryption processes
Entrust Identification Service is categorized under Entrust Secure Transaction Platform which
provides essential security capabilities to ensure secure transactions. This usually allows
companies to fully control the identities that are trusted to perform web service transactions.
Entrust Entitlement service is those whose task is to verify the services that are attempting to
access the web services. It basically ensures security in business operations as well as some
authentication services.
As the name suggests, Entrust Privacy Service perform encryption of the data so that only
concerned parties are able to access the data. It basically deals with two factors
Confidentiality
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Security
Explain WSDL?
WSDL stands for Web service Description Language. It is a simple XML document which
comes under the Service Description layer of Web Service Protocol Stock and describes the
technical details or locates the user interface to web service. Few of the important
information present in WSDL document are
Method name
Port types
Service end point
Method parameters
Header information
Origin, etc
The different elements of WSDL document along with brief description is enlisted below
Types: This defines the message data types, which are in the form of XML schema, used by
the web services.
Message: This defines the data elements for each operation where messages could be the
entire document or an argument that is to be mapped.
Port Type: There are multiple services present in WSDL. Port type defines the collection of
operations that can be performed for binding.
Binding: Determines and defines the protocol and data format for each port type.
Operations: This defines the operations performed for a message to process the message.
Message element describes the data that has been exchanged between the consumer and the
web service providers. Every web service consists of two messages and each message has
zero or more <part> parameters. The two messages are
WSDL basically defines 4 types of Operation type responses. These are enlisted below
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
Yes, it is possible to bind WSDL to SOAP. The binding is possible by basically two
attributes
Definition element is described as the root of WSDL document which defines the name of the
web service as well as act as a container for all the other elements.
Every port element is related to a specific binding by defining an individual endpoint. The
port element has following two attributes
Name: This attribute provides the unique name within the WSDL document.
Binding: This attribute refers to the process of binding which has to be performed as per the
linking rules defined by WSDL.
What are the points that should be considered by ports while binding?
WSDL allows extensibility elements which are used to specify binding information. Below
are few important points that should be kept in consideration while binding.
Web service protocol stack consists of 4 layers. This can be described as follows
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
1) Service transport: This is the first layer which helps in transporting XML messages
between various client applications. This layer commonly uses the below-mentioned
protocols:
2) XML messaging: This layer is based on the XML model where messages are encoded in
common XML format which is easily understood by others. This layer includes
XML-RPC
3) Service description: This layer contains description like location, available functions, and
data types for XML messaging which describes the public interface to a specific web service.
This layer includes:
4) Service discovery: This layer is responsible for providing a way to publish and find web
services over the web. This layer includes:
Web service framework consists of an architecture which consists of three different layers.
The roles of these layers are defined as below
Service Provider: As the name denotes, service provider role is to create the web service and
makes it accessible to the client applications over the internet for their usage.
Service Requestor: Service requestor is basically any consumer of web service like any
client application. Client applications are written in any language contact web service for any
type of functionality by sending XML request over the available network connection.
Service Registry: Service registry is the centralized directory which helps locate web
services for client applications. Here we can find the existing web services, as well as
developers, can also create the new one.
The Service Provider uses the ‘Publish’ interface of Service Registry to make the existing
web services available to client applications. With all the information provided by the service
registry, service requestor is able to bind or invoke services.
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
RPC is Remote Procedure Call and as the name suggests, it is the method of calling a
procedure or function available on any remote computer.
XML stands for Extensible Markup Language. Thus XML-RPC represents a simple protocol
that performs RPCs by using XML messaging. This has been considered as an excellent tool
for connecting different environments and also establishing connections between wide
varieties of computers.
We have already discussed web services, its architecture, components. Now, let us see
some its advantages
Every application is now on the internet and it the web service which provides some
sort of required functionality to the client applications.
Web services help in exposing the existing functionalities over the network to help
other applications to use in their programs.
It has features like ‘Interoperability’ which determines the communication between
various applications, sharing of data as well as services among themselves.
Web services use the standardized web service protocol stack for communication
which consists of 4 layers namely, Service Transport, XML messaging, Service
description and Service discovery.
It has the feature of the low cost of communication because of the usage of SOAP
(Simple Object Access Protocol) over HTTP protocol.
Easy to deploy, integrate and is reusable.
Allows simple integration between different feature as a part of loose coupling
feature.
UDDI is an XML-based standard in the service discovery layer of web service protocol stack.
It is used for publishing and finding web services over the web as it acts like a directory.
Some of the features of UDDI are explained below
[email protected] 09441281686
WEB SERVICES INTERVIEW QUESTIONS
UDDI uses the language known as WSDL (Web Service Description Language)
Explain BEEP?
BEEP stands for Blocks Extensible Exchange Protocol. BEEP is determined as building new
protocols for the variety of applications such as instant messaging, network management, file
transfer etc. It is termed as new Internet Engineering Task Force (IETF) which is layered
directly over TCP. It has some built-in features like
Authentication
Security
Error handling
Handshake Protocol
SoapUI
REST client
JMeter
The only requirement for accessing web services from any application is that it must support
XML-based request and response. There is no need or say the requirement of installing any
application for accessing web services.
[email protected] 09441281686