JDK 6 Web Services - PowerPoint PPT Presentation

About This Presentation
Title:

JDK 6 Web Services

Description:

{ LoanApprover la = new LoanApprover(); Endpoint endpoint = Endpoint.publish ... This populates the client subdirectory with .class. and .java files. 8. 95-702 OCT ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 11
Provided by: Office20055
Category:
Tags: jdk | class | services | web

less

Transcript and Presenter's Notes

Title: JDK 6 Web Services


1
JDK 6 Web Services
  • Week 3 JAX-WS 2.0

2
JAX-WS 2.0
  • Part of Java EE.
  • New in Java SE 6.
  • API stack for web services.
  • Replaces JAX-RPC.
  • New APIs
  • JAX-WS, SAAJ, Web Service metadata
  • New packages
  • javax.xml.ws, javax.xml.soap,javax.jws

3
Writing A Web Service
  • package loanservice
  • import javax.jws.WebService
  • import javax.jws.WebMethod
  • import javax.xml.ws.Endpoint
  • _at_WebService
  • public class LoanApprover
  • _at_WebMethod
  • public boolean approve(String name)
  • return name.equals("Mike")

4
  • public static void main(String args)
  • LoanApprover la new LoanApprover()
  • Endpoint endpoint
  • Endpoint.publish(
  • "http//localhost8080/loanapprover",
  • la)

5
Compile The Service
  • Create a myservice directory.
  • From the directory just above loanservice, run
    Javas
  • Annotation Processing Tool (APT)
  • C\gtapt -d myservice loanservice/LoanApprover.java
  • This populates a directory named myservice.
  • The directory holds the compiled package as well
  • as a new directory (package) called jaxws.
  • The new jaxws package holds classes associated
    with
  • the parameters to and from each web service
    method.
  • Use the -s switch to generate the source code.

6
Publish the Service
  • From a directory just above myservice
  • C\gtjava -cp myservice loanservice/LoanApprover
  • To view the WSDL, visit the service with a
    browser at
  • http//localhost8080/loanapprover?wsdl

7
Generate Stub Code
  • Make a client directory.
  • C\gtwsimport p client keep http//localhost8080
    /loanapprover?wsdl
  • This populates the client subdirectory with
    .class
  • and .java files.

8
Write the Client
  • package 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("Approve
    d")
  • else System.out.println("Not
    approved")

9
Compile Run the Client
  • C\gtjavac cp . client/ApproverClient.java
  • C\gtjava -cp . client/ApproverClient
  • Approved

Demo files under mm6/www/95-843/JDK6_WebServices
/Demo
10
ServerCounter is a Singleton
  • _at_WebService
  • public class ServerCounter
  • int ctr 0
  • public int getCtr()
  • ctr
  • return ctr

What happens? A single object holds the
count and every client shares it. Each visit
generates a new updated count.
Write a Comment
User Comments (0)
About PowerShow.com