0% found this document useful (0 votes)
369 views

Q1 What Are Web Services ?: Answers - HTML

Web services allow software applications to communicate over the HTTP protocol. They provide interoperability between applications running on different platforms through standards-based web APIs. The key characteristics of web services are interoperability, extensibility, and machine-readable descriptions. SOA is a style that exposes business capabilities as services. Web services realize SOAP by leveraging XML over common protocols like HTTP. REST is an architectural style using HTTP to transmit and manipulate representations of resources through URIs. Popular frameworks for developing RESTful web services include Jersey and Restlet.

Uploaded by

prema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
369 views

Q1 What Are Web Services ?: Answers - HTML

Web services allow software applications to communicate over the HTTP protocol. They provide interoperability between applications running on different platforms through standards-based web APIs. The key characteristics of web services are interoperability, extensibility, and machine-readable descriptions. SOA is a style that exposes business capabilities as services. Web services realize SOAP by leveraging XML over common protocols like HTTP. REST is an architectural style using HTTP to transmit and manipulate representations of resources through URIs. Popular frameworks for developing RESTful web services include Jersey and Restlet.

Uploaded by

prema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 226

http://javahungry.blogspot.

com/2015/07/web-services-interview-questions-and-
answers.html

Q1 What are web services ?

According to oracle docs, web services can be defined as

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 processable descriptions.

for example in simple words , when we call somebody so the person dialing and
calling is the client application , while person receiving the call is server application
and "hello" word is the protocol as similar to HTTP request .

Q2 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.

Q3 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.

Q4 What is REST?

REST (REpresentational State Transfer) is an architectural style by which data can be


transmitted over transport protocol such as HTTP(S).
Q5 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
REST supports different formats like text, JSON and XML; SOAP only
supports XML;
REST works only over HTTP(S) on a transport layer; SOAP can be used
different protocols on a transport layer;
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;
SOAP based reads can’t be cached, for SOAP need to provide caching;
REST based reads can be cached;
SOAP supports SSL security and WS-security(Web Service-security);
REST only supports SSL security;
SOAP supports ACID (Atomicity, Consistency, Isolation, Durability);
REST supports transactions, but it is neither ACID compliant nor can provide
two phase commit.
Q6 How to decide which one of web service to use REST or SOAP?

“REST vs SOAP” we can 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 favored where service requires comprehensive
support for security (WS-security) and transactional safety (ACID).

“SOAP”

Q7 What is WSDL?

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

Q8 What is JAX-WS?

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

Q9 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.

Q10 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="<claim061400a.xml@ javahungry.com>"
Content-Description: This is the optional message description.
<?xml version='1.0' ?>
<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]>

...binary TIFF image...


--MIME_boundary—

Q11 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.

Q12 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.

Q13 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:
<?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>

Q14 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

Q15 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.

Q16 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"

Q17 What are 2 styles web service’s endpoint by using JAX-WS?

RPC (remote procedure call) style web service in JAX-WS;


document style web service in JAX-WS.

Q18 What is encoding rules for header entries?

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.

Q19 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

Q20 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 the tool are required to test SOAP services?

SOAPUI tool for SOAP WS: http://www.soapui.org/

Q21 What is the difference between SOAP and other remote access techniques?

SOAP is simple to use and it is non - symmetrical unlike DCOM or


CORBA is highly popular and usually have complexity in them.
SOAP provides greater platform independent with the language
independence unlike DCOM or CORBA doesn't provide any of these.
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.
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.

“REST”

Q22 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.

Q23 What are HTTP methods supported by REST?

GET;
POST;
PUT;
DELETE;
OPTIONS;
HEAD.

Q24 Whether can use GET request instead of POST to create a resource?

It is not possibly, because GET can’t change a resource.

Q25 What is the difference between PUT and POST?

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.

Q26 What is WADL?

WADL (Web Application Description Language) is a XML description of a deployed


RESTful web application.

Q27 What are frameworks available to implement REST web services?

Jersey, Restlet, EasyRest, etc.

Q28 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.
http://restlet.com/

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
contains support for Web Application Description Language (WADL);
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.
https://jersey.java.net/

Q30 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.
http://resteasy.jboss.org/

Q31 What is the difference between AJAX and REST?

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;
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.

Q32 What tool are required to test REST services?

Firefox “poster” plugin for RESTFUL services. https://addons.mozilla.org/en-


us/firefox/addon/poster/
Q33 What does a @Path annotation do?

@Path annotation binds URI pattern to a Java method.

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

@Path("/persons")
public class PersonRestService {

@GET
public Response getPerson() {

return Response.status(200).entity("getPerson is called").build();

@GET
@Path("/vip")
public Response getPersonVIP() {

return Response.status(200).entity("getPersonVIP is called").build();


}
}

On calling URI: “/persons” result: getPerson is called


On calling URI: “/persons/vip” result: getPersonVIP is called

Q34 What does a @PathParam do?

@PathParam annotation injects the value of URI parameter that defined in @Path
expression.

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/persons")
public class PersonRestService {

@GET
@Path("{id}")
public Response getPersonById(@PathParam("id") String id) {

return Response.status(200).entity("getPersonById is called, id : " + id).build();


}
}

On calling URI: “/persons/1” result: getPersonById is called, id : 1

Q35 What does a @QueryParam do?

@QueryParam annotation injects URI query parameter into Java method.

import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

@Path("/persons")
public class PersonService {

@GET
@Path("/query")
public Response getPersons(
@QueryParam("from") int from,
@QueryParam("to") int to,
@QueryParam("orderBy") List&lt;String&gt; orderBy) {

return Response
.status(200)
.entity("getPersons is called, from : " + from + ", to : " + to
+ ", orderBy" + orderBy.toString()).build();

}
}

On calling URI: “/persons/query?from=10&to=20&orderBy=age&orderBy=name”


result: getPersons is called, from : 10, to : 20, orderBy[age, name]

Q36 What does a @MatrixParam do?

@MatrixParam are a set of “name=value” in URI path.

import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/books")
public class BookService {

@GET
@Path("{year}")
public Response getBooks(@PathParam("year") String year,
@MatrixParam("author") String author,
@MatrixParam("country") String country) {

return Response
.status(200)
.entity("getBooks is called, year : " + year
+ ", author : " + author + ", country : " + country)
.build();

}
}

On calling URI: “/books/2015” result: getBooks is called, year : 2015, author : null,
country : null
On calling URI: “/books/2015;author= doyle;country=scotland” result: getBooks is
called, year : 2015, author : doyle, country : scotland

Q37 What does a @FormParam do?

@FormParam bind HTML form parameters value to a Java method.

import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
@Path("/persons")
public class PersonService {

@POST
@Path("/add")
public Response addPerson(
@FormParam("name") String name,
@FormParam("age") int age) {

return Response.status(200)
.entity("addPerson is called, name : " + name + ", age : " + age)
.build();

}
}

HTML form:

<html>
<body>
<form action="/persons/add" method="post">
<p>
Name : <input type="text" name="name" />
</p>
<p>
Age : <input type="text" name="age" />
</p>
<input type="submit" value="Add Person" />
</form>

</body>
</html>

Q39 How to get HTTP request header in JAX-RS (2 ways)?

inject directly with @HeaderParam;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.core.Response;
@Path("/persons")
public class PersonService {

@GET
@Path("/get")
public Response getPerson(
@HeaderParam("person-agent") String personAgent) {

return Response.status(200)
.entity("getPerson is called, personAgent : " + personAgent)
.build();

}
}

On calling URI: “/persons/get” result: getPerson is called, personAgent : Mozilla/5.0


(Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0
pragmatically via @Context.

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;

@Path("/persons")
public class PersonService {

@GET
@Path("/get")
public Response getPerson(@Context HttpHeaders headers) {

String personAgent = headers.getRequestHeader("person-agent").get(0);

return Response.status(200)
.entity("getPerson is called, personAgent : " + personAgent)
.build();

}
}

On calling URI: “/persons/get” result: getPerson is called, personAgent : Mozilla/5.0


(Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0

Q40 How to download file in JAX-RS?


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.

import java.io.File;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;

@Path("/image")
public class ImageService {

private static final String FILE_PATH = "c:\\my.png";

@GET
@Path("/get")
@Produces("image/png")
public Response getFile() {

File file = new File(FILE_PATH);

ResponseBuilder response = Response.ok((Object) file);


response.header("Content-Disposition",
"attachment; filename=image_from_server.png");
return response.build();
}
}

http://javarevisited.blogspot.in/2012/01/rest-web-services-framework-
interview.html

REST web services has quickly becoming defacto web services in web world and has
almost replaced SOAP based web services which rules the world before. with
growing use of REST in web technology space REST is also becoming increasingly
important on J2EE and other web development interviews and if you say you know
web-service then be prepare for some REST concept related questions. In this article
I have put together some of the basic and some advanced REST web service
questions together which will be useful to revise the concept before appearing for
any REST web service interviews:

This article is in continuation of my earlier post on Interviews like Top Spring


Interview Questions and Top Struts Interview Questions.
Top 10 REST Web services Framework interview questions answers
RESTFul Web Services Interview Questions and Answers
Here are list of my REST Interview questions, helpful for quick review before going
for any web services interview on Java J2EE.

300x250 Medium Rectangle

1) What is REST and RESTful web services ?


this is the first REST interview question on most of interviews as not everybody
familiar with REST and also
start discussion based on candidates response. Anyway REST stands for
REpresentational State Transfer (REST) its a relatively new concept of writing web
services which enforces a stateless client server design where web services are
treated as resource and can be accessed and identified by there URL unlike SOAP
web services which were defined by WSDL.

Web services written by apply REST Architectural concept are called RESTful web
services which focus on System resources and how state of Resource should be
transferred over http protocol to a different clients written in different languages. In
RESTful web services http methods like GET, PUT, POST and DELETE can can be used
to perform CRUD operations.

2) 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:

1) REST is more simple and easy to use than 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.
5) REST web services call can be cached to improve performance.
3) What is Restlet framework ?
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.

4) What is Resource in REST framework ?


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.

5) Can you use Restlet without any web-container ?


Yes, Restlet framework provide default server which can be used to handle service
request in web container is not available.

6) What is difference between Restlets and Jersey ?


This REST web service interview questions is open for you all, post you answer in
comment section.

7) 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.

8) 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.

9) How to display custom error pages using RestFull web services ?


In order to customize error you need to extend StatusService and implement
getRepresentation(Status, Request, Response) method with your custom code now
assign instance of your CustomStatusService to appropriate "statusService
property".

10) Which HTTP methods are supported by RestFull web 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.

11) What is difference between top-down and bottom-up approach of developing


web services ?
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.

