Developing Web services for WebSphere using JAX-WS Annotations
JAX WS 2
Click here to load reader
-
Upload
mario-cartia -
Category
Technology
-
view
1.300 -
download
10
Transcript of JAX WS 2
![Page 1: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/1.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
JAX-WS2:Web Services made easy
diMario Cartia
![Page 2: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/2.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
La diffusione delle architetture SOA ha portato alla ribalta negli ultimi anni il ruolo dei Web Services
nell'ambito dello sviluppo software
La specifica JSR 101 (JAX-RPC 1.1) ha consentito agli sviluppatori Java di utilizzare WS fino alla
definizione della specifica JSR 244 (Java API for XML-Based Web Services) seppure con alcune
limitazioni...
![Page 3: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/3.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
![Page 4: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/4.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
Layers sottostanti (binding e parsing) legati ad implementazioni proprietarie
Interoperabilità
Performances
Modello di sviluppo
![Page 5: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/5.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
L'utilizzo delle annotations consente di creare un WS a partire da una classe POJO
@WebService publ ic c lass Calculator { publ i c int add ( int a , int b ) { return a+b; }
● Tutti i metodi pubblici sono esposti come operazioni web service● Un WSDL con valori di default è generato in automatico
![Page 6: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/6.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
...o da un EJB
@WebService @State less publ ic c lass Calculator { @Resource WebServiceContext context; publ i c int add ( int a , int b ) { return a+b; }
● L'EJB “conserva” tutte le sue features (transazioni, sicurezza, interceptors, ...
![Page 7: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/7.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
Agendo sulle annotations è possibile rendere più leggibile il WSDL autogenerato
@WebService(name=”CreditRatingService”, targetNamespace=”http://example.org”) public c lass CreditRating { @WebMethod(operationName=”getCreditScore”) public Score getCredit ( @WebParam(name=”customer”) Customer c) { / / . . . i m p l e m e n t a z i o n e . . . } }
![Page 8: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/8.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
Creazione del client Java SE
Il tool “wsimport” a partire dal WSDL crea le classi di supporto
Per invocare una operazione WS è necessario istanziare la classe service ed ottenere il proxy
mediante chiamata al metodo get<ServiceName>Port
CalculatorService svc = new CalculatorService ( ) ; Calcu la tor proxy = svc.ge tCalcu la torPort ( ) ; int answer = proxy.add(35, 7 ) ;
![Page 9: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/9.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
Creazione del client Java EE
Il tool “wsimport” a partire dal WSDL crea le classi di supporto
Con il meccanismo della dependancy injection, mediante annotation @WebServiceReference ottengo
la reference (N.B. non è necessario utilizzare JNDI)
![Page 10: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/10.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
Esempio
@State less public class MyBean { / / Resource inject ion @WebServiceRef (CalculatorService.c lass ) Calculator proxy ; public int mymethod() { re turn proxy. add (35 , 7 ) ; }
![Page 11: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/11.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
Annotations utilizzate in JAX-WS
● JSR 181: Web Services Metadata for the Java Platform ● JSR 222: Java Architecture for XML Binding (JAXB) ● JSR 224: Java API for XML Web Services (JAX-WS) ● JSR 250: Common Annotations for the Java Platform
![Page 12: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/12.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
@WebService Si applica ad una classe o ad una interfaccia (implementazione o interfaccia).
Attributi ● endpointInterface ● name ● portName ● serviceName ● targetNamespace● wsdlLocation
![Page 13: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/13.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
@WebMethod Personalizza un metodo esposto come operazione WS
N.B. Non è necessario che il metodo dichiari di lanciare una java.rmi.RemoteException.
Attributi ● action ● exclude ● operationName
![Page 14: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/14.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
@WebParam Personalizza la mappatura di un parametro di input ad una parte del messaggio WS ed ad un elemento XML
Attributi ● header ● mode ● name ● partName ● targetNamespace
![Page 15: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/15.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 - Ragusa
@WebResult Come il precedente ma si applica ai valori di ritorno
Attributi ● header ● name ● partName ● targetNamespace
![Page 16: JAX WS 2](https://reader038.fdocuments.net/reader038/viewer/2022100506/556a5b3bd8b42a7a138b4ef0/html5/thumbnails/16.jpg)
Meeting JUG Sicilia / ASI21 Maggio 2008 – Ragusa
Utilizzando Java SE 6 è possibile pubblicare un web service senza l'ausilio di un web server
javax.xml.ws.Endpoint.publish(url, object);