1. Trang chủ
  2. » Công Nghệ Thông Tin

Developing Web Services with Apache Axis 2 phần 6 pptx

22 284 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 22
Dung lượng 1,44 MB

Nội dung

Chapter Sending and receiving complex data structures 111 Choose the fault, in the Properties window, set its name to f01: Choose to create a new message: Enter the name for the message: Set the one and only part to a new XML element By default it should be of type xsd:string which is what you want here Create the second fault similarly Set the message name to queryInvalidQty, set the XML element to whose type is xsd:int Finally it should be like: 112 Chapter Sending and receiving complex data structures Next, create the binding for the two faults Choose the binding and click "Generate Binding Content" in the Properties window: Choose it It represents the binding Click here Check "Overwrite existing binding information" and then click "Finish": Chapter Sending and receiving complex data structures 113 This will generate the binding portion: Finally go into the schema index to delete the unused elements created by Eclipse: 114 Chapter Sending and receiving complex data structures They were created when you added the faults Similarly, choose "Window | Show View | Outline" to show the outline of the WSDL file as shown below Right click and delete the unused messages such as query_faultMsg and query_faultMsg1: Now, generate the service and client stubs and refresh the files in Eclipse You will find some new Java classes: Chapter Sending and receiving complex data structures class QueryInvalidProductId extends Exception { InvalidProductId faultMessage; } class InvalidProductId { String invalidProductId; } 115 A fault message is mapped to a Java exception Its one and only part (an XML element) is mapped to a field As usual, an XML element such as the element is mapped to a Java class It wanted to extend String, but String is a final class So the string is mapped to a field class QueryInvalidQty extends Exception { InvalidQty faultMessage; } class InvalidQty { int invalidQty; } The method signature in BizServiceSkeletonInterface has also been updated to throw such exceptions: public interface BizServiceSkeletonInterface { public ProductQueryResult query(ProductQuery productQuery) throws QueryInvalidProductId, QueryInvalidQty; } Now modify your implementation code: public class BizServiceImpl implements BizServiceSkeletonInterface { public ProductQueryResult query(ProductQuery productQuery) throws QueryInvalidProductId, QueryInvalidQty { ProductQueryResult result = new ProductQueryResult(); QueryItemType[] queryItems = productQuery.getQueryItem(); for (int i = 0; i < queryItems.length; i++) { QueryItemType queryItem = queryItems[i]; if (!queryItem.getProductId().startsWith("p")) { QueryInvalidProductId fault = new QueryInvalidProductId(); InvalidProductId part = new InvalidProductId(); part.setInvalidProductId(queryItem.getProductId()); fault.setFaultMessage(part); throw fault; } if (queryItem.getQty()

Ngày đăng: 13/08/2014, 08:20

TỪ KHÓA LIÊN QUAN