posts - 32, comments - 153, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Web Service学习日记-11月30日-访问Amazon

Posted on 2006-11-30 23:32 Zou Ang 阅读(737) 评论(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里面部署?

只有注册用户登录后才能发表评论。


网站导航: