eBay大中华区API开发者平台 开发者专区

搜 索
首页>API开发者平台>技术文档>Finding API - Jave stub代码

技术文档

问题
Finding API - Jave stub代码
解答
0
人觉得答案有帮助)

总述

此例程使用JAX-WS附带的wsimport工具生成Java stub代码 ,并展示了对Finding API的调用方法。



详细描述

软件需求:

使用wsimport工具生成Java代码:

安装JAW-WS后,你可以在{JAX-WS install-dir}/bin目录下找到wsimport 工具。打开命令行控制器,输入下面的命令以更改目录:

wsimport -extension http://developer.ebay.com/webservices/finding/latest/FindingService.wsdl  

通过上述步骤可从WSDL生成需要的Java类, 你可以在此目录中看到所有生成的类:./com/ebay/marketplace/search/v1/services 

示例的Java类:

import java.util.Collections; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 

import javax.xml.ws.BindingProvider; 
import javax.xml.ws.handler.MessageContext; 

import com.ebay.marketplace.search.v1.services.FindItemsAdvancedRequest; 
import com.ebay.marketplace.search.v1.services.FindItemsAdvancedResponse; 
import com.ebay.marketplace.search.v1.services.FindingService; 
import com.ebay.marketplace.search.v1.services.FindingServicePortType; 
import com.ebay.marketplace.search.v1.services.ItemFilter; 
import com.ebay.marketplace.search.v1.services.ItemFilterType; 
import com.ebay.marketplace.search.v1.services.OutputSelectorType; 
import com.ebay.marketplace.search.v1.services.SortOrderType; 

public class FindingSample 

          
     public static void main(String[] args) 
     {      
         
        String strBaseURL = "http://svcs.ebay.com/services/search/FindingService/v1"; 
        FindingService service = new FindingService(); 
        FindingServicePortType port     = service.getFindingServiceSOAP12PortHttp(); 
           
        BindingProvider bp = (BindingProvider) port; 
        Map<String, Object> requestProperties = bp.getRequestContext();  
        Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();  
        //Set the headers 
        httpHeaders.put("X-EBAY-SOA-MESSAGE-PROTOCOL", Collections.singletonList("SOAP12")); 
        httpHeaders.put("X-EBAY-SOA-OPERATION-NAME", Collections.singletonList("findItemsAdvanced"));  
        
        //Edit the following line to insert your AppID to set the X-EBAY-SOA-SECURITY-APPNAMEcorrectly 
        httpHeaders.put("X-EBAY-SOA-SECURITY-APPNAME", Collections.singletonList("YOUR_APP_ID_HERE")); 
         
        requestProperties.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders); 
        requestProperties.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, strBaseURL); 

        FindItemsAdvancedRequest req = new FindItemsAdvancedRequest(); 
        List<OutputSelectorType> opSelector = req.getOutputSelector(); 
        opSelector.add(OutputSelectorType.SELLER_INFO); 
         
        ItemFilter objFilter1 = new ItemFilter(); 
        objFilter1.setName(ItemFilterType.AVAILABLE_TO); 
        objFilter1.getValue().add("US"); 
         
        ItemFilter objFilter2 = new ItemFilter(); 
        objFilter2.setName(ItemFilterType.LISTING_TYPE); 
        objFilter2.getValue().add("All"); 

        ItemFilter objFilter3 = new ItemFilter(); 
        objFilter3.setName(ItemFilterType.HIDE_DUPLICATE_ITEMS); 
        objFilter3.getValue().add("true"); 

        List<ItemFilter> itemFilter = req.getItemFilter(); 
        itemFilter.add(objFilter1); 
        itemFilter.add(objFilter2); 
        itemFilter.add(objFilter3); 
                
        List<String> catID = req.getCategoryId(); 
        catID.add("279");

        req.setSortOrder(SortOrderType.END_TIME_SOONEST); 
        req.setKeywords("Harry Potter"); 

        FindItemsAdvancedResponse res = port.findItemsAdvanced(req); 
        System.out.println("Search Count: " + res.getSearchResult().getCount()); 
     } 

 

设置CLASSPATH并运行例程:

运行Java代码前,保证你的类文件中已包含:

1. {JAX-WS install-dir}/lib目录中的所有jar包 2. wsimport工具生成的Java stub类

现在你可以编译FindingSample.java并运行例程了。


答案对您有帮助吗?

是,对我很有帮助
否,没解决我的问题