12) 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.
Read more: http://javarevisited.blogspot.com/2012/01/rest-web-services-
framework-interview.html#ixzz47ePbCzjQ

http://www.java-success.com/java-web-services-interview-questions-and-answers/

As an enterprise Java developer, you will be spending more time integrating systems
via web services & messaging. Java Web Services interview questions are very
popular.
Q1. What are the different styles of Web Services used for application integration?
and What are the differences between both approaches?
A1. SOAP WS and RESTful Web Service. Web services are very popular and widely
used to integrate similar (i.e. Java applications) and disparate systems (i.e. legacy
applications and applications written in .Net etc) as they are language neutral.

Java Web Service styles comparison


SOAP Web service RESTful Web service
SOAP (Simple Object Access Protocol) is a standard communication REST is an architectural s
protocol on top of transport protocols such as HTTP, SMTP, Messaging, TCP, transport protocol such a
UDP, etc.
Each unique URL is a som
Account, Customer, etc),
Objects) via HTTP verb “G
“PUT”.

SOAP Layers
SOAP uses its own protocol and focuses on exposing pieces of application REST is about exposing a
logic (not data) as services. SOAP exposes operations. SOAP is focused on (Create, Read, Update, an
accessing named operations, which implement some business logic through accessing named resourc
different interfaces.
SOAP only permits XML data formats. REST permits many differ
HTML, atom, RSS, etc. JSO
data and parses much fas

SOAP URL: http://localhost:808

REST
SOAP based reads cannot be cached. The application that uses SOAP needs REST based reads can be
to provide cacheing.
Supports both SSL security and WS-security, which adds some enterprise Supports only point-to-p
security features. Supports identity through intermediaries, not just point to
point SSL. — The basic mechanism b
requests based on a key r
— WS-Security maintains its encryption right up to the point where the received at the destinatio
request is being processed. This means the request is
— WS-Security allows you to secure parts (e.g. only credit card details) of client and the server. Onc
the message that needs to be secured. Given that encryption/decryption is certificate), it is decrypte
not a cheap operation, this can be a performance boost for larger messages. — The SSL encrypts the w
— It is also possible with WS-Security to secure different parts of the not.
message using different keys or encryption algorithms. This allows separate
parts of the message to be read by different people without exposing other,
unneeded information.
— SSL security can only be used with HTTP. WS-Security can be used with
other protocols like UDP, SMTP, etc.
Has comprehensive support for both ACID based transaction management REST supports transaction
for short-lived transactions and compensation based transaction provide two phase comm
management for long-running transactions. It also supports two-phase is limited by its HTTP prot
commit across distributed resources.
SOAP has success or retry logic built in and provides end-to-end reliability REST does not have a stan
even through SOAP intermediaries. invoking the service to de
Which one to favor? 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.
SOA done right is more about RESTFul + JSON, favoring lighter weight approaches to
moving messages around than the heavyweight ESBs using WSDL+XML that gave
SOA a bad name.
Q2. Differentiate between SOA (Service Oriented Architecture) versus WOA (Web
Oriented Architecture)?
A2. WOA extends SOA to be a light-weight architecture using technologies such as
REST and POX (Plain Old XML). POX compliments REST. JSON is a variant for data
returned by REST Web Services. It consumes less bandwidth and is easily handled by
web developers mastering the Javascript language

WOA – RESTFul Service Calls via AJAX to populate different sections of a UI


SOA and WOA differ in terms of the layers of abstraction. SOA is a system-level
architectural style that tries to expose business capabilities so that they can be
consumed by many applications. WOA is an interface-level architectural style that
focuses on the means by which these service capabilities are exposed to consumers.
You can start out with a WOA and then grow into SOA.
SOA (Service Oriented Architecture)
Q3. How would you decide what style of Web Service to use? SOAP WS or REST?
A3. 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.
1) 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).
2) Do consumers and the service providers require a formal contract? (SOAP has a
formal contract via WSDL)
3) Do we need to support multiple data formats?
4) Do we need to make AJAX calls? (REST can use the XMLHttpRequest)
5) Is the call synchronous or asynchronous?
6) Is the call stateful or stateless? (REST is suited for statless CRUD operations)
7) What level of security is required? (SOAP WS has better support for security)
8) What level of transaction support is required? (SOAP WS has better support for
transaction management)
9) Do we have limited band width? (SOAP is more verbose)
10) What’s best for the developers who will build clients for the service? (REST is
easier to implement, test, and maintain)
Q4. What tools do you use to test your Web Services?
A4. SoapUI tool for SOAP WS & RESTFul web service testing and on the browser the
Firefox “poster” plugin or Google Chrome “Postman” extension for RESTFul services.
Q5. Why not favor traditional style middle-ware such as RPC, CORBA, RMI and DCOM
as opposed to Web services?
A5. The traditional middle-wares tightly couple connections to the applications.
Tightly coupled applications are hard to maintain and less reusable. Generally do not
support heterogeneity. Do not work across Internet and 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 or JSON messages to
each other via a Web API. Do work across internet, less expensive and easier to use.
Q6. What is the difference between SOA and a Web service?
A6. 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.
Q7. What is a microservice architecture (aka MSA)?
A7. Martin Fowler defines Microservices as a subset of Service Oriented Architecture
(SOA). In SOA, the services can be of any size. In a microservice, the service performs
a single function. Micro means small. The term micro is not well defined, but the
questions you need to ask are – Are my services small enough?
1) can they be reused in many different business contexts as possible?
2) can they be individually deployed?
3) can they be individually scaled?
4) can they be individually monitored?
5) can they be individually developed by different small teams?
Q8. What are the key characteristics of microservices?
A8. Focuses more on “loose coupling & high cohesion” than reuse. The definition of
a service is an individual execution unit, and the definition of “micro” is the size, so
that the service can be autonomously developed, deployed, scaled & monitored.
This means the service is full-stack and has control of all the components like UI,
middleware, persistence, and transaction. The services can be invoked both
synchronously and asynchronously.
Microservices deployed to multiple hosts (e.g. on the cloud)
Microservices
1) are reusable, but NOT ALWAYS. How do we ensure the highest possible reuse?
Make all service so small that they can be reused in many different business contexts
as possible. Whilst it is possible to have very small services with few or no
dependencies on other services, microservices are not always reusable because 1)
unlike libraries that share only behavior, services generally share both behavior and
data. 2) By increasing reuse, you are increasing dependencies and coupling as
explained below.
2) are loosely coupled and highly cohesive. All good software designs should strive
for loose/low coupling & tight/high cohesion. Every time we reuse, we increase our
coupling. How? If we wrote the code all in one place, there are no dependencies. By
reusing code, you’ve created a dependency. The more you reuse, the more
dependencies you have.
Coupling refers to how related are two or more classes/modules and how
dependent they are on each other. Loose coupling would mean that changing
something major in one class should not affect the other. Tight coupling would make
your code difficult to make changes as making a change to one class/module will
require a revamp to other tightly coupled classes/modules.
High cohesion means a class is focused on what it should be doing. Low cohesion
means a class does a great variety of actions.
So, applications built from microservices aim to be as decoupled and as cohesive as
possible by acting more like filters in UNIX:

ls | ws -c
1
2 ls | ws -c
3

Receiving a request -> applying logic as appropriate -> producing a response |


Receiving a request -> applying logic as appropriate -> producing a response | …
3) require a service registration as multiple processes working together need to find
each other. Spring Cloud is built on Spring Boot, and incorporates the registration
service called “Eureka” built by Netflix.
Microservices allow large systems to be built from a number of collaborating
components. The collaborating components can be web services, messaging, event-
driven APIs, Web Sockets, and non-HTTP backed RPC mechanisms. So, A web service
can be a microservice, but microservice might not be a web service.
Q09. How does SOA (Service Oriented Architecture) differ from MSA (i.e.
MicroServices Architecture)?
A09.
SOA (Service Oriented Architecture) MSA (MicroServices Architecture)
SOA is coarse-grained. MSA is fine-grained. Often behavior & d
Adheres to the Single Responsibility Pri
SOA focuses more on re-usability. SOA has higher coupling, MSA focuses more on low coupling & h
where services depend on other services to function. emphasizes on autonomy, where servic
developed, deployed, scaled & monitor
value on its own with both behavior &
allows the service to operate independ
cohesion increases it’s ability to add val
Q10. How do you achieve low latency in microservices ?
A10. A cloud based scale out model spins out more servers to improve microservices
that don’t perform well.
You can also scale up by
Favoring in-memory services.
Allocating more heap and tuning the JVM for GC as microservices tend to consume
more memory.
Making use of reactive programming techniques relying on asynchronous message
passing.
Owning their own data without sharing with other services.
Avoid caching (or use sparingly) and transactions where applicable.
Using Web Sockets for better scalability of the real-time web applications. It
provides bidirectional & full duplex communication over a single socket that
is native to the browser without any additional overhead or complexity.
Q11. How do you version your RESTful web services?
A11. URL & HTTP headers.
1) A commonly used way to version your API is to add a version number in the URL.

/api/v1/user/67
1
2 /api/v1/user/67
3

to move to another API with significant changes

/api/v2/user/67
1
2 /api/v2/user/67
3

2) Hypermedia way using the “Accept” HTTP headers.

GET /api/v2/user/67 HTTP/1.1


Accept: application/json; version=1.0
1
2 GET /api/v2/user/67 HTTP/1.1
3 Accept: application/json; version=1.0
4

Q12. What are the different types of RESTful API changes requiring newer
versioning?
A12. There is no single standard approach, but here are some guidelines:
1) Simple format or cosmetic changes: Changing the output format from XML in v1
to JSON in v2. This requires JAXB annotation changes.
2) Modest schema changes. Make the required logic changes without having to
create any new packages.
3) Major schema changes. May require a parallel set of packages and artifacts like
controllers, services, entities, and possibly database tables.

Q. What are the high level steps in developing a RESTful web service in Java?
A. You can see the complete tutorial in the tutorials section. This post is to quickly
explain the major steps at the job interview. Knowing all the basics is of no use if you
can’t write a web service.
Step 1: Create a Maven project structure:

mvn archetype:generate -DgroupId=com.mytutorial -DartifactId=simpleRestWeb -


DarchetypeArtifactId=maven-archetype-webapp
1 mvn archetype:generate -DgroupId=com.mytutorial -DartifactId=simpleRestWeb -DarchetypeArtifac

Step 2: Need the libraries/frameworks


