Java Reference
In-Depth Information
String cardNumber = creditCard.getCardNumber();
//create custom type for return
Authorization auth = new Authorization();
//business logic here
if (cardNumber.startsWith("4")) {
auth.setAmount(2500.0);
} else {
auth.setAmount(0.0);
}
LOGGER.debug("Returning auth for amt: " + auth.getAmount());
return auth;
}
}
Let's first examine the authorize business method. It accepts a CreditCard type and returns
an Authorization type. Neither of these exists anywhere as Java classes; they are generated
by XJC within your build before compiling the service. You need to do some tweaking in the
annotations to make your service match up with the WSDL we've defined.
You annotate your method with the @WebMethod annotation. Normally all of the public meth-
ods in a class that is annotated with @WebService will be exposed in a generated WSDL as
operations. But you hand-coded ouyr WSDL, so you want to match up the method name with
the name of the operation specified in the WSDL as <operation name="authorize"> . We
use the @WebMethod.operationName property to do so.
Next include binding information, indicating that you want to use a style of document, a use
of literal, and a parameterStyle of bare. (You can read more about these in Specifying the
SOAP Binding Style, Use, and Parameter Style .) The main thing here is that you don't have
any wrapper types, so you need to use a bare parameter style. Notice that you specify this on
the class, and not a particular method because you cannot mix these styles within the same
service.
Both the return type and the method parameter specify their namespace, and their name prop-
erties match the part names in the WSDL.
As for the body of the method, your business logic simply returns an authorization in the
amount of $2,500 if your card number starts with a 4, and it returns 0 otherwise. It sets this
return value into the generated Authorization type, which is returned to the client.
Example 7-4 shows what the messages for each of these types looks like on the wire.
Example7-4.SOAP message credit card request
Search WWH ::




Custom Search