12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 14 ■ SOAP WEB SERVICES• WSDL mapping annotations: These annotations belong to the javax.jws packageand allow you to change the WSDL/<strong>Java</strong> mapping. The @WebMethod, @WebResult,@WebParam, and @OneWay annotations are used on the web service to customize thesignature of the exposed methods.• SOAP binding annotations: These annotations belong to the javax.jws.soappackage and allow customizing of the SOAP binding (@SOAPBinding and@SOAPMessageHandler).Like all the other <strong>Java</strong> <strong>EE</strong> 6 specifications, web services annotations can be overridden by an XMLdeployment descriptor (webservices.xml), which is optional. Let’s take a closer look at the WSDLmapping annotations.@WebServiceThe @javax.jws.WebService annotation marks a <strong>Java</strong> class or interface as being a web service. If useddirectly on the class (as in all examples so far), the annotation processor of the container will generatethe interface, so the following snippets of code are equivalent. Following is the annotation on the class:@WebServicepublic class CardValidator {...}And this shows the annotation on an interface implemented by a class:@WebServicepublic interface CCValidator {...}public class CardValidator implements CCValidator {...}The @WebService annotation has a set of attributes (see Listing 14-15) that allow you to customizethe name of the web service in the WSDL file (the or element) and itsnamespace, as well as change the location of the WSDL itself (the wsdlLocation attribute).Listing 14-15. The @WebService API@Retention(RUNTIME) @Target(TYPE)public @interface WebService {String name() default "";String targetNamespace() default "";String serviceName() default "";String portName() default "";String wsdlLocation() default "";String endpointInterface() default "";}When you use the @WebService annotation, all public methods of the web service are exposed exceptwhen using the @WebMethod annotation.434

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!