Académique Documents
Professionnel Documents
Culture Documents
Development Using
Annotations
Brian Zotter
Staff Engineer
BEA Systems
http://www.bea.com
TS-7964
2005 JavaOne SM Conference | Session TS-7964 1
Instant Web Services
• JSR 181
• Development Models
• Processor
• Runtime
• Annotations
• Reference Implementation
• Next Steps
• Summary
• Q&A
2005 JavaOneSM Conference | Session TS-7964 | 4
Agenda
• JSR 181
• Development Models
• Processor
• Runtime
• Annotations
• Reference Implementation
• Next Steps
• Summary
• Q&A
2005 JavaOneSM Conference | Session TS-7964 | 5
JSR 181
@WebService
public class HelloWorld { Exposes this
method as a Web
Service operation
@WebMethod
public String hello(){
return “Hello World!”;
}
}
JSR-181 Processor
Semantic Checking
Deployment Artifact
Generation
• JSR 181
• Development Models
• Processor
• Runtime
• Annotations
• Reference Implementation
• Next Steps
• Summary
• Q&A
2005 JavaOneSM Conference | Session TS-7964 | 12
Annotations
• JSR 175
• Purpose
• Java technology to WSDL Mapping
• Binding
• Processing(Handlers)
• Defines smart defaults
(Configuration by exception)
• WebService
• OneWay
• WebParam
• WebResult
• SOAPBinding
• HandlerChain
• SoapMessageHandler(SoapMessageHandlers)
• operationName
• Name of the wsdl:operation matching this method
• action
• The action for this operation. For SOAP bindings, this
determines the value of the SOAPAction header
@WebService
public class HelloWorld {
@WebMethod
public String hello(){
return “Hello World!”;
}
}
@WebMethod (operationName=“hi”)
public String hello(){
return “Hello World!”;
}
}
<wsdl:message name="hello">
name=“hi">
<wsdl:part name="parameters" element="tns:helloRequest"/>
element="tns:hiRequest"/>
</wsdl:message>
<wsdl:message name="helloResponse">
name=“hiResponse">
<wsdl:part name="return" element="tns:helloResponse"/>
element="tns:hiResponse"/>
</wsdl:message>
<wsdl:portType name="HelloWorld">
<wsdl:operation name="hello">
name=“hi">
<wsdl:input message="tns:hello"/>
message="tns:hi"/>
<wsdl:output message="tns:helloResponse"/>
message="tns:hiResponse"/>
</wsdl:operation>
</wsdl:portType>
2005 JavaOneSM Conference | Session TS-7964 | 18
Example 1—Hello World
@WebService (serviceName=“myService”)
public class HelloWorld {
@WebMethod
public String hello(){
Default is class return “Hello World!”;
name + “Service” }
}
<wsdl:service name="myService">
name="HelloWorldService">
<wsdl:port name="HelloWorldServicePort“
binding="tns:HelloWorldBinding">
<soap:address location="…"/>
</wsdl:port>
</wsdl:service>
@WebService
@SOAPBinding(
style=SOAPBinding.Style.RPC,
use=SOAPBinding.Use.ENCODED)
public class EchoService {
@WebMethod(action=“echo”)
@WebResult(name=“echoResult")
public String echo( @WebParam(name=“echoMsg") String msg){
return msg;
}
}
@WebMethod(action=“echo”)
@WebResult(name=“echoResult")
public String echo( @WebParam(name=“echoMsg") String msg){
return msg;
}
}
<message name="echo">
<part name=“echoMsg" type="s0:string"/>
</message>
<message name="echoResponse">
<part name=“echoResult" type="s0:string"/>
</message>
<portType name="EchoService">
<operation name="echo" parameterOrder=“echoMsg">
<input message="s1:echo"/>
<output message="s1:echoResponse"/>
</operation>
</portType>
2005 JavaOneSM Conference | Session TS-7964 | 25
Example 2—RPC/ENCODED
@WebService
@SOAPBinding(style=SOAPBinding.Style.RPC,use=SOAPBinding.Use.ENCODED)
public class EchoService {
…
}
@WebService
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
use=SOAPBinding.Use.LITERAL,
parameterStyle=SOAPBinding.ParameterStyle.BARE)
public class EchoService {
@WebMethod(action="echo")
@WebResult(targetNamespace=“http://exa.org”, name="echoResult")
public String echo(
@WebParam(targetNamespace=“http://exa.org”, name="echoMsg") String msg){
return msg;
}
}
@WebMethod(action="echo")
@WebResult(targetNamespace=“http://exa.org”, name="echoResult")
public String echo(
@WebParam(targetNamespace=“http://exa.org”, name="echoMsg") String msg){
return msg;
}
}
<wsdl:message name="echo">
<wsdl:part name="parameters" element="ns0:echoMsg"/>
<wsdl:types>
</wsdl:message>
<xs:schema targetNamespace=“http://exa.org”
<wsdl:message name="echoResponse">
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<wsdl:part name="echoResult" element="ns0:echoResult"/>
<xs:element name="echoResult" type="xs:string"/>
</wsdl:message>
<xs:element name="EchoService">
<wsdl:portType name="echoMsg" type="xs:string"/>
</xs:schema>
<wsdl:operation name="echo">
<wsdl:input message="tns:echo"/>
</wsdl:types>
<wsdl:output message="tns:echoResponse"/>
</wsdl:operation>
</wsdl:portType> 2005 JavaOne SM
Conference | Session TS-7964 | 28
Example 3—DOCUMENT/LITERAL/BARE
@WebService
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
use=SOAPBinding.Use.LITERAL,
parameterStyle=SOAPBinding.ParameterStyle.BARE)
public class EchoService {
@WebMethod(action="echo")
@WebResult(targetNamespace=“http://exa.org”, name="echoResult")
public String echo(
@WebParam(targetNamespace=“http://exa.org”, name="echoMsg") String msg){
return msg;
}
}
<wsdl:binding name="EchoServiceBinding" type="tns:EchoService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation
<wsdl:types> name="echo">
<soap:operation soapAction="echo" style="document"/>
<xs:schema targetNamespace=“http://exa.org”
<wsdl:input name="echoInput">
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soap:body parts="parameters" use="literal" namespace="examples"/>
<xs:element name="echoResult" type="xs:string"/>
</wsdl:input>
<xs:element name="echoMsg" type="xs:string"/>
<wsdl:output name="echoOutput">
</xs:schema>
<soap:body parts="echoResult" use="literal" namespace="examples"/>
</wsdl:types>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
2005 JavaOneSM Conference | Session TS-7964 | 29
Example 4—Headers and Mode
@WebService
@SOAPBinding(style=SOAPBinding.Style.RPC,
use=SOAPBinding.Use.LITERAL)
public class EchoHeaderService {
@WebMethod
public String echo(
@WebParam(name="myHeader",
header=true,
mode=WebParam.Mode.INOUT) StringHolder header,
String msg){
String ret = header.value + + ", " + msg;
header.value = "got it";
return ret;
}
} 2005 JavaOneSM Conference | Session TS-7964 | 30
Example 4—Headers and Mode
@WebMethod
public String echo(
@WebParam(name="myHeader",
header=true,
mode=WebParam.Mode.INOUT) StringHolder header,
String msg){
String ret = header.value + ", " + msg;
header.value = "got it";
return ret;
}
<wsdl:binding name="EchoHeaderServiceBinding" type="tns:EchoHeaderService">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="echo">
<soap:operation soapAction="" style="rpc"/>
<wsdl:types>
<wsdl:input name="echoInput">
<xs:schema
<soap:bodytargetNamespace=“http://exa.org”
parts="msg" use="literal" namespace="examples"/>
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soap:header message="tns:echo" part="myHeader" use="literal"/>
<xs:element name="echoResult" type="xs:string"/>
</wsdl:input>
<xs:element
<wsdl:output name="echoMsg" type="xs:string"/>
name="echoOutput">
</xs:schema>
<soap:body parts="return" use="literal" namespace="examples"/>
</wsdl:types>
<soap:header message="tns:echo" part="myHeader" use="literal"/>
</wsdl:output>
</wsdl:operation>
2005 JavaOne Conference | Session TS-7964
SM
| 31
</wsdl:binding>
Example 4—Headers and Mode
@WebMethod
public String echo(
@WebParam(name="myHeader",
header=true,
mode=WebParam.Mode.INOUT) StringHolder header,
String msg){
String ret = header.value + ", " + msg;
header.value = "got it";
return ret;
}
Request Response
<soap:Envelope xmlns:ns0="examples“ <soap:Envelope xmlns:soap="…">
xmlns:soap="…"> <soap:Header>
<soap:Header> <exam:myHeader xmlns:exam="examples">
<ns0:myHeader>Hello</ns0:myHeader> got it
</soap:Header> </exam:myHeader>
<soap:Body> </soap:Header>
<ns0:echo> <soap:Body>
<msg>How are you?</msg> <exam:echoResponse xmlns:exam="examples">
</ns0:echo> <return>Hello, How are you?</return>
</soap:Body> </exam:echoResponse>
</soap:Envelope> </soap:Body>
</soap:Envelope>
2005 JavaOneSM Conference | Session TS-7964 | 32
HandlerChain
• file
• Location of the handler chain file
• name
• Name of the handler chain in the file
@WebService
@SOAPMessageHandlers({
@SOAPMessageHandler(
name = "myHandler",
className = "foo.myHandler",
initParams = {@InitParam(name="offset", value="1")})
})
public class MyWebService
{
}
<handler-config xmlns:j2ee="http://java.sun.com/xml/ns/j2ee">
<handler-chain>
<handler-chain-name>MyHandlerChain</handler-chain-name>
<handler>
<j2ee:handler-name>myHandler</j2ee:handler-name>
<j2ee:handler-class>foo.MyHandler</j2ee:handler-class>
<j2ee:init-param>
<j2ee:param-name>offset</j2ee:param-name>
<j2ee:param-value>1</j2ee:param-value>
</j2ee:init-param>
</handler>
</handler-chain>
</handler-config>
2005 JavaOneSM Conference | Session TS-7964 | 37
Agenda
• JSR 181
• Development Models
• Processor
• Runtime
• Annotations
• Reference Implementation
• Next Steps
• Summary
• Q&A
2005 JavaOneSM Conference | Session TS-7964 | 38
Reference Implementation
compil
produces
JWSC deploy
e
@WebService
@SOAPBinding(style=SOAPBinding.Style.RPC,
use=SOAPBinding.Use.LITERAL)
public class EchoHeaderService {
@WebMethod
public String echo(
@WebParam(name="myHeader",
header=true,
mode=WebParam.Mode.INOUT) StringHolder header,
String msg){
String ret = header.value + + ", " + msg;
header.value = "got it";
return ret;
}
}
• JSR 181
• Development Models
• Processor
• Runtime
• Annotations
• Reference Implementation
• Next Steps
• Summary
• Q&A
2005 JavaOneSM Conference | Session TS-7964 | 45
Maintenance Release
• WSDL 2.0
• SOAP 1.2
• Support of JSR 250 Common Annotations
• Improving the quality of service
• Buffering
• Transactional support
• Reliability
• Callbacks
• Conversations
• Policy
• Beyond J2EE platform security
2005 JavaOneSM Conference | Session TS-7964 | 47
Summary
Related Specs
• JSR 101 Java API for XML-based RPC (JAXRPC
• http://jcp.org/en/jsr/detail?id=101
• JSR 109 J2EE™ Platform Web Services
• http://jcp.org/en/jsr/detail?id=109
• JSR 175 Java Language Metadata
• http://jcp.org/en/jsr/detail?id=175
• JSR 224 JAX-WS 2.0
• http://www.jcp.org/en/jsr/detail?id=224
2005 JavaOneSM Conference | Session TS-7964 | 49
Submit Session Evaluations for Prizes!
Your opinions are important to Sun
• You can win a $75.00 gift certificate to the on-site Retail
Store by telling Sun what you think!
• Turn in completed forms to enter the daily drawing
• Each evaluation must be turned in the same day as
the session presentation
• Five winners will be chosen each day (Sun will send
the winners email)
• Drop-off locations: give to the room monitors or use any
of the three drop-off stations in the Northand South Halls
Note: Winners on Thursday, 6/30, will receive and can
redeem certificates via email.
2005 JavaOneSM Conference | Session TS-7964 | 50
Q&A