WELCOME Abdennour : Software engineer

May 17, 2012

4.JAX-WS & JAVA 6 SE & EJB : Part3

7.Java6 &EJB

7.Java6 &EJB
With JavaSE6, we can get rid of Glassfish servers & tomcat.
JAVASE6 provides Embedded Web Server.

To publish a service,follo this steps:
1) Annotate the class with @ WebService to a minimum.
2) In the publisher Class (Main): Call:
Endpoint.publish Endpoint (String address, Object implementor)
=> Address: Address Choose this format

              Example:  http://localhost:7865/hellojava6se
=> implementor: implement Implements instance of a Web Service
3) Run Main then, if you want WSDL URL, simply type the URL:
if you work on Chrome:

  i.Methods OF EndPoint : 
 1) publish(@,imp) : to publish a Web Service  .
 2) isPublished() : ensure if service was published .
 3)stop() : stop Publication of Service .

ii. HelloWorld WS&Java SE 6 : 
 1) Create Service Web and add required Annotations : 

package slm.abdennour.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
//Service Endpoint Interface
public interface HelloWorld{
 @WebMethod String getHelloWorldAsString(String name);

    b.Implementation : 
File : HelloWorldImpl.java

package slm.abdennour.ws;
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "slm.abdennour.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
 public String getHelloWorldAsString(String name) {
  return "Hello World JAX-WS " + name;

 2)  manage publication of Web Service : 

package slm.abdennour.endpoint;
import javax.xml.ws.Endpoint;
import slm.abdennour.ws.HelloWorldImpl;
//Endpoint publisher
public class HelloWorldPublisher{
 public static void main(String[] args) {
    Endpoint.publish("http://localhost:8878/ws/hello", new HelloWorldImpl());


In general words, “web service endpoint” is a service which published outside for user to access; where “web service client is the party who access the published service.

<>EJB :
1) To get Web Service in EJB Context : add @WebService to a Session EJB.(Stateless or ~ful)
    Example : 
  @WebService(endpointInterface = "fr.ensma.lisi.notebookwebservicefromejb.NotebookService")
   public class NotebookServiceImpl {

2)Deploy App.....EJB Container Manage the Web Service ===>Don't need Servlet.

3) URL of WSDL : http://monserveur/app/Service?WSDL

4)To retrieve a Service Instance from EJB Container =>Inject @WebServiceReference.
    Example :
     public class NotebookWebServiceFromEJBClientServlet extends HttpServlet {
               @WebServiceRef(wsdlLocation =                  "http://localhost:8080/NotebookWebServiceFromEJB/Notebook?wsdl")
                private Notebook_Service service;
                protected void doGet(HttpServletRequest request, HttpServletResponse response)  thr ...

Reference : 

No comments:

Post a Comment