Skip to main content
Published: October 14 2009, 6:11:00 AMUpdated: August 11 2022, 9:21:44 AM

How can I generate Java code stubs against Finding API WSDL using wsimport tool and make Finding API calls?


Summary

This sample uses wsimport tool that ships with JAX-WS to generate Java code stubs and demonstrates how to make Finding API calls.



Detailed Description

Software Requirements:

        Java Downloads ( (wsimport tool is available from jdk5 onwards))

Generate Java code stub using wsimport tool:

Once you have set up JAW-WS on your machine, go to the {JAX-WS install-dir}/bin directory where you will find the wsimport tool. Open command prompt, change the directory to {JAX-WS install-dir}/bin and enter the following command:

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

This will generate the required Java classes from the WSDL and you should see all the classes in the ./com/ebay/marketplace/search/v1/services directory.

Sample Java class:

/*
© 2009-2013 eBay Inc., All Rights Reserved
Licensed under CDDL 1.0 - http://opensource.org/licenses/cddl1.php
*/
 

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-APPNAME correctly
        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");

       // set the time filters
        ItemFilter endtimefromFilter = new ItemFilter();
        endtimefromFilter.setName(ItemFilterType.END_TIME_FROM);
        List<String> endtimefrom = endtimefromFilter.getValue();
        endtimefrom.add("2012-07-010T20:25:11.513Z");
        ItemFilter endtimetoFilter = new ItemFilter();
        endtimetoFilter.setName(ItemFilterType.END_TIME_TO);
        List<String> endtimeto = endtimetoFilter.getValue();
        endtimeto.add("2012-07-15T20:25:11.513Z");

        List<ItemFilter> itemFilter = req.getItemFilter();
        itemFilter.add(objFilter1);
        itemFilter.add(objFilter2);
        itemFilter.add(objFilter3);
        itemFilter.add(endtimefromFilter);
        itemFilter.add(endtimetoFilter);
      
        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());
     }
}

Set CLASSPATH and run the code sample:

Please ensure that the following are included in your classpath before you run the above Java code.

  • Include the jars in the {JAX-WS install-dir}/lib directory
  • Include the Java stub classes generated by the wsimport tool as instructed in the sample earlier.

Now you can compile FindingSample.java and run the sample.

 

How well did this answer your question?
Answers others found helpful

Got thoughts? Click the feedback button – your insights help us improve!