This example shows RESTEasy as JAX-RS implementation from JBoss.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mytutorial</groupId>
<artifactId>simpleRestWeb</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>simpleRestWeb Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<resteasy.version>2.3.6.Final</resteasy.version>
<javax-servlet.version>3.0.1</javax-servlet.version>
<spring.version>3.1.0.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- JAX-RS RESTEasy implementation-->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<!-- <scope>provided</scope> -->
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<!-- <scope>provided</scope> -->
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<!-- <scope>provided</scope> -->
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring</artifactId>
<scope>runtime</scope>
<version>${resteasy.version}</version>
</dependency>
<!-- Servelet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
<version>${javax-servlet.version}</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>compile</scope>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<finalName>simpleRestWeb</finalName>
</build>
</project>
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLS
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_
3 <modelVersion>4.0.0</modelVersion>
4 <groupId>com.mytutorial</groupId>
5 <artifactId>simpleRestWeb</artifactId>
6 <packaging>war</packaging>
7 <version>1.0-SNAPSHOT</version>
8 <name>simpleRestWeb Maven Webapp</name>
9 <url>http://maven.apache.org</url>
10
11 <properties>
12 <resteasy.version>2.3.6.Final</resteasy.version>
13 <javax-servlet.version>3.0.1</javax-servlet.version>
14 <spring.version>3.1.0.RELEASE</spring.version>
15 </properties>
16
17 <dependencies>
18 <dependency>
19 <groupId>junit</groupId>
20 <artifactId>junit</artifactId>
21 <version>3.8.1</version>
22 <scope>test</scope>
23 </dependency>
24
25 <!-- JAX-RS RESTEasy implementation-->
26 <dependency>
27 <groupId>org.jboss.resteasy</groupId>
28 <artifactId>jaxrs-api</artifactId>
29 <!-- <scope>provided</scope> -->
30 <version>${resteasy.version}</version>
31 </dependency>
32 <dependency>
33 <groupId>org.jboss.resteasy</groupId>
34 <artifactId>resteasy-jaxrs</artifactId>
35 <!-- <scope>provided</scope> -->
36 <version>${resteasy.version}</version>
37 </dependency>
38 <dependency>
39 <groupId>org.jboss.resteasy</groupId>
40 <artifactId>resteasy-jaxb-provider</artifactId>
<!-- <scope>provided</scope> -->
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring</artifactId>
<scope>runtime</scope>
<version>${resteasy.version}</version>
</dependency>

<!-- Servelet API -->


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
<version>${javax-servlet.version}</version>
</dependency>

<!-- Spring -->


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>compile</scope>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<finalName>simpleRestWeb</finalName>
</build>
</project>

Step 3: Web service interface with JAX-RS annotations


Folder: src/main/java

package com.mytutorial;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@Path("/myapp")
public interface SimpleRestWeb {
@GET
@Path("/name/{name}")
public String sayHello(@PathParam("name") String name);
}
1 package com.mytutorial;
2
3 import javax.ws.rs.GET;
4 import javax.ws.rs.Path;
5 import javax.ws.rs.PathParam;
6
7 @Path("/myapp")
8 public interface SimpleRestWeb {
9
10 @GET
11 @Path("/name/{name}")
12 public String sayHello(@PathParam("name") String name);
13 }

Step 4: Implementation of Web service interface


package com.mytutorial;
public class SimpleRestWebImpl implements SimpleRestWeb {
@Override
public String sayHello(String name) {
String result = "Hello " + name;
return result;
}
}
1 package com.mytutorial;
2
3 public class SimpleRestWebImpl implements SimpleRestWeb {
4
5 @Override
6 public String sayHello(String name) {
7 String result = "Hello " + name;
8 return result;
9 }
10 }
11

Step 4: Spring XML config as IoC.


Folder: src/main/resources/com/mytutorial

<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="simpleRestWeb" class="com.mytutorial.SimpleRestWebImpl" />
</beans>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:aop="http://www.springframework.org/schema/aop"
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframe
6 http://www.springframework.org/schema/aop http://www.springframework.org/sch
7
8 <bean id="simpleRestWeb" class="com.mytutorial.SimpleRestWebImpl" />
9 </beans>
10

Step 5: web.xml deployment descriptor


to bootstrap Spring and initialize servlet, mapping, etc. Folder:
src/main/webapp/WEB-INF.

<!DOCTYPE web-app PUBLIC


