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}}CreditCard creditCard = new CreditCard();creditCard.setNumber("12341234");creditCard.setExpiryDate("10/10");creditCard.setType("VISA");creditCard.setControlNumber(1234);CardValidator cardValidator = cardValidatorService.getCardValidatorPort();System.out.println(cardValidator.validate(creditCard));This Main class creates an instance of the CreditCard object, sets some data, gets injected a referenceof the web service, invokes the validate() method, and displays the result (true or false depending onwhether the credit card is valid). The interesting thing is that the consumer does not have any of theseclasses. The CardValidatorService, CardValidator, and CreditCard are totally unknown to the consumer.This code will not compile until all these classes are generated.Generating Consumer’s Artifacts and Packaging <strong>with</strong> MavenBefore compiling the consumer Main class, you need to generate the artifacts <strong>with</strong> the wsimport tool. Thegood news is that Maven has a wsimport goal, and this goal is executed automatically during thegenerate-sources life-cycle phase. As described in Chapter 1, Maven uses a rich life cycle to buildapplications. The generate-sources phase is used to generate code and is executed before compilation.The only thing to do is tell this wsimport goal where to find the WSDL document. You know thisinformation because you’ve deployed the web service into <strong>GlassFish</strong>, and you have displayed thecontent of the WSDL. Its location is at:http://localhost:8080/chapter14-service-2.0/CardValidatorService?wsdlThe pom.xml file in Listing 14-27 also specifies the needed dependencies, the jaxws-rt version (2.2),as well as the JDK version (1.6). The Main class is packaged in a jar file, and, like every jar file, it has aMETA-INF\MANIFEST.MF file. This file can be used to define some metadata about the jar, and that’s whatyou do when you use the maven-jar-plugin. You add a Main-Class element to the MANIFEST pointing tothe consumer Main class. This will allow execution of the jar file.Listing 14-27. The pom.xml File Generates the Consumer Artifacts and Packages4.0.0com.apress.javaee6chapter14-consumerjar2.0447

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

Saved successfully!

Ooh no, something went wrong!