posts - 32, comments - 153, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Web Service學習日記-11月30日-訪問Amazon

          Posted on 2006-11-30 23:32 Zou Ang 閱讀(770) 評論(1)  編輯  收藏 所屬分類:
          今天在學習Web Service的時候得知Amazon提供了一個搜索的Web Service,于是考慮寫一個方法訪問一下看看..
          Amazon Web Service 的WSDL: http://soap.amazon.com/schemas2/AmazonWebServices.wsdl
          得到了WSDL以后,在命令行執行:
          java org.apache.axis.wsdl.WSDL2Java http://soap.amazon.com/schemas2/AmazonWebServices.wsdl
          就會在%AXIS_HOME%目錄下生成一個包結構:com.amazon.soap.*;里面有很多包,不過如果看了上面那個wsdl的話應該知道主要的類是
          AmazonSearchService和AmazonSearchPort,前面是服務,后面是調用方法的對象..

          AmazonSearchService:
          public?interface?AmazonSearchService?extends?javax.xml.rpc.Service?{
          ????
          public?java.lang.String?getAmazonSearchPortAddress();

          ????
          public?com.amazon.soap.AmazonSearchPort?getAmazonSearchPort()?throws?javax.xml.rpc.ServiceException;

          ????
          public?com.amazon.soap.AmazonSearchPort?getAmazonSearchPort(java.net.URL?portAddress)?throws?javax.xml.rpc.ServiceException;
          }

          AmazonSearchPort:
          package?com.amazon.soap;

          public?interface?AmazonSearchPort?extends?java.rmi.Remote?{
          ????
          public?com.amazon.soap.ProductInfo?keywordSearchRequest(com.amazon.soap.KeywordRequest?keywordSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?powerSearchRequest(com.amazon.soap.PowerRequest?powerSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?browseNodeSearchRequest(com.amazon.soap.BrowseNodeRequest?browseNodeSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?asinSearchRequest(com.amazon.soap.AsinRequest?asinSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductLine[]?blendedSearchRequest(com.amazon.soap.BlendedRequest?blendedSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?upcSearchRequest(com.amazon.soap.UpcRequest?upcSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?authorSearchRequest(com.amazon.soap.AuthorRequest?authorSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?artistSearchRequest(com.amazon.soap.ArtistRequest?artistSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?actorSearchRequest(com.amazon.soap.ActorRequest?actorSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?manufacturerSearchRequest(com.amazon.soap.ManufacturerRequest?manufacturerSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?directorSearchRequest(com.amazon.soap.DirectorRequest?directorSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?listManiaSearchRequest(com.amazon.soap.ListManiaRequest?listManiaSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?wishlistSearchRequest(com.amazon.soap.WishlistRequest?wishlistSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ListingProductDetails?exchangeSearchRequest(com.amazon.soap.ExchangeRequest?exchangeSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.MarketplaceSearch?marketplaceSearchRequest(com.amazon.soap.MarketplaceRequest?marketplaceSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.SellerProfile?sellerProfileSearchRequest(com.amazon.soap.SellerProfileRequest?sellerProfileSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.SellerSearch?sellerSearchRequest(com.amazon.soap.SellerRequest?sellerSearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ProductInfo?similaritySearchRequest(com.amazon.soap.SimilarityRequest?similaritySearchRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ShoppingCart?getShoppingCartRequest(com.amazon.soap.GetShoppingCartRequest?getShoppingCartRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ShoppingCart?clearShoppingCartRequest(com.amazon.soap.ClearShoppingCartRequest?clearShoppingCartRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ShoppingCart?addShoppingCartItemsRequest(com.amazon.soap.AddShoppingCartItemsRequest?addShoppingCartItemsRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ShoppingCart?removeShoppingCartItemsRequest(com.amazon.soap.RemoveShoppingCartItemsRequest?removeShoppingCartItemsRequest)?throws?java.rmi.RemoteException;
          ????
          public?com.amazon.soap.ShoppingCart?modifyShoppingCartItemsRequest(com.amazon.soap.ModifyShoppingCartItemsRequest?modifyShoppingCartItemsRequest)?throws?java.rmi.RemoteException;
          }


          我打算調用keywordSearchRequest這個方法,這個方法有一個keywordRequest參數,返回一個ProductInfo對象
          public?com.amazon.soap.ProductInfo?keywordSearchRequest(com.amazon.soap.KeywordRequest?keywordSearchRequest)?throws?java.rmi.RemoteException;
          下面是調用Web Service的類:
          /**
          ?*?org.zsu.zouang
          ?*?2006-11-30
          ?
          */

          package?org.zsu.zouang;

          import?java.rmi.RemoteException;

          import?javax.xml.rpc.ServiceException;

          import?com.amazon.soap.AmazonSearchPort;
          import?com.amazon.soap.AmazonSearchServiceLocator;
          import?com.amazon.soap.Details;
          import?com.amazon.soap.KeywordRequest;
          import?com.amazon.soap.ProductInfo;

          /**
          ?*?2006-11-30
          ?*?
          @author?Zou?Ang
          ?*?Contact?<a?href?="mailto:richardeee@gmail.com">Zou?Ang</a>
          ?
          */

          public?class?MyAmazonClient?{

          ????
          /**
          ?????*?
          @param?args
          ?????
          */

          ????
          public?static?void?main(String[]?args)?{
          ????????KeywordRequest?keyword?
          =?new?KeywordRequest();
          ????????keyword.setKeyword(
          "Java");
          ????????keyword.setMode(
          "books");
          ????????keyword.setTag(
          "D3HW0PG66IPLAM");
          ????????keyword.setDevtag(
          "D3HW0PG66IPLAM");
          ????????keyword.setPage(
          "1");
          ????????keyword.setType(
          "heavy");
          ????????keyword.setSort(
          null);
          ????????keyword.setVariations(
          null);
          ????????keyword.setLocale(
          null);
          ????????
          //?TODO?Auto-generated?method?stub
          ????????try?{
          ????????????AmazonSearchPort?port?
          =?new?AmazonSearchServiceLocator().getAmazonSearchPort();
          ????????????ProductInfo?info?
          =?port.keywordSearchRequest(keyword);
          ????????????System.out.println(
          "Number?of?Results?:"?+?info.getTotalResults());
          ????????????Details[]?details?
          =?info.getDetails();
          ????????????
          for(Details?d?:?details){
          ????????????????System.out.println(
          "ISBN?:"?+?d.getIsbn()?+?"?Name:"?+?d.getProductName());
          ????????????}

          ????????}
          ?catch?(RemoteException?e)?{
          ????????????
          //?TODO?Auto-generated?catch?block
          ????????????e.printStackTrace();
          ????????}
          ?catch?(ServiceException?e)?{
          ????????????
          //?TODO?Auto-generated?catch?block
          ????????????e.printStackTrace();
          ????????}

          ????}

          }
          返回的結果:
          -?Unable?to?find?required?classes?(javax.activation.DataHandler?and?javax.mail.internet.MimeMultipart).?Attachment?support?is?disabled.
          Number?of?Results?:
          5161
          ISBN?:
          0072253606?Name:SCJP?Sun?Certified?Programmer?for?Java?5?Study?Guide?(Exam?310-055)?(Certification?Press?Study?Guides)
          ISBN?:
          0596007124?Name:Head?First?Design?Patterns?(Head?First)
          ISBN?:
          0553803905?Name:Ship?of?Ghosts:?The?Story?of?the?USS?Houston,?FDR's?Legendary?Lost?Cruiser,?and?the?Epic?Saga?of?Her?Survivors
          ISBN?:0596009410?Name:Mac?OS?X?Tiger:?Missing?Manual
          ISBN?:
          0596101996?Name:JavaScript:?The?Definitive?Guide
          ISBN?:
          0131483986?Name:Java?How?to?Program?(6th?Edition)?(How?to?Program?(Deitel))
          ISBN?:
          0596009208?Name:Head?First?Java,?2nd?Edition
          ISBN?:
          1591968097?Name:What?is?WebSphere??Java,?J2EE,?Portal?and?Beyond!?(Demystifying?IBM's?Middle?Tier?Technology,?Vol.?1)
          ISBN?:0596005407?Name:Head?First?Servlets?and?JSP:?Passing?the?Sun?Certified?Web?Component?Developer?Exam?(SCWCD)
          ISBN?:
          1932394613?Name:Ajax?in?Action

          下一步可能打算寫個GUI的Amazon搜索客戶端

          評論

          # re: Web Service學習日記-11月30日-訪問Amazon[未登錄]  回復  更多評論   

          2007-04-22 22:54 by tony
          想問調用amazon web服務如何在ide里面部署?
          主站蜘蛛池模板: 天等县| 融水| 宁晋县| 蕲春县| 苏尼特右旗| 水城县| 锡林浩特市| 平果县| 凤庆县| 高碑店市| 大同县| 新民市| 克山县| 阿瓦提县| 武隆县| 大丰市| 本溪| 郧西县| 斗六市| 广汉市| 双辽市| 揭阳市| 峨边| 余江县| 江华| 新沂市| 莱西市| 镇雄县| 阿图什市| 海门市| 闸北区| 新田县| 老河口市| 阿勒泰市| 大城县| 丰台区| 壤塘县| 宾阳县| 平潭县| 宿松县| 湘西|