JDK 6 Web ServicesJAX-WS 2.0Writing A Web ServicePowerPoint PresentationCompile The ServicePublish the ServiceGenerate Stub CodeWrite the ClientCompile & Run the ClientServerCounter is a Singleton195-804 Applied CryptographyMaster of Information System ManagementJDK 6 Web ServicesWeek 4: JAX-WS 2.0295-804 Applied CryptographyMaster of Information System ManagementJAX-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.jws395-804 Applied CryptographyMaster of Information System ManagementWriting A Web Servicepackage loanservice;import javax.jws.WebService;import javax.jws.WebMethod;import javax.xml.ws.Endpoint;@WebServicepublic class LoanApprover { @WebMethod public boolean approve(String name) { return name.equals("Mike"); }495-804 Applied CryptographyMaster of Information System Managementpublic static void main(String[] args){ LoanApprover la = new LoanApprover(); Endpoint endpoint = Endpoint.publish( "http://localhost:8080/loanapprover", la); }}595-804 Applied CryptographyMaster of Information System ManagementCompile The ServiceCreate a myservice directory.From the directory just above loanservice, run Java’sAnnotation Processing Tool (APT):C:\>apt -d myservice loanservice/LoanApprover.javaThis 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.695-804 Applied CryptographyMaster of Information System ManagementPublish the ServiceFrom a directory just above myservice:C:\>java -cp myservice loanservice/LoanApproverTo view the WSDL, visit the service with a browser at http://localhost:8080/loanapprover?wsdl795-804 Applied CryptographyMaster of Information System ManagementGenerate Stub CodeMake a client directory.C:\>wsimport –p client –keep http://localhost:8080/loanapprover?wsdlThis populates the client subdirectory with .classand .java files.895-804 Applied CryptographyMaster of Information System ManagementWrite 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");}}995-804 Applied CryptographyMaster of Information System ManagementCompile & Run the ClientC:\>javac –cp . client/ApproverClient.javaC:\>java -cp . client/ApproverClientApprovedDemo files under :mm6/www/95-843/JDK6_WebServices/Demo1095-804 Applied CryptographyMaster of Information System ManagementServerCounter 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
or
We will never post anything without your permission.
Don't have an account? Sign up