Don't forget to create account on our site to get access to more material made only for free registered user.  

CCD-410 Certifcation CCA-500 Hadoop Administrator Exam HBase Certifcation CCB-400 Data Science Certifcation Hadoop Training with Hands On Lab

152 Practice Questions for Java WebService Certifications (Lifetime access & free updates on same machine)

Java WebService Training (JAX-WS and JAX-RS)

Q15. Select the correct statement, with regards to EJB to be exposed as Restful WebService (JAX-RS) ?
 
A. the EJB can only be deployed to a web container, since RESTful access to the EJB requires a web container to support the HTTP interaction needed.
B. the EJB can be deployed to any EJB or web container that would support local references to the EJB from the JAX-RS runtime in the ejb container.
C. the EJB can be deployed to any EJB or web container that would support local references to the EJB from the JAX-RS runtime in the web container.
D. the EJB can be deployed to an EJB or web container that is visible to the JAX-RS runtime, even on an application server separate from the JAX-RS runtime, since EJBs support local or remote interactions via RMI.
 
Ans: C
Exp : Now for building Restful web service from an EJB class, all that we need to do is to package the web service in a Web application (servlet 3.0/3.1) and create an application class that loads the EJB class as a Rest Root class and annotating the EJB class with @Path annotation.
 
 EJB class will be included in the war file and not in the ejb jar file, as in JEE 7 it is allowed to declare EJB classes in war files.
 
 @Path: declares that this EJB should be exposed as restful web service
 @GET: means that the method will be invoked on the HTTP GET request.
@Produces: means that the method will return data of type plain text.
 
Bean has a @LocalBean annotation -> bean has a no-interface view
Bean has a @Local annotation -> bean has a local view
Bean has a @Remote annotation -> bean has a remote view
 
For Resource:
If EJB-based resource does not implement any interface, all of the methods that are declared in this class are available as JAX-RS resources.
If EJB-based resource implements one interface (local or POJO), then all the methods that are declared in this interface are available as JAX-RS resources.
If EJB-based resource implements multiple interface,
If all the interfaces are POJO interfaces without the @Local annotation, then all the methods that are declared in interface are available as JAX-RS resources.
If all the interfaces are local interfaces with the @Local annotation, then all the methods that are declared in the interface are available as JAX-RS resources.
If some of the interfaces are local interfaces with the @Local annotation while others are not local interfaces, then only the methods declared in the local interfaces are available as JAX-RS resources. The reason is that the EJB container can generate EJB stub for local interfaces only in this scenario.
If the EJB-based resource has the @LocalBean annotation, then all the methods that are declared in class are available as JAX-RS resource.
If EJB-based resource implements an interface, then JAX-RS resource method must be declared in the interface. If the interface is a provider that can't be modified, then you must create a new interface for the resource class to add the resource method. Otherwise, it is not seen as EJB resource.
If a resource class with the @Path annotation implements JAX-RS provider interface or it declares with the @Provider annotation, this class works as both a resource and a provider. In this case, by default, the JAX-RS 2.0 engine uses only one instance of this class that is shared by the resource and the provider, and the lifecycle of the instance is singleton.
If a class is registered in both the getClasses and getSingletons methods of the application class, then by default, the JAX-RS 2.0 engine uses the instance from the getSingletons method and ignore the registration in the getClasses method.
If a RESTful resource is also a CDI managed bean and its scope is javax.enterprise.context.Dependent, the PreDestroy method cannot be called because of the CDI restriction.

152 Practice Questions for Java WebService Certifications (Lifetime access & free updates on same machine)

Java WebService Training (JAX-WS and JAX-RS)