O'Reilly logo

Java SOA Cookbook by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Web Service That Uses Complex Types Based on Custom WSDL and a Custom Schema

Problem

You have to program in the real world, not Hello World, so you want to write a web service that sends and receives complex types based on a schema that you have written. That schema is referred to by a WSDL that you have written, and you want to be sure to maintain the constraints specified in your schema. You are not using a Provider, but a class annotated with @WebService, so you need to generate portable types from the schema before your web service will compile.

Solution

Basically, you will use the @WebService.wsdlLocation annotation and generate your classes at the right point in your build with the XJC Ant task.

Discussion

You will create a Credit web service that defines a single operation: authorize. It will accept a CreditCard complex type and execute some business logic to determine what amount the card should be authorized for. It will then return a custom Authorization Java type.

You’ll write each artifact in the order you would in the real world: the schema, the WSDL, the Java web service, and the build script that puts it all together and deploys it.

Schema

The schema in Example 7-1 contains elements that specify parts of a credit card and an authorization amount. The idea in this solution is to create a complex schema, such as you might use in the real world, that is still not overly long.

This schema is suitable for use with a parameter style of bare because the two elements defined ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required