7.Java6 &EJB
7.Java6 &EJB
<>Java6
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
http://<host>:<port>/<ServerName>
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:
http://<host>:<port>/<ServiceName>?wsdl
if you work on Chrome:
view-source:http://<host>:<port>/<ServiceName>?wsdl
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 :
a.Interface:
package slm.abdennour.ws; import javax.jws.WebMethod; import javax.jws.WebService; //Service Endpoint Interface @WebService public interface HelloWorld{ @WebMethod String getHelloWorldAsString(String name); }
b.Implementation :
File : HelloWorldImpl.java
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()); } }
Note
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 :
@Stateless
@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