The largest Interview Solution Library on the web


Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

81.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<String> 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]

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

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

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

85.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();
}
}

86.What are the types of information included in SOAP header?

Header of SOAP contains information like that,

  • In SOAP header client should handle authentication and transaction.
  • The SOAP message should process by client.
  • EncodingStyle is also has in header.

87.How can you explain HTTP Binding in SOAP ?

Let us start with and example to inform you HTTP perform communication over TCP/IP.And TCP HTTP client can connect to an HTTP server.
When connection will established than using that connection client can send an HTTP request message to the server.
POST /item HTTP/1.1
Host: 189.123.345.239
Content-Type: text/plain
Content-Length: 200
Server processes this request and sends an HTTP response back to the client. The response contains has a status code that are use to indicate the status of the request.
200 OK
Content-Type: text/plain
Content-Length: 200
This server returned a status code of 200.This is also called as standard success code for HTTP.
If the server has unable to decode the request, it can returned something like.
400 Bad Request
Content-Length: 0
SOAP HTTP Binding: We use SOAP method to complies with the SOAP encoding rules.
HTTP + XML = SOAP
A SOAP request may be an HTTP POST or an HTTP GET request.
HTTP POST request specifies at least two HTTP headers:

  • Content-Type
  • Content-Length
  • Content-Type: In case of Soap request and response, Content-Type header defines the MIME type for the message and the character encoding ( that is optional) used only for XML body of the request or response.

  • Syntax:
    Content-Type MIMEType;
    charset=character-encoding
    Example:
    POST /item HTTP/1.1
    Content-Type application/soap+xml; charset=utf-8
  • Content-Length: Using Content-Length header we specifies the number of bytes in the body of the request or response for a SOAP request and response.

Syntax:
Content-Length: bytes
Example:
POST /item HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 250

88.Explain the differnece between fault and exception in Apache SOAP?

Difference b/w the fault and exception depends upon where these error occurs, may be they occour on client side or on server side. Exception occurs on client side where as faulut occur on server side. I have explain you with an example.We send an SOAP encoded request for which method that does not exist results in a SOAP fault whereas when server sends a response with a field that does not exist in a client side class

89.What are the software components that we must used to build a SOAP server?

XML processor and HTTP Server are mandatory when you want to build SOAP Server.We have to use some other tools when you deal with different language.
When you deal with Visual Basic 6.0 or VBA than you must have to use either Microsoft SOAP TOOLkit or PocketSOAP.
When you deal with VB.Net or C# than you must have to use Visual Stdio.Net or .Net Framework.
When you deal with Delphi than you have to use Borland’s Web services.
When you deal with C++ than you have to use Systinet WASP Server for C++ or gSOAP.
When you deal with Java,Than their is a many choices for you like: Apache Axis, Systinet WASP Server for Java, The Mind Electric GLUE, Cape Clear Cape Connect, BEA Workshop, etc.
Most likely Java environments are WASP, GLUE, and Axis.

90.What is SOAP and how we can utilize this with Web components ?

SOAP is stands for Simple Object Access Protocol. SOAP was first comes in 1990 after that in 2000 it introduced to W3C.
In Web Component we use SOAP to send an request for to invoke programs on remote computers with using XML wrappers.
The main purpose to use SOAP in Web Service is that to send messages over HTTP protocol.

91.What are the element that we used in SOAP?

  • An envelope element is used to identifies and translates the XML document into a SOAP message.
  • A header element is used to contain header message.
  • A body is used to contain call and response message.
  • Fault element is used to communicate about the errors occurred during the process.

92.What are the disadvantages of SOAP?

Some disadvantages .

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

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

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

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

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

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

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

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

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

    « Previous | 0 | 1 | 2 | 3 | 4 | Next »


  • copyright © 2014 - all rights riserved by javatechnologycenter.com