"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/com/mytutorial/applicationContext.xml</param-
value>
</context-param>
<context-param>
<param-name>resteasy.use.deployment.sensitive.factory</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<listener>
<listener-
class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<listener>
<listener-
class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-simple</servlet-name>
<servlet-
class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-simple</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
1 <!DOCTYPE web-app PUBLIC
2 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3 "http://java.sun.com/dtd/web-app_2_3.dtd" >
4
5 <web-app>
6 <display-name>Archetype Created Web Application</display-name>
7
8 <context-param>
9 <param-name>contextConfigLocation</param-name>
10 <param-value>classpath:/com/mytutorial/applicationContext.xml</param-value>
11 </context-param>
12
13 <context-param>
14 <param-name>resteasy.use.deployment.sensitive.factory</param-name>
15 <param-value>false</param-value>
16 </context-param>
17
18 <context-param>
19 <param-name>resteasy.servlet.mapping.prefix</param-name>
20 <param-value>/rest</param-value>
21 </context-param>
22
23 <listener>
24 <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
25 </listener>
26 <listener>
27 <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
28 </listener>
29
30 <servlet>
31 <servlet-name>resteasy-simple</servlet-name>
32 <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
33 </servlet>
34
35 <servlet-mapping>
36 <servlet-name>resteasy-simple</servlet-name>
37 <url-pattern>/rest/*</url-pattern>
38 </servlet-mapping>
39 </web-app>
40

Build the war and deploy to say JBoss application server.


Step 6: JBoss deployment descriptor
Folder: src/main/webapp/WEB-INF/jboss-web.xml

<jboss-web>
<context-root>tutorial</context-root>
</jboss-web>
1 <jboss-web>
2 <context-root>tutorial</context-root>
3 </jboss-web>
4

The URL = http://localhost:8080/tutorial/rest/myapp/name/arul


tutorial: defined in jboss-web.xml (application context)
rest: defined in web.xml (servlet-mapping)
myapp/name/arul: in SimpleRestWeb interface (@Path annotation at class and
method level)
Project Structure:
RESTful Web Service using RESTEasy
Hmmm, some of the other steps are agreeing on content type like XML, JSON, etc
among the producer & consumers, the contract for the content, service retry logic,
service timeouts, using JAXB to map XML/JSON to Java objects, etc need to be sorted
out.

11: ♥ JAX-WS how to create a SOAP web service in Java?


Posted on June 18, 2015 by Arulkumaran Kumaraswamipillai
Tweet
0

Like
0

in
Share

Step 1:Create the Java Maven project:

mvn archetype:generate -DgroupId=com.mytutorial -DartifactId=simpleSoapWeb -


DarchetypeArtifactId=maven-archetype-webapp
1 mvn archetype:generate -DgroupId=com.mytutorial -DartifactId=simpleSoapWeb -DarchetypeArtifa

Step 2: Need the libraries/frameworks


This example shows Apache CXF library as JAX-WS implementation with Spring and
deployed to JBoss server 5.1.1.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mytutorial</groupId>
<artifactId>simpleSoapWeb</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>simpleSoapWeb Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<cxf.version>2.7.9</cxf.version>
<javax-servlet.version>3.0.1</javax-servlet.version>
<spring.version>3.1.0.RELEASE</spring.version>
</properties>
<dependencies>
<!-- JAX-WS -->
<!-- apache cxf -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- Servelet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
<version>${javax-servlet.version}</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>compile</scope>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
<build>
<finalName>simpleSoapWeb</finalName>
</build>
</project>
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLS
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_
3 <modelVersion>4.0.0</modelVersion>
4 <groupId>com.mytutorial</groupId>
5 <artifactId>simpleSoapWeb</artifactId>
6 <packaging>war</packaging>
7 <version>1.0-SNAPSHOT</version>
8 <name>simpleSoapWeb Maven Webapp</name>
9 <url>http://maven.apache.org</url>
10 <properties>
11 <cxf.version>2.7.9</cxf.version>
12 <javax-servlet.version>3.0.1</javax-servlet.version>
13 <spring.version>3.1.0.RELEASE</spring.version>
14 </properties>
15
16 <dependencies>
17 <!-- JAX-WS -->
18 <!-- apache cxf -->
19 <dependency>
20 <groupId>org.apache.cxf</groupId>
21 <artifactId>cxf-rt-frontend-jaxws</artifactId>
22 <version>${cxf.version}</version>
23 </dependency>
24
25 <dependency>
26 <groupId>org.apache.cxf</groupId>
27 <artifactId>cxf-rt-transports-http</artifactId>
28 <version>${cxf.version}</version>
29 </dependency>
30
31 <!-- Servelet API -->
32 <dependency>
33 <groupId>javax.servlet</groupId>
34 <artifactId>javax.servlet-api</artifactId>
35 <scope>provided</scope>
36 <version>${javax-servlet.version}</version>
37 </dependency>
38
39 <!-- Spring -->
40 <dependency>
41 <groupId>org.springframework</groupId>
42 <artifactId>spring-web</artifactId>
43 <scope>compile</scope>
44 <version>${spring.version}</version>
45 </dependency>
46
47 <dependency>
48 <groupId>org.slf4j</groupId>
49 <artifactId>slf4j-api</artifactId>
50 <version>1.7.0</version>
51 </dependency>
52 </dependencies>
53 <build>
54 <finalName>simpleSoapWeb</finalName>
55 </build>
56 </project>
57

Step 3: Web service interface with JAX-WS annotations


Folder: src/main/java

package com.mytutorial;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface SimpleSoapWeb {
@WebMethod
public String sayHello(String name);
}
1 package com.mytutorial;
2
3 import javax.jws.WebMethod;
4 import javax.jws.WebService;
5
6 @WebService
7 public interface SimpleSoapWeb {
8
9 @WebMethod
10 public String sayHello(String name);
11 }

Step 4: Implementation of Web service interface


package com.mytutorial;
import javax.jws.WebService;
@WebService(endpointInterface = "com.mytutorial.SimpleSoapWeb",
serviceName="simpleSoapService")
public class SimpleSoapWebImpl implements SimpleSoapWeb {
public String sayHello(String name) {
String result = "Hello " + name;
return result;
}
}
1 package com.mytutorial;
2
3 import javax.jws.WebService;
4
5 @WebService(endpointInterface = "com.mytutorial.SimpleSoapWeb", serviceName="simpleSoapS
6 public class SimpleSoapWebImpl implements SimpleSoapWeb {
7
8 public String sayHello(String name) {
9 String result = "Hello " + name;
10 return result;
11 }
12 }
13

Step 5: Spring XML config as IoC.


Folder: src/main/resources/com/mytutorial

<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:endpoint id="simpleSoapService"
implementor="com.mytutorial.SimpleSoapWebImpl" address="/simpleSoapService"
/>
</beans>
1 <?xml version="1.0" encoding="UTF-8"?>
2 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/
3 xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
4 xsi:schemaLocation="http://www.springframework.org/schema/beans
5 http://www.springframework.org/schema/beans/spring-beans.xsd
6 http://cxf.apache.org/jaxrs
7 http://cxf.apache.org/schemas/jaxrs.xsd
8 http://cxf.apache.org/jaxws
9 http://cxf.apache.org/schemas/jaxws.xsd">
10
11 <jaxws:endpoint id="simpleSoapService" implementor="com.mytutorial.SimpleSoapWebImpl" ad
12
13 </beans>

Note down the “address”.


Step 6: web.xml deployment descriptor
to bootstrap Spring and initialize servlet, mapping, etc. Folder:
src/main/webapp/WEB-INF.

<!DOCTYPE web-app PUBLIC


"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/com/mytutorial/applicationContext.xml</param-
value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
1 <!DOCTYPE web-app PUBLIC
2 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3 "http://java.sun.com/dtd/web-app_2_3.dtd" >
4
5 <web-app>
6 <display-name>Archetype Created Web Application</display-name>
7
8 <context-param>
9 <param-name>contextConfigLocation</param-name>
10 <param-value>classpath:/com/mytutorial/applicationContext.xml</param-value>
11 </context-param>
12 <listener>
13 <listener-class>
14 org.springframework.web.context.ContextLoaderListener
15 </listener-class>
16 </listener>
17
18 <servlet>
19 <servlet-name>CXFServlet</servlet-name>
20 <display-name>CXF Servlet</display-name>
21 <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
22 <load-on-startup>2</load-on-startup>
23 </servlet>
24
25 <servlet-mapping>
26 <servlet-name>CXFServlet</servlet-name>
27 <url-pattern>/*</url-pattern>
28 </servlet-mapping>
29 </web-app>
30
31

Build the war and deploy to say JBoss application server.


Step 6: JBoss deployment descriptor
Folder: src/main/webapp/WEB-INF/jboss-web.xml

<jboss-web>
<context-root>tutorial</context-root>
</jboss-web>
1 <jboss-web>
2 <context-root>tutorial</context-root>
3 </jboss-web>
4

The URL = http://localhost:8080/tutorial/


tutorial: defined in jboss-web.xml (application context)

JAX-WS Web Services listings on the browser


To get the WSDL
URL: http://localhost:8180/tutorial/simpleSoapService?wsdl

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions


xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://mytutorial.com/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="simpleSoapService"
targetNamespace="http://mytutorial.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://mytutorial.com/" elementFormDefault="unqualified"
targetNamespace="http://mytutorial.com/" version="1.0">
<xs:element name="sayHello" type="tns:sayHello"/>
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
<xs:complexType name="sayHello">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="SimpleSoapWeb">
<wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello">
</wsdl:input>
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="simpleSoapServiceSoapBinding" type="tns:SimpleSoapWeb">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="simpleSoapService">
<wsdl:port binding="tns:simpleSoapServiceSoapBinding"
name="SimpleSoapWebImplPort">
<soap:address location="http://localhost:8180/tutorial/simpleSoapService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
1 <
2 ?
3 x
4 m
5 l
6
7 v
8 e
9 r
10 s
11 i
12 o
13 n
14 =
15 '
16 1
17 .
18 0
19 '
20
21 e
22 n
23 c
24 o
25 d
26 i
27 n
28 g
29 =
30 '
31 U
32 T
33 F
34 -
35 8
36 '
37 ?
38 >
39 <
40 w
41 s
42 d
43 l
44 :
45 d
46 e
47 f
48 i
49 n
50 i
51 t
52 i
53 o
54 n
55 s
56
x
m
l
n
s
:
x
s
d
=
"
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
1
/
X
M
L
S
c
h
e
m
a
"

x
m
l
n
s
:
w
s
d
l
=
"
h
t
t
p
:
/
/
s
c
h
e
m
a
s
.
x
m
l
s
o
a
p
.
o
r
g
/
w
s
d
l
/
"

x
m
l
n
s
:
t
n
s
=
"
h
t
t
p
:
/
/
m
y
t
u
t
o
r
i
a
l
.
c
o
m
/
"

x
m
l
n
s
:
s
o
a
p
=
"
h
t
t
p
:
/
/
s
c
h
e
m
a
s
.
x
m
l
s
o
a
p
.
o
r
g
/
w
s
d
l
/
s
o
a
p
/
"

x
m
l
n
s
:
n
s
1
=
"
h
t
t
p
:
/
/
s
c
h
e
m
a
s
.
x
m
l
s
o
a
p
.
o
r
g
/
s
o
a
p
/
h
t
t
p
"

n
a
m
e
=
"
s
i
m
p
l
e
S
o
a
p
S
e
r
v
i
c
e
"

t
a
r
g
e
t
N
a
m
e
s
p
a
c
e
=
"
h
t
t
p
:
/
/
m
y
t
u
t
o
r
i
a
l
.
c
o
m
/
"
>

<
w
s
d
l
:
t
y
p
e
s
>
<
x
s
:
s
c
h
e
m
a

x
m
l
n
s
:
x
s
=
"
h
t
t
p
:
/
/
w
w
w
.
w
3
.
o
r
g
/
2
0
0
1
/
X
M
L
S
c
h
e
m
a
"

x
m
l
n
s
:
t
n
s
=
"
h
t
t
p
:
/
/
m
y
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u
t
o
r
i
a
l
/
s
i
m
p
l
e
S
o
a
p
S
e
r
v
i
c
e
"
/
>
<
/
w
s
d
l
:
p
o
r
t
>

<
/
w
s
d
l
:
s
e
r
v
i
c
e
>
<
/
w
s
d
l
:
d
e
f
i
n
i
t
i
o
n
s
>

WSDL structure

WSDL structure
Project Structure
Maven Project Structure
Deployable WAR file Structure

Deployable war file


http://www.dineshonjava.com/2014/12/rest-and-soap-web-service-
interview.html#.Vylf74R_glY

REST and SOAP Web Service Interview Questions


Posted by Dinesh Rajput
In this interview questions tutorial we will explain most asking interviews questions
on the web services like SOAP, REST etc and its protocol support. REST is getting
popular day by day and replacing SOAP web services which was standard earlier and
Interviewer expect you to know about REST and how it work.

Define Web Service?


A web service is a kind of software that is accessible on the Internet. It makes use of
the XML messaging system and offers an easy to understand, interface for the end
users.

What is REST and RESTful web services ?


REST stands for REpresentational State Transfer (REST) its a relatively new concept
of writing web services which enforces a stateless client server design where web
services are treated as resource and can be accessed and identified by there URL
unlike SOAP web services which were defined by WSDL.

Web services written by apply REST Architectural concept are called RESTful web
services which focus on System resources and how state of Resource should be
transferred over http protocol to a different clients written in different languages. In
RESTful web services http methods like GET, PUT, POST and DELETE can can be used
to perform CRUD operations.

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:

1) REST is more simple and easy to use than 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.
5) REST web services call can be cached to improve performance.

What is Restlet framework ?


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.

What is Resource in REST framework ?


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.

Can you use Restlet without any web-container ?


Yes, Restlet framework provide default server which can be used to handle service
request in web container is not available.

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.

How to display custom error pages using RestFull web services ?


In order to customize error you need to extend StatusService and implement
getRepresentation(Status, Request, Response) method with your custom code now
assign instance of your CustomStatusService to appropriate "statusService
property".

Which HTTP methods are supported by RestFull web 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.

What is difference between top-down and bottom-up approach of developing web


services ?
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.

Define SOAP?
SOAP is an XML based protocol to transfer between computers.

Define WSDL?
It means Web Services Description Language. It is basically the service description
layer in the web service protocol stock. The Service Description layer describes the
user interface to a web service.
Differentiate between a SOA and a Web service?
SOA is a design and architecture to implement other services. SOA can be easily
implemented using various protocols such as HTTP, HTTPS, JMS, SMTP, RMI, IIOP,
RPC etc. While Web service, itself is an implemented technology. In fact one can
implement SOA using the web service.

Discuss various approaches to develop SOAP based web service?


We can develop SOAP based web service with two different types of approaches
such as contract-first and contract-last. In the first approach, the contract is defined
first and then the classes are derived from the contract while in the later one, the
classes are defined first and then the contract is derived from these classes.

If you have to choose one approach, then what will be your choice?
In my point of view, the first approach that is the contract-first approach is more
feasible as compared to the second one but still it depends on other factors too.

What are the types of information included in SOAP header?


Header of SOAP contains information like that,
1. In SOAP header client should handle authentication and transaction.
2. The SOAP message should process by client.
3. EncodingStyle is also has in header.

What are the disadvantages of SOAP?


Some disadvantages .
1. It is much slower than middleware technologies.
2. Because we used HTTP for transporting messages and not use to defined ESB or
WS-Addressing interaction of parties over a message is fixed.
3. Application protocol level is problematic because usability of HTTP for different
purposes is not present.

http://www.tutorialspoint.com/webservices/webservices_interview_questions.htm

What are web services?


Web services are open standard (XML, SOAP, HTTP etc.) based Web applications that
interact with other web applications for the purpose of exchanging data. Web
Services can convert your existing applications into Web-applications.
What are the features of web services?
Following are the features of Web service −
It is available over the Internet or private (intranet) networks.
It uses a standardized XML messaging system.
It is not tied to any one operating system or programming language.
It is self-describing via a common XML grammar.
It is discoverable via a simple find mechanism.
What the components of a Web Service?
The basic web services platform is XML + HTTP. All the standard web services work
using the following components −
SOAP (Simple Object Access Protocol)
UDDI (Universal Description, Discovery and Integration)
WSDL (Web Services Description Language)
How Does a Web Service Work?
A web service enables communication among various applications by using open
standards such as HTML, XML, WSDL, and SOAP.
You can build a Java-based web service on Solaris that is accessible from your Visual
Basic program that runs on Windows.
You can also use C# to build new web services on Windows that can be invoked from
your web application that is based on JavaServer Pages (JSP) and runs on Linux.
What is the purpose of XML in a web service?
A web services takes the help of XML to tag the data, format the data.
What is the purpose of SOAP in a web service?
A web service takes the help of SOAP to transfer a message.
What is the purpose of WSDL in a web service?
A web service takes the help of WSDL to describe the availability of service.
What are the benefits of Web Services?
Following are the benefits of using web services −
Exposing the Existing Function on the network − Web services allows you to
expose the functionality of your existing code over the network. Once it is
exposed on the network, other application can use the functionality of your
program.
Interoperability − Web services allow various applications to talk to each other
and share data and services among themselves.
Standardized Protocol − Web services use standardized industry standard
protocol for the communication. All the four layers (Service Transport, XML
Messaging, Service Description, and Service Discovery layers) use well-
defined protocols in the web services protocol stack.
Low Cost of Communication − Web services use SOAP over HTTP protocol, so you
can use your existing low-cost internet for implementing web services.
What do you mean by Interoperability of Web Services?
Web services allow various applications to talk to 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 talk to Java web services and vice versa. Web
services are used to make the application platform and technology independent.
What do you mean by loosely coupled architecture of Web services?
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 allows simpler integration between different systems.
Do Web services supports Remote Procedure Calls(RPCs)?
Web services allow clients to invoke procedures, functions, and methods on remote
objects using an XML-based protocol. Remote procedures expose input and output
parameters that a web service must support.
Component development through Enterprise JavaBeans (EJBs) and .NET Components
has increasingly become a part of architectures and enterprise deployments over the
past couple of years. Both technologies are distributed and accessible through a
variety of RPC mechanisms.
A web service supports RPC by providing services of its own, equivalent to those of a
traditional component, or by translating incoming invocations into an invocation of
an EJB or a .NET component.
What are the behavioral characteristics of web services?
Web services have the following special behavioral characteristics −
XML-Based − Web Services uses XML at data representation and data
transportation layers.
Loosely Coupled − A consumer of a web service is not tied to that web service
directly.
Coarse-Grained − Businesses and the interfaces that they expose should be
coarse-grained. Web services technology provides a natural way of defining
coarse-grained services that access the right amount of business logic.
Ability to be Synchronous or Asynchronous − Asynchronous clients retrieve their
result at a later point in time, while synchronous clients receive their result
when the service has completed. Asynchronous capability is a key factor in
enabling loosely coupled systems.
Supports Remote Procedure Calls(RPCs) − A web service supports RPC by
providing services of its own, equivalent to those of a traditional component,
or by translating incoming invocations into an invocation of an EJB or a .NET
component.
Supports Document Exchange − Web services support the transparent exchange
of documents to facilitate business integration.
What are the benefits of having XML based WEB services?
Using XML eliminates any networking, operating system, or platform binding. So
Web Services based applications are highly interoperable application at their core
level.
What is the benefit of a Web services being loosely coupled?
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 allows simpler integration between
different systems.
What is Synchronicity?
Synchronicity refers to the binding of 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. Asynchronous operations allow a client to invoke a
service and then execute other functions.
What are the core Roles in Web Service architecture?
There are three major roles within the web service architecture −
Service Provider
Service Requestor
Service Registry
What is the purpose of Service Provider in Web Service architecture?
This is the provider of the web service. The service provider implements the service
and makes it available on the Internet.
What is the purpose of Service Requestor in Web Service architecture?
This is any consumer of the web service. The requestor utilizes an existing web
service by opening a network connection and sending an XML request.
What is the purpose of Service Registry in Web Service architecture?
This is a logically centralized directory of services. The registry provides a central
place where developers can publish new services or find existing ones. It therefore
serves as a centralized clearing house for companies and their services.
What are the core layers in Web Service Protocol Stack?
The Web Service Protocol Stack is still evolving, but currently has four main layers −
Service Transport
XML Messaging
Service Description
Service Discovery
What is the purpose of Service Transport layer in Web Service Protocol Stack?
This layer is responsible for transporting messages between applications. Currently,
this layer includes Hyper Text Transport Protocol (HTTP), Simple Mail Transfer
Protocol (SMTP), File Transfer Protocol (FTP), and newer protocols such as Blocks
Extensible Exchange Protocol (BEEP).
What is the purpose of XML Messaging layer in Web Service Protocol Stack?
This layer is responsible for encoding messages in a common XML format so that
messages can be understood at either end. Currently, this layer includes XML-RPC
and SOAP.
What is the purpose of Service Description layer in Web Service Protocol Stack?
A. This layer is responsible for describing the public interface to a specific web
service. Currently, service description is handled via the Web Service Description
Language (WSDL).
What is the purpose of Service Discovery layer in Web Service Protocol Stack?
This layer is responsible 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).
What HTTP stands for?
HTTP stands for Hyper Text Transfer Protocol.
What is HTTP?
Currently, HTTP is the most popular option for service transport. HTTP is simple,
stable, and widely deployed. Furthermore, most firewalls allow HTTP traffic. This
allows XML-RPC or SOAP messages to masquerade as HTTP messages.
What BEEP stands for?
BEEP stands for Blocks Extensible Exchange Protocol.
What is BEEP?
This is a promising alternative to HTTP. BEEP is a new Internet Engineering Task
Force (IETF) framework for building new protocols. BEEP is layered directly on TCP
and includes a number of built-in features, including an initial handshake protocol,
authentication, security, and error handling. Using BEEP, one can create new
protocols for a variety of applications, including instant messaging, file transfer,
content syndication, and network management.
What is XML-RPC?
XML-RPC is a simple protocol that uses XML messages to perform RPCs.
How request is sent in XML-RPC?
Requests are encoded in XML and sent via HTTP POST.
How response is sent in XML-RPC?
XML responses are embedded in the body of the HTTP response.
What are the features of XML-RPC?
Following are the features of XML-RPC −
XML-RPC is a simple protocol that uses XML messages to perform RPCs.
Requests are encoded in XML and sent via HTTP POST.
XML responses are embedded in the body of the HTTP response.
XML-RPC is platform-independent.
XML-RPC allows diverse applications to communicate.
A Java client can speak XML-RPC to a Perl server.
XML-RPC is the easiest way to get started with web services.
What SOAP stands for?
SOAP stands for Simple Access Object Protocol.
What is SOAP?
SOAP is an XML-based protocol for exchanging information between computers.
What are the features of SOAP?
Following are the features of SOAP −
SOAP is a communication protocol.
SOAP is for communication between applications.
SOAP is a format for sending messages.
SOAP is designed to communicate via Internet.
SOAP is platform independent.
SOAP is language independent.
SOAP is simple and extensible.
SOAP allows you to get around firewalls.
SOAP will be developed as a W3C standard.
Is SOAP platform independent?
Yes!
What WSDL stands for?
WSDL stands for Web Services Description Language.
What is WSDL?
WSDL is an XML-based language for describing web services and how to access
them.
What are the features of WSDL?
Following are the features of WSDL −
WSDL was developed jointly by Microsoft and IBM.
WSDL is an XML based protocol for information exchange in decentralized and
distributed environments.
WSDL is the standard format for describing a web service.
WSDL definition describes how to access a web service and what operations it will
perform.
WSDL is a language for describing how to interface with XML-based services.
WSDL is an integral part of UDDI, an XML-based worldwide business registry.
WSDL is the language that UDDI uses.
WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'.
What UDDI stands for?
UDDI stands for Universal Description, Discovery, and Integration.
What is UDDI?
UDDI is an XML-based standard for describing, publishing, and finding web services.
What are the features of UDDI?
Following are the features of UDDI −
UDDI is a specification for a distributed registry of web services.
UDDI is platform independent, open framework.
UDDI can communicate via SOAP, CORBA, and Java RMI Protocol.
UDDI uses WSDL to describe interfaces to web services.
UDDI is seen with SOAP and WSDL as one of the three foundation standards of
web services.
UDDI is an open industry initiative enabling businesses to discover each other and
define how they interact over the Internet.
What are the primary security issues with web services?
There are three specific security issues with web services −
Confidentiality
Authentication
Network Security
Which component of Web service describes interfaces to web services?
UDDI describes interfaces to web services.
Which language UDDI uses?
WSDL is the language that UDDI uses.
Is XML-RPC is platform-dependent?
No! XML-RPC is platform-independent.
If a client sends an XML request to a server, can we ensure that the communication
remains confidential?
Yes! As XML-RPC and SOAP run primarily on top of HTTP and HTTP has support for
Secure Socketes Layer (SSL). Communication can be encrypted via SSL.
If a client connects to a web service, how do we identify the user? Is the user
authorized to use the service?
The following options can be considered but there is no clear consensus on a strong
authentication scheme.
HTTP includes built-in support for Basic and Digest authentication, and services can
therefore be protected in much the same manner as HTML documents are currently
protected.
SOAP Digital Signature (SOAP-DSIG) leverages public key cryptography to digitally
sign SOAP messages. It enables the client or server to validate the identity of the
other party. Check it at http://www.w3.org/TR/SOAP-dsig.
The Organization for the Advancement of Structured Information Standards (OASIS)
is working on the Security Assertion Markup Language (SAML).
What do you mean by Web services manageability?
Web services manageability is defined as a set of capabilities for discovering the
existence, availability, health, performance, usage, as well as the control and
configuration of a web service within the web services architecture. As web services
become pervasive and critical to business operations, the task of managing and
implementing them is imperative to the success of business operations.
How to handle Network security threats in Web services?
There are two possible solutions −
Filter out all HTTP POST requests that set their content type to text/xml.
Another alternative is to filter the SOAPAction HTTP header attribute.

http://www.javatpoint.com/web-services-interview-questions

Web Services Interview Questions

There is given frequently asked Web Services interview questions and answers that has
been asked in many companies. Let's see the list of top Web Services interview questions.

1) What is Web Service?

Web Service is a software system for communicating two devices over the network. More
details...

2) What are the advantages of web services?

Interoperability: By the help of web services, an application can communicate with other
application developed in any language.
Reuability: We can expose the web service so that other applications can use it.
Modularity: By the help of web service, we can create a service for a specific task such as tax
calculation etc.
More details...
3) What are the different types of web services?

There are two types of web services:

SOAP
RESTful
4) What is SOAP?

SOAP stands for Simple Object Access Protocol. It is a XML-based protocol for accessing web
services. More details...

5) What are the advantages of SOAP web services?

WS Security
Language Independent
Platform Independent
More details...
6) What are the disadvantages of SOAP web services?
Slow
WSDL Dependent
More details...
7) 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...

8) 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...

9) What is RESTful web services?

REST stands for REpresentational State Transfer. It is a architectural style. It is not a protocol
like SOAP. More details...

10) What are the advantages of RESTful web services?

Fast
Language Independent
Platform Independent
Can use SOAP.
Allows different data format.
More details...
11) What is the difference between SOAP and REST web services?

No. SOAP REST


1) SOAP is a protocol. REST is an architectural style.
2) SOAP stands for Simple Object Access Protocol. REST stands for REpresentational
State Transfer.
3) SOAP can't use REST because it is a protocol. REST can use SOAP web services
because it is a concept and can use any protocol like HTTP, SOAP.
4) SOAP uses services interfaces to expose the business logic. REST uses URI to expose
business logic.
5) SOAP defines standards to be strictly followed. REST does not define too much
standards like SOAP.
6) SOAP permits XML data format only. REST permits different data format such as Plain
text, HTML, XML, JSON etc.
More details...
12) What is SOA?

SOA stands for Service Oriented Architecture. It is a design pattern to provide services to
other application through protocol. More details...
13) What tools are used to test web services?

SoapUI tool for testing SOAP and RESTful web services


Poster for firefox browser
Postman extension for Chrome

http://career.guru99.com/top-50-web-services-interview-questions/

1) Define Web Service?


A web service is a kind of software that is accessible on the Internet. It makes use of
the XML messaging system and offers an easy to understand, interface for the end
users.

2) What is new in this field for past few years?


The initiation of XML in this field is the advancement that provides web service a
single language to communicate in between the RPCs, web services and their
directories.
3) Give me an example of real web service?
One example of web services is IBM Web Services browser. You can get it from IBM
Alphaworks site. This browser shows various demos related to web services.
Basically web services can be used with the help of SOAP, WSDL, and UDDI . All
these, provide a plug-and-play interface for using web services such as stock-quote
service, a traffic-report service, weather service etc.
4) How you define web service protocol stack?
It is basically set of various protocols that can be used to explore and execute web
services. The entire stack has four layers i.e. Service Transport, XML Messaging,
Service Description and Service Discovery.
5) Can you define each of these layers of protocol stack?
The Service Transport layer transfer messages between different applications, such
as HTTP, SMTP, FTP, and Blocks Extensible Exchange Protocol (BEEP). The XML
Messaging layer encodes messages in XML format so that messages can be
understood at each end, such as XML-RPC and SOAP. The Service Description layer
describes the user interface to a web service, such as WSDL. The Service Discovery
layer centralizes services to a common registry and offer simple publish
functionality, such as UDDI.
6) Define XML – RPC?
It is a protocol that makes use of XML messages to do Remote Procedure Calls.
7) Define SOAP?
SOAP is an XML based protocol to transfer between computers.
8) Define WSDL?
It means Web Services Description Language. It is basically the service description
layer in the web service protocol stock. The Service Description layer describes the
user interface to a web service.
9) What kind of security is needed for web services?

The security level for web services should be more than that of what we say Secure
Socket Layer (SSL). This level of security can be only achieved from Entrust Secure
Transaction Platform. Web services need this level of security to ensure reliable
transactions and secure confidential information .
10) Do you have any idea about foundation security services?
As implies from its name, these services are the foundation or basics of integration,
authentication, authorization, digital signatures and encryption processes.
11) Define Entrust Identification Service?
Entrust Identification Service comes from the Entrust Security Transaction Platform.
This platform allows companies to control the identities that are trusted to perform
transactions for Web services transactions.
12) What UDDI means?
UDDI stands for Universal, Description, Discovery, and Integration. It is the discovery
layer in the web services protocol stack.
13) Define Entrust Entitlements Service?
This service verifies entities that attempt to access a web service. For Example, the
authentication service, the Entitlements Service ensures security in business
operations.
14) Define Entrust Privacy Service?
As its name implies, it deals with security and confidentiality. This service encrypts
data to ensure that only concerned parties can access the data.
15) What do you mean by PKI?
It means Public-Key Infrastructure.
16) What tools are used to test a web service?
I have used SoapUI for SOAP WS and Firefox poster plugin for RESTFul Services.
17) Differentiate between a SOA and a Web service?
SOA is a design and architecture to implement other services. SOA can be easily
implemented using various protocols such as HTTP, HTTPS, JMS, SMTP, RMI, IIOP,
RPC etc. While Web service, itself is an implemented technology. In fact one can
implement SOA using the web service.
18) Discuss various approaches to develop SOAP based web service?
We can develop SOAP based web service with two different types of approaches
such as contract-first and contract-last. In the first approach, the contract is defined
first and then the classes are derived from the contract while in the later one, the
classes are defined first and then the contract is derived from these classes.
19) If you have to choose one approach, then what will be your choice?
In my point of view, the first approach that is the contract-first approach is more
feasible as compared to the second one but still it depends on other factors too.
20) Is there any special application required to access web service?
No, you don’t need to install any special application to access web service. You can
access web service from any application that supports XML based object request and
response.
21) Can you name few free and commercial implementations for web services?
The implementations I know are Apache SOAP, JAX-WS Reference Implementation,
JAX-RS Reference Implementation, Metro, Apache CXF, MS.NET and Java 6.
22) Name browser that allows access to web service?
JavaScript XmlHttpRequest object is required to access web service via browsers.
The browsers that support this object are Internet Explorer, Safari and Mozilla-based
browsers like FireFox.
23) What is REST?
REST stands for Representational State Transfer. REST itself is not a standard, while it
uses various standards such as HTTP, URL, XML/HTML/GIF/JPEG (Resource
Representations) and text/xml, text/html, image/gif, image/jpeg, etc (MIME Types).
24) How one can provide API to users?
To provide an API to the users, one can easily do this with an “open table”. All you
need to do is to write open table which is basically an XML schema that point to a
web service.
25) Name the various communication channels in web service?
Web service is integrated with three protocols such as HTTP/POST, HTTP/GET, and
SOAP. It provides three different communication channels to clients. Client can
choose any communication method as per requirements.

26) How can you document web service?


Web services are contemplated as self-documenting because they provide entire
information regarding the available methods and parameters used for XML based
standard, known as WSDL. One can also provide more information to explain web
services via their own WebService and WebMethod attributes.
27) What are the situations, when we need ASP.NET web services?
ASP.NET web services are used when one need to implement three tier architecture
in a web service. It allows handy ways to use middle tier components through
internet. The main advantage of .NET Web services is that they are capable enough
to communicate across firewalls because they use SOAP as transport protocol.
28) What are distributed technologies?
The increasing ratio of distributed applications has raised demand for distributed
technologies. It allows segmenting of application units and transferring them to
different computers on different networks.
29) Differentiate between web services, CORBA and DCOM?
Web services transfer/receive messages to/from application respectively, via HTTP
protocol. It uses XML to encode data.
CORBA and DCOM transfer/receive messages to/from application respectively, via
non-standard protocols such as IIOP and RPC.
30) Can you tell few benefits of web services?
The biggest advantage of web service is that is supported by wide variety of
platforms. Moreover, in near future, web services may spread its boundary and
enhance new methods that will provide ease to clients. The enhancement will not
affect the clients, even if they offer old methods and parameters.
31) Can you name some standards used in web services?
The standards used in web services are WSDL (used to create interface definition),
SOAP (used to structure data), HTTP (communication channels), DISCO (used to
create discovery documents) and UDDI (used to create business registries).
32) Explain in brief, what DISCO is?
DISCO means discovery. It groups the list of interrelated web services. The
organization that provides web services, issues a DISCO file on its server and that file
contains the links of all the provided web services. This standard is good when client
knows the company already. Also it can be used within a local network as well.
33) Explain in brief, what UDDI is?
UDDI (Universal Description, Discovery, and Integration) provides consolidated
directory for web services on the internet. Clients use UDDI to find web services as
per their business needs. It basically hosts the web services from various companies.
In order to share web services, you need to publish it in UDDI.
34) Explain the .NET web services supported data types?
.Net web services uses XML-based standards to transfer/receive information. Thus,
.NET web services can only works with data types known by XML schema standard.
Like FileSteam, Eventlog etc. are not recognized by the XML schema standards and
hence, not supported in web services.
35) How a .NET web service is tested?
ASP.NET uses a test page routinely, when one calls for the URL of .asmx file in any
browser. This page shows complete information regarding web services.
36) How a .NET web service is consumed?
Since we know that web services are constructed on XML standards. Therefore,
clients need to have complete understanding of XML-based messages to interchange
messages. Clients can communicate with web services through .NET framework that
offers proxy mechanisms. These proxy mechanisms have detailed information
regarding data sharing within web services that can be easily used by the clients.
37) Can you name the two Microsoft solutions for distributed applications?
The two Microsoft solutions for distributed applications are .NET Web Services and
.NET Remoting.
38) Differentiate between .NET Web Services and .NET Remoting?
As far as protocol is concerned, .NET Web Service uses HTTP, while, .NET Remoting
uses any protocol i.e. TCP/HTTP/SMTP. When it comes to performance, .NET
Remoting is comparatively, faster than.NET Web Service. Also, as .NET Web Services
are hosted via IIS, therefore, it is far more reliable than the .NET Remoting.
39) Name the components to be published while deploying a Web Service?
The components that need to be published during a web service deployment are
Web Application Directory, Webservice.asmx File, Webservice.Disco File, Web.Config
File and Bin Directory.
40) What are the steps performed by the client to access a web service?
First of all a web reference to the web service is created by the client in his
application. Then a proxy class is generated. After that an object of the proxy class is
created and at last, the web service is accessed via that proxy object.
41) How web services are implemented in .NET?
To implement web services in .NET, HTTP handlers are used that interrupt requests
to .asmx files.
42) Explain few disadvantages of Response Caching?
Response Caching is useless or incompetent when method accepts extensive amount
of values because caching means to store lot of information. Also, if the method
depends on external source of information, and that are not provided within the
parameters then such methods are bypassed.
43) What is the alternate solution to Response Caching?
One can use Data Caching (System.Web.Caching.Cach) instead of Response Caching.
44) Brief few drawbacks of using GET and POST methods to communicate with the
web service?
These methods are less secure and inhibit users to pass structures and objects as
arguments. Also, it doesn’t allow users to pass ByRef arguments.
45) How can one access a class as a web service?
To access a class as a web service, one should inherit the class from the
System.Web.Services.WebService class and qualify the class with the WebService
attribute.
46) How can one access the web service class method via internet?
To access web service class method via internet, one should qualify a method with
the WebMethod attribute.
47) How a SOAP message is structured?
A SOAP message is consists of SOAP Envelope, SOAP Headers, and SOAP Body.
48) Can you name different kinds of web services?
There are two types of web services in total i.e. SOAP based web service and RESTful
web service.
This question is already mentioned earlier.
49) What’s different in RESTful web services?
The RESTful web services contains no contract or WSDL file.
50) Give me few reasons to use RESTful web service?
The RESTFul web services are simple to implement and test. It supports various data
formats such as XML, JSON etc.

http://www.careerride.com/Interview-Questions-Java-Web-services.aspx

Explain each web service technologies - SOAP, WSDL, UDDI, eBXML and JAX pack
Web service technologies - SOAP, WSDL, UDDI, eBXML and JAX pack - SOAP: Simple Object Access Proto
protocol that is used to exchange structured information at the time of implementing a web service....
Technologies included within JAX pack, i.e. JAXP, JAXB, JAXM, JAX-RPC, JAXR
JAX pack technologies - JAXP: Java API for xml processing. It provides the validation capability and parsin
documents...
Explain the web services architecture
Web services architecture - The operations between different software applications, which are running o
variety of platforms and frameworks are supported by a standard called Web services....
What are smart web services?
What are smart web services? - A smart web service understands the situational context and capable of
the context with other services....
Java Web Services: What is Web Services
Web Services are the components that provide functionality via internet, uses standard protocol..
Java Web Service: What is SOAP?
SOAP is an XML-based protocol that enables 2 components to communicate each other..
Explain JAXR
JARX is a standard API that are used to access XML registries (list of services available on the web) from t
platform..
Explain JAX-RPC.
JAX-RPC uses SOAP to call remote procedures. JAX-RPC...
What are Web Services?
What are Web Services? - Web services exposes functionality over internet using protocol such as HTTP.
Web Services: Define UDDI, DISCO and WSDL.
UDDI, Universal description, discovery and integration,DISCO, Discovery,WSDL, Web Service description
language....
Explain JAXM messaging models.
JAXM messaging models has two types of messaging model, synchronous and asynchronous..

http://www.journaldev.com/9193/web-services-interview-questions-soap-and-rest

What is a Web Service?
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.

What are the advantages of Web Services?
Some of the advantages of web services are:
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.
Easy to deploy and integrate, just like web applications.
Multiple service versions can be running at same time.

What are different types of Web Services?
There are two types of web services:
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.

What are advantages of SOAP Web Services?
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.

What are disadvantages of SOAP Web Services?
Some of the disadvantages of


SOAP protocol are:
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

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.

What are different components of WSDL?
Some of the different tags in WSDL xml
are:
xsd:import namespace and schemaLocation: provides WSDL URL and
unique namespace for web service.
message: for method arguments
part: for method argument name and type
portType: service name, there can be multiple services in a wsdl document.
operation: contains method name
soap:address for endpoint URL.

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.

What is difference between Top Down and Bottom Up approach in SOAP Web
Services?
In Top Down approach first WSDL document is created to establish
the contract between web service and client and then code is written, it’s
also termed as contract first approach. This is hard to implement because
classes need to be written to confirm the contract established in WSDL.
Benefit of this approach is that both client and server code can be written in
parallel.
In Bottom Up approach, first web service code is written and then
WSDL is generated. It’s also termed as contract last approach. This approach
is easy to implement because WSDL is generated based on code. In this
approach client code have to wait for WSDL from server side to start their
work.

What is REST Web Services?
REST is the acronym for REpresentational State


Transfer. REST is an architectural style for developing applications that can be
accessed over the network. REST architectural style was brought in light by
Roy Fielding in his doctoral thesis in 2000.
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. REST doesn’t specify any specific protocol to use, but in almost
all cases it’s used over HTTP/HTTPS. When compared to SOAP web services,
these are lightweight and doesn’t follow any standard. We can use XML,
JSON, text or any other type of data for request and response.

What are advantages of REST web services?
Some of the advantages of REST web
services are:
Learning curve is easy since it works on HTTP protocol
Supports multiple technologies for data transfer such as text, xml, json,
image etc.
No contract defined between server and client, so loosely coupled
implementation.
REST is a lightweight protocol
REST methods can be tested easily over browser.

What are disadvantages of REST web services?
Some of the disadvantages of REST


are:
Since there is no contract defined between service and client, it has to be
communicated through other means such as documentation or
emails.
Since it works on HTTP, there can’t be asynchronous calls.
Sessions can’t be maintained.

What is a Resource in Restful web services?
Resource is the fundamental concept


of Restful architecture. A resource is an object with a type, relationship with
other resources and methods that operate on it. Resources are identified
with their URI, HTTP methods they support and request/response data type
and format of data.

What are different HTTP Methods supported in Restful Web Services?
Restful


web services supported HTTP methods are – GET, POST, PUT, DELETE and
HEAD.

Compare SOAP and REST web services?


SOAP
SOAP is a standard protocol for creating web services. REST is an architectural
SOAP is acronym for Simple Object Access Protocol. REST is acronym for REp
SOAP uses WSDL to expose supported methods and technical REST exposes methods thro
details.
SOAP web services and client programs are bind with WSDL REST doesn’t have any contrac
contract
SOAP web services and client are tightly coupled with contract. REST web service
SOAP learning curve is hard, requires us to learn about WSDL REST learning curve is simple, P
generation, client stubs creation etc. and works on
SOAP supports XML data format only REST supports any data typ
SOAP web services are hard to maintain, any change in WSDL REST web services are easy to m
contract requires us to create client stubs again and then new method can be adde
make changes to client code. for ex
SOAP web services can be tested through programs or software REST can be easily tested thro
such as Soap UI. extensions su

What are different ways to test web services?
SOAP web services can be tested
programmatically by generating client stubs from WSDL or through software
such as Soap UI.
REST web services can be tested easily with program, curl
commands and through browser extensions. Resources supporting GET
method can be tested with browser itself, without any program.

Can we maintain user session in web services?
Web services are stateless so we


can’t maintain user sessions in web services.

What is difference between SOA and Web Services?
Service Oriented Architecture


(SOA) is an architectural pattern where applications are designed in terms of
services that can be accessed through communication protocol over network.
SOA is a design pattern and doesn’t go into implementation.
Web Services
can be thought of as Services in SOAP architecture and providing means to
implement SOA pattern.

What is the use of Accept and Content-Type Headers in HTTP Request?
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 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.

Quick Adsense WordPress Plugin: http://quicksense.net/
CM_JD_AP_Bottom_Responsive




















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:
Do you know your web service clients beforehand? If Yes, then you can
define a contract before implementation and SOAP seems better
choice. But if you don’t then REST seems better choice because you
can provide sample request/response and test cases easily for client
applications to use later on.
How much time you have? For quick implementation REST is the best
choice. You can create web service easily, test it through browser/curl
and get ready for your clients.
What kind of data format are supported? If only XML then you can go with
SOAP but if you think about supporting JSON also in future then go
with REST.

What is JAX-WS API?
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.

Name some frameworks in Java to implement SOAP web services?
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.

Name important annotations used in JAX-WS API?
Some of the important


annotations used in JAX-WS API are:
@WebService
@SOAPBinding
@WebMethod

What is use of javax.xml.ws.Endpoint class?
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.
What is the difference between RPC Style and Document Style SOAP web
Services?
RPC style generate WSDL document based on the method name
and it’s parameters. No type definitions are present in WSDL
document.
Document style contains type and can be validated against
predefined schema. Let’s look at these with a simple program. Below is a
simple test program where I am using Endpoint to publish my simple SOAP
web service.
TestService.java
1
2 package com.journaldev.jaxws.service;
 
import javax.jws.WebMethod;
import javax.jws.W

 javax.jws.soap.SOAPBinding;
import javax.xml.ws.Endpoint;
 
@WebService
@SOAPB
3 class TestService {
 
 @WebMethod
 public String sayHello(String msg){
 return

 main(String[] args){
 Endpoint.publish("http://localhost:8888/testWS", new TestSer
4

5

6

7

8

9

1
0

1
1

1
2

1
3

1
4

1
5

1
6

1
7

1
8

1
9

2
0


When I run above program and then access the WSDL, it gives me below XML.
rpc.xml
1
2 <

 ?
3 x

 m
4 l

5 v

 e
6 r

 s
7 i

 o
8 n

 =
9 '

 1
1 .
0 0

 '
1
1 e

 n
1 c
2 o

 d
1 i
3 n

 g
1 =
4 '

 U
1 T
5 F

 -
1 8
6 '

 ?
1 >
7 


 <
1 !
8 -

 -
1
9 P

 u
2 b
0 l

 i
2 s
1 h

 e
2 d
2

 b
2 y
3

 J
2 A
4 X

 -
2 W
5 S

2 R
6 I

2 (
7 h

 t
2 t
8 p

 :
2 /
9 /

 j
3 a
0 x

 -
3 w
1 s

 .
3 j
2 a

 v
3 a
3 .

 n
3 e
4 t
)
.

R
I
'
s

v
e
r
s
i
o
n

i
s

J
A
X
-
W
S

R
I

2
.
2
.
1
0

s
v
n
-
r
e
v
i
s
i
o
n
#
9
1
9
b
3
2
2
c
9
2
f
1
3
a
d
0
8
5
a
9
3
3
e
8
d
d
6
d
d
3
5
d
4
9
4
7
3
6
4
b
.

-
-
>
<
!
-
-

G
e
n
e
r
a
t
e
d

b
y

J
A
X
-
W
S

R
I

(
h
t
t
p
:
/
/
j
a
x
-
w
s
.
j
a
v
a
.
n
e
t
)
.

R
I
'
s

v
e
r
s
i
o
n

i
s

J
A
X
-
W
S

R
I

2
.
2
.
1
0
s
v
n
-
r
e
v
i
s
i
o
n
#
9
1
9
b
3
2
2
c
9
2
f
1
3
a
d
0
8
5
a
9
3
3
e
8
d
d
6
d
d
3
5
d
4
9
4
7
3
6
4
b
.

-
-
>

<
d
e
f
i
n
i
t
i
o
n
s

x
m
l
n
s
:
w
s
u
=
"
h
t
t
p
:
/
/
d
o
c
s
.
o
a
s
i
s
-
o
p
e
n
.
o
r
g
/
w
s
s
/
2
0
0
4
/
0
1
/
o
a
s
i
s
-
2
0
0
4
0
1
-
w
s
s
-
w
s
s
e
c
u
r
i
t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
r
p
c
"
/
>

<
o
p
e
r
a
t
i
o
n

n
a
m
e
=
"
s
a
y
H
e
l
l
o
"
>

<
s
o
a
p
:
o
p
e
r
a
t
i
o
n

s
o
a
p
A
c
t
i
o
n
=
"
"
/
>

<
i
n
p
u
t
>

<
s
o
a
p
:
b
o
d
y

u
s
e
=
"
l
i
t
e
r
a
l
"

n
a
m
e
s
p
a
c
e
=
"
h
t
t
p
:
/
/
s
e
r
v
i
c
e
.
j
a
x
w
s
.
j
o
u
r
n
a
l
d
e
v
.
c
o
m
/
"
/
>

<
/
i
n
p
u
t
>

<
o
u
t
p
u
t
>

<
s
o
a
p
:
b
o
d
y

u
s
e
=
"
l
i
t
e
r
a
l
"

n
a
m
e
s
p
a
c
e
=
"
h
t
t
p
:
/
/
s
e
r
v
i
c
e
.
j
a
x
w
s
.
j
o
u
r
n
a
l
d
e
v
.
c
o
m
/
"
/
>

<
/
o
u
t
p
u
t
>

<
/
o
p
e
r
a
t
i
o
n
>

<
/
b
i
n
d
i
n
g
>

<
s
e
r
v
i
c
e

n
a
m
e
=
"
T
e
s
t
S
e
r
v
i
c
e
S
e
r
v
i
c
e
"
>

<
p
o
r
t

n
a
m
e
=
"
T
e
s
t
S
e
r
v
i
c
e
P
o
r
t
"

b
i
n
d
i
n
g
=
"
t
n
s
:
T
e
s
t
S
e
r
v
i
c
e
P
o
r
t
B
i
n
d
i
n
g
"
>

<
s
o
a
p
:
a
d
d
r
e
s
s

l
o
c
a
t
i
o
n
=
"
h
t
t
p
:
/
/
l
o
c
a
l
h
o
s
t
:
8
8
8
8
/
t
e
s
t
W
S
"
/
>

<
/
p
o
r
t
>

<
/
s
e
r
v
i
c
e
>

<
/
d
e
f
i
n
i
t
i
o
n
s
>



Notice that types element is empty and we can’t validate it against any schema.
Now just change the SOAPBinding.Style.RPC to
SOAPBinding.Style.DOCUMENT and you will get below WSDL.
document.xml
1
2 <

 ?
3 x

 m
4 l

5 v

 e
6 r

 s
7 i

 o
8 n

 =
9 '

 1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
a
r
g
0
"

t
y
p
e
=
"
x
s
:
s
t
r
i
n
g
"

m
i
n
O
c
c
u
r
s
=
"
0
"
/
>

<
/
x
s
:
s
e
q
u
e
n
c
e
>

<
/
x
s
:
c
o
m
p
l
e
x
T
y
p
e
>


<
x
s
:
c
o
m
p
l
e
x
T
y
p
e

n
a
m
e
=
"
s
a
y
H
e
l
l
o
R
e
s
p
o
n
s
e
"
>

<
x
s
:
s
e
q
u
e
n
c
e
>

<
x
s
:
e
l
e
m
e
n
t

n
a
m
e
=
"
r
e
t
u
r
n
"

t
y
p
e
=
"
x
s
:
s
t
r
i
n
g
"

m
i
n
O
c
c
u
r
s
=
"
0
"
/
>

<
/
x
s
:
s
e
q
u
e
n
c
e
>

<
/
x
s
:
c
o
m
p
l
e
x
T
y
p
e
>

<
/
x
s
:
s
c
h
e
m
a
>



So here WSDL document can be validated against the schema definintion.
How to get WSDL file of a SOAP web service?
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.

What is sun-jaxws.xml file?
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. For example;
sun-jaxws.xml
1
 <?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-
2 version="2.0">
 <endpoint
 name="PersonServiceImpl"
 implementation="com.jou

 pattern="/personWS"/>
</endpoints>

3

4

5

6

7

What is JAX-RS API?
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.

Name some implementations of JAX-RS API?
There are two major


implementations of JAX-RS API.
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.
RESTEasy: RESTEasy is the JBoss project that provides JAX-RS
implementation.

What is wsimport utility?
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.

<img src="http://1988780851.rsc.cdn77.org/wp-
content/uploads/2015/10/wsimport-utility-parse-wsdl-450x293.png"
alt="wsimport-utility-parse-wsdl" width="450" height="293"
class="aligncenter size-medium wp-image-9129"
srcset="http://1988780851.rsc.cdn77.org/wp-
content/uploads/2015/10/wsimport-utility-parse-wsdl-450x293.png 450w,
http://1988780851.rsc.cdn77.org/wp-content/uploads/2015/10/wsimport-
utility-parse-wsdl-1024x667.png 1024w,
http://1988780851.rsc.cdn77.org/wp-content/uploads/2015/10/wsimport-
utility-parse-wsdl-700x456.png 700w, http://1988780851.rsc.cdn77.org/wp-
content/uploads/2015/10/wsimport-utility-parse-wsdl-150x98.png 150w,
http://1988780851.rsc.cdn77.org/wp-content/uploads/2015/10/wsimport-
utility-parse-wsdl.png 1176w" sizes="(max-width: 450px) 100vw, 450px" />

Name important annotations used in JAX-RS API?
Some of the important JAX-RS


annotations are:
@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.

What is the use of @XmlRootElement annotation?
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.
How to set different status code in HTTP response?
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.
1
 return Response.status(422).entity(exception).build();
return Response.ok(response).build(); /
2

http://java67.blogspot.in/2015/09/top-10-restful-web-service-interview-questions-
answers.html

REST is an architectural style of developing web services which has become


immensely popular in last couple of years and consequently gained lot of importance
in core Java and Java EE interviews. If you are a Java web developer then you are
most likely see couple of questions from web services every time you go for a Java
web developer interview. One of the most frequently one is difference between
REST and SOAP web services, which I have recently answered there, but there are lot
many other good questions I have collected from friends and my readers, which I
have not yet published. In this article, I am sharing those questions, mainly based
upon REST style web services for your practice and preparation. Some of them are
easy to answer and you will find them either in my blog or by doing Google but
couple of them is really interesting and challenging and required real solid
experience in Java web service domain to answer. I leave it to you guys for now and
will probably update this post with answers in near future. If you don't find answer
of any REST interview question then I suggest you to take a look at these two books,
Java Programming Interview Exposed and RESTful Web Services, you will most likely
find your answer there.

RESTful Web Services Interview Questions


Here is my list of RESTful web services questions for senior Java developers who has
couple of years of experience developing both SOAP and REST based web services.
This is actually second part of my series of Java web services based question, in
earlier article I have shared some SOAP web services based questions. If you have
not looked already, you may want to take a look.
Question 1 : What is REST?
Answer : REST is an architectural style of developing web services which take
advantage of ubiquity of HTTP protocol and leverages HTTP method to define
actions. REST stands for REpresntational State Transfer.

Question 2 : What is RESTFul Web Service?


Answer : There are two popular way to develop web services, using SOAP (Simple
Object Access Protocol) which is XML based way to expose web services and second
REST based web services which uses HTTP protocol. Web services developed using
REST style is also known as RESTful web services.

Question 3 : What is HTTP Basic Authentication and how it works?


The server sends back a header stating it requires authentication for a given realm.
The user provides the username and password, which the browser concatenates
(username + ":" + password), and base64 encodes. This encoded string is then sent
using a "Authorization"-header on each request from the browser. Because the
credentials are only encoded, not encrypted, this is highly insecure unless it is sent
over https.

Read more: http://java67.blogspot.com/2015/09/top-10-restful-web-service-


interview-questions-answers.html#ixzz48XdeyM7f

Question 4 : Can you tell me which API can be used to develop RESTFul web service
in Java?
Answer : There are many framework and libraries out there which helps to develop
RESTful web services in Java including JAX-RS which is standard way to develop REST
web services. Jersey is one of the popular implementation of JAX-RS which also
offers more than specification recommends. Then you also have RESTEasy, RESTlet
and Apache CFX. If you like Scala then you can also use Play framework to develop
RESTful web services.

Question 5 : How do you configure RESTFul web service?

Question 6 : How you apply security in RESTFul web services?

Question 7 : Have you used securing RESTful APIs with HTTP Basic Authentication

Question 8 : How you maintain session in RESTful services?

Question 9 : Have you used Jersey API to develop RESTful services in Java?
Answer : Jersey is one of the most popular framework and API to develop REST
based web services in Java. Since many organization uses Jersey they check if
candidate has used it before or not. It's simple to answer, say Yes if you have really
used and No, if you have not. In case of No, you should also mention which
framework you have used for developing RESTful web services e.g. Apache CFX, Play
or Restlet.

Question 10 : How you test RESTful web services?


There several tools to create automated tests for RESTful Web Services. You can test
internally or externally.
For internal testing you can relay in unit test (JUnit or other of your choice), mocking
the lower layers you need, business, cache, persistence, etc.
For external testing you can use tools (JMeter, Grinder, etc) to perform functional
and stress test. Of course you have to recreate all the enviroment to recreate the
same conditions, using in-memory db, and emulated servers (Docker myself) will
allow you to do it easily.
Both kind of test can be tested by a CI server or manually

Question 11 : What is WADL in RESTFul?

Question 12 : What do you understand by payload in RESTFul?


Answer : Payload means data which passed inside request body also payload is not
request parameters. So only you can do payload in POST and not in GET and DELTE
method

Question 13 : Can you do payload in GET method?


Answer : No, payload can only be passed using POST method.

Question 14 : Can you do payload in HTTP DELETE?


Answer : This is again similar to previous REST interview question, answer is No. You
can only pass payload using HTTP POST method.

Question 15 : How much maximum pay load you could do in POST method?
Answer : If you remember difference between GET and POST request then you know
that unlike GET which passes data on URL and thus limited by maximum URL length,
POST has no such limit. So, theoretically you can pass unlimited data as payload to
POST method but you need to take practical things into account e.g. sending POST
with large payload will consume more bandwidth, take more time and present
performance challenge to your server.

Question 16 : What is difference between SOAP and RESTFul web services?


Answer : There are many difference between these two style of web services e.g.
SOAP take more bandwidth because of heavy weight XML based protocol but REST
takes less bandwidth because of popular use of JSON as message protocol and
leveraging HTTP method to define action. This also means that REST is faster than
SOAP based web services. You can derive many differences between SOAP and
RESTful with the fact that its HTTP based e.g. REST URLs can be cached or
bookmarked. Here are few more differences between them :
Question 17 : If you have to develop web services which one you will choose SOAP
OR RESTful and why?
Answer : You can answer this question based upon your experience but the key here
is if you know difference between them than you can answer this question in more
detail. For example, its easy to develop RESTful web services than SOAP based web
services but later comes with some in-built security features.

Question 18 : What framework you had used to develop RESTFul services?


Answer : This is really experience based question. If you have used Jersey to develop
RESTFul web services then answer as Jersey but expect some follow-up question on
Jersey. Similarly if you have used Apache CFX or Restlet then answer them
accordingly.

That's all in this list of some good RESTful web service interview questions for Java
developers. Though this list is meant for Java developer, you can use this questions
to check any candidate's knowledge on REST style web services independent of
programming language because REST doesn't say that you need to implement web
service in Java only. Since it take advantage of ubiquitous HTTP protocol you can
build backed with any web technology stack e.g. Java, .NET or any other.

Read more: http://java67.blogspot.com/2015/09/top-10-restful-web-service-


interview-questions-answers.html#ixzz48XdXWWV2

You might also like