JDK 6 Web Services
description
Transcript of JDK 6 Web Services
![Page 1: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/1.jpg)
195-702 OCT
Master of Information System Management
JDK 6 Web Services
Lecure 6: JAX-WS 2.0
![Page 2: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/2.jpg)
295-702 OCT
Master of Information System Management
JAX-WS 2.0
• Part of Java EE.• New in Java SE 6.• API stack for web services.• Replaces JAX-RPC.• New API’s: JAX-WS, SAAJ, Web Service metadata
• New packages: javax.xml.ws, javax.xml.soap,javax.jws
![Page 3: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/3.jpg)
395-702 OCT
Master of Information System Management
Writing A Web Servicepackage loanservice;
import javax.jws.WebService;import javax.jws.WebMethod;import javax.xml.ws.Endpoint;
@WebService
public class LoanApprover {
@WebMethod public boolean approve(String name) { return name.equals("Mike"); }
![Page 4: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/4.jpg)
495-702 OCT
Master of Information System Management
public static void main(String[] args){ LoanApprover la = new LoanApprover();
Endpoint endpoint = Endpoint.publish( "http://localhost:8080/loanapprover", la); }}
![Page 5: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/5.jpg)
595-702 OCT
Master of Information System Management
Compile The ServiceCreate a myservice directory.
From the directory just above loanservice, run Java’sAnnotation Processing Tool (APT):
C:\>apt -d myservice loanservice/LoanApprover.java
This populates a directory named myservice.The directory holds the compiled package as wellas a new directory (package) called jaxws.The new jaxws package holds classes associated withthe parameters to and from each web service method.Use the -s switch to generate the source code.
![Page 6: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/6.jpg)
695-702 OCT
Master of Information System Management
Publish the ServiceFrom a directory just above myservice:
C:\>java -cp myservice loanservice/LoanApprover
To view the WSDL, visit the service with a browser at http://localhost:8080/loanapprover?wsdl
![Page 7: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/7.jpg)
795-702 OCT
Master of Information System Management
Generate Stub CodeMake a client directory.
C:\>wsimport –p client –keep http://localhost:8080/loanapprover?wsdl
This populates the client subdirectory with .classand .java files.
![Page 8: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/8.jpg)
895-702 OCT
Master of Information System Management
Write the Clientpackage client;
class ApproverClient {
public static void main(String args[]){ LoanApproverService service = new LoanApproverService(); LoanApprover approverProxy = service.getLoanApproverPort(); boolean result = approverProxy.approve("Mike"); if(result) System.out.println("Approved"); else System.out.println("Not approved");
}}
![Page 9: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/9.jpg)
995-702 OCT
Master of Information System Management
Compile & Run the ClientC:\>javac –cp . client/ApproverClient.java
C:\>java -cp . client/ApproverClientApproved
Demo files under :mm6/www/95-843/JDK6_WebServices/Demo
![Page 10: JDK 6 Web Services](https://reader036.fdocuments.in/reader036/viewer/2022082505/56813c0a550346895da5752f/html5/thumbnails/10.jpg)
1095-702 OCT
Master of Information System Management
ServerCounter is a Singleton
@WebServicepublic class ServerCounter { int ctr = 0; public int getCtr() { ctr++; return ctr; }}
What happens?
A single objectholds the countand every clientshares it. Eachvisit generates a new updated count.