question

peterarsentev avatar image
0 Likes"
peterarsentev asked ·

to use ItemFilter in Java code

Hi everyone. I need to make search in ebay. I found a finding.jar and try to do. But I have some doubt with use it.

I need to make search by some params. I did some simple code that illustrate my problems

[code]

 

package test;

 

import java.util.ArrayList;

import java.util.Arrays;

import java.util.List;

 

import com.ebay.services.client.ClientConfig;

import com.ebay.services.client.FindingServiceClientFactory;

import com.ebay.services.finding.*;

 

/**

 * A sample to show eBay Finding service call using the simplified interface

 * provided by the findingKit.

 *

 * @author boyang

 *

 */

class FindByKey extends FindItemsByKeywordsRequest {

    public FindByKey() {

        this.itemFilter = new ArrayList<ItemFilter>();

    }

    public void add(ItemFilter filter) {

        this.itemFilter.add(filter);

    }

}

public class FindItem {

    public static ItemFilter buildFulter(ItemFilterType type, String value) {

        ItemFilter filter = new ItemFilter();

            filter.setName(type);

            filter.setParamValue(value);

        return filter;

    }

    public static  void main(String[] args) {

        try {

            // initialize service end-point configuration

            ClientConfig config = new ClientConfig();

            config.setEndPointAddress("http://svcs.sandbox.ebay.com/services/search/FindingService/v1");

            config.setApplicationId("AppID");

            //create a service client

            FindingServicePortType serviceClient = FindingServiceClientFactory.getServiceClient(config);

            FindByKey request = new FindByKey();

            request.add(buildFulter(ItemFilterType.CURRENCY, "USD"));

            request.add(buildFulter(ItemFilterType.MIN_BIDS, "0.1"));

            request.add(buildFulter(ItemFilterType.MAX_BIDS, "10.0"));

            //set request parameters

            request.setKeywords("Harry Potter");

            PaginationInput pi = new PaginationInput();

            pi.setEntriesPerPage(10);

            request.setPaginationInput(pi);

 

            //call service

            FindItemsByKeywordsResponse result = serviceClient.findItemsByKeywords(request);

            System.out.println("Ack = "+result.getAck());

            System.out.println("Find " + result.getSearchResult().getCount() + " items." );

            List<SearchItem> items = result.getSearchResult().getItem();

            for(SearchItem item : items) {

                System.out.println("Items : " + item.getTitle());

                Amount amount = item.getListingInfo().getBuyItNowPrice();

                if (amount != null) {

                    System.out.println("Price : " + amount.getValue() + " " + amount.getCurrencyId());

                }

            }

 

        } catch (Exception ex) {

            // handle exception if any

            ex.printStackTrace();

        }

    }

}

[code]

But when I run it I have exceptions. 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

  <soapenv:Header/>

  <soapenv:Body>

    <findItemsByKeywordsResponse xmlns="http://www.ebay.com/marketplace/search/v1/services">

      <ack>Failure</ack>

      <errorMessage>

        <error>

          <errorId>46</errorId>

          <domain>Marketplace</domain>

          <severity>Error</severity>

          <category>Request</category>

          <message>Value is required for item filter, CURRENCY.</message>

          <subdomain>Search</subdomain>

          <parameter>CURRENCY</parameter>

        </error>

      </errorMessage>

      <version>1.11.0</version>

      <timestamp>2011-11-03T08:23:17.373Z</timestamp>

    </findItemsByKeywordsResponse>

  </soapenv:Body>

</soapenv:Envelope>

Can you help me what I do wrong?

Thanks.

java-itemfilter
· 1
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I found how I can fix it.

[code]

 

class Filter extends ItemFilter {
    public Filter() {
        this.value = new ArrayList<String>();
    }
 
    public void addValue(String value) {
        this.value.add(value);
    }
}
public class FindItem {
    public static ItemFilter buildFulter(ItemFilterType type, String value) {
        Filter filter = new Filter();
        filter.setName(type);
        filter.addValue(value);
        return filter;
    }

[/code]

 

But actually it is very weird why I must hack this class. I didn't find how I can take some filter params in ItemFilter class.

if anybody know how to do it. Please can you tell me? :)

0 Likes 0 · ·

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.