Jax Ws2.0

1,610
-1

Published on

Published in: Technology, Education
1 Comment
2 Likes
Statistics
Notes
  • Awesome presentation, congratulations!
    http://www.medicaldebtsconsolidation.com
    http://www.medicaldebtsconsolidation.com/category/bankruptcy/
    http://www.medicaldebtsconsolidation.com/category/medical-bills/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
1,610
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
44
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Jax Ws2.0

  1. 1. JDK 6 Web Services JAX-WS 2.0
  2. 2. JAX-WS 2.0 <ul><li>Part of Java EE. </li></ul><ul><li>New in Java SE 6. </li></ul><ul><li>API stack for web services. </li></ul><ul><li>Replaces JAX-RPC. </li></ul><ul><li>New API’s: </li></ul><ul><li>JAX-WS, SAAJ, Web Service metadata </li></ul><ul><li>New packages: </li></ul><ul><li>javax.xml.ws, javax.xml.soap,javax.jws </li></ul>
  3. 3. Writing A Web Service <ul><li>package loanservice; </li></ul><ul><li>import javax.jws.WebService; </li></ul><ul><li>import javax.jws.WebMethod; </li></ul><ul><li>import javax.xml.ws.Endpoint; </li></ul><ul><li>@WebService </li></ul><ul><li>public class LoanApprover { </li></ul><ul><li>@WebMethod </li></ul><ul><li>public boolean approve(String name) { </li></ul><ul><li>return name.equals(&quot;Mike&quot;); </li></ul><ul><li>} </li></ul>
  4. 4. <ul><li>public static void main(String[] args){ </li></ul><ul><li>LoanApprover la = new LoanApprover(); </li></ul><ul><li>Endpoint endpoint = </li></ul><ul><li>Endpoint.publish( </li></ul><ul><li>&quot;http://localhost:8080/loanapprover&quot;, </li></ul><ul><li>la); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  5. 5. Compile The Service <ul><li>Create a myservice directory. </li></ul><ul><li>From the directory just above loanservice, run Java’s </li></ul><ul><li>Annotation Processing Tool (APT): </li></ul><ul><li>C:>apt -d myservice loanservice/LoanApprover.java </li></ul><ul><li>This populates a directory named myservice. </li></ul><ul><li>The directory holds the compiled package as well </li></ul><ul><li>as a new directory (package) called jaxws. </li></ul><ul><li>The new jaxws package holds classes associated with </li></ul><ul><li>the parameters to and from each web service method. </li></ul><ul><li>Use the -s switch to generate the source code. </li></ul>
  6. 6. Publish the Service <ul><li>From a directory just above myservice: </li></ul><ul><li>C:>java -cp myservice loanservice/LoanApprover </li></ul><ul><li>To view the WSDL, visit the service with a browser at </li></ul><ul><li>http://localhost:8080/loanapprover?wsdl </li></ul>
  7. 7. Generate Stub Code <ul><li>Make a client directory. </li></ul><ul><li>C:>wsimport –p client –keep http://localhost:8080/loanapprover?wsdl </li></ul><ul><li>This populates the client subdirectory with .class </li></ul><ul><li>and .java files. </li></ul>
  8. 8. Write the Client <ul><li>package client; </li></ul><ul><li>class ApproverClient { </li></ul><ul><li>public static void main(String args[]){ </li></ul><ul><li> LoanApproverService service = new LoanApproverService(); </li></ul><ul><li>LoanApprover approverProxy = service.getLoanApproverPort(); </li></ul><ul><li>boolean result = approverProxy.approve(&quot;Mike&quot;); </li></ul><ul><li>if(result) System.out.println(&quot;Approved&quot;); </li></ul><ul><li>else System.out.println(&quot;Not approved&quot;); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  9. 9. Compile & Run the Client <ul><li>C:>javac –cp . client/ApproverClient.java </li></ul><ul><li>C:>java -cp . client/ApproverClient </li></ul><ul><li>Approved </li></ul>
  10. 10. ServerCounter is a Singleton <ul><li>@WebService </li></ul><ul><li>public class ServerCounter { </li></ul><ul><li>int ctr = 0; </li></ul><ul><li>public int getCtr() { </li></ul><ul><li>ctr++; </li></ul><ul><li>return ctr; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>What happens? A single object holds the count and every client shares it. Each visit generates a new updated count.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×