站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Netbeans 专题Launching the eBay Java SDK API Calls Demo Sample Application from NetBeans 4.1

Launching the eBay Java SDK API Calls Demo Sample Application from NetBeans 4.1

摘要: This is a follow up to the 23 Feb 2005 article, Using NetBeans to Develop with the eBay SDK for Java. As I continued to experiment with eBay's Java SDK, I found one sample application, the API Calls Demo, an invaluable resource for helping me learn the APIs. In this article, I show you how to create a NetBeans project that will will run and debug the API Calls Demo sample application

Setting Up Your Environment

This article assumes you have already followed the steps for setting up your environment outlined in Using NetBeans to Develop with the eBay SDK for Java.

Creating the eBay API Calls Demo Project

  1. Choose File > New Project (Ctrl+Shift-N).
  2. Select Java Project with Existing Ant Script under the General Category. This will create what's known as a Free-Form Project in NetBeans. To learn more about this project type, see Advanced Free-Form Project Configuration.
  3. For the Location, browse to the samples/apiCallsDemo folder where you installed the eBay SDK. The wizard will locate the build script and recommend a Project Name. Select Next.
  4. The wizard located the Compile, Clean, Javadoc and run targets. Select next.
  5. Add the application's source package folder, which is simply src. If you've correctly configured NetBeans to start with the –jdkhome argument, the Source Level will say JDK 1.4. Click Next.
  6. Add the eBay SDK JARs to the project's classpath:
    1. choose Add JAR/Folder
    2. Select all the JAR files in the <eBay SDK Install Location>/lib/ directory. These should be attributes.jar, ebaycalls,jar, ebaysdkcore.jar, eps.jar and helper.jar.
    3. Choose Add JAR/Folder again
    4. Select axis.jar from the <eBay SDK Install Location>/externalLib/axis-1_1/ directory.
  7. Click Finish.

Building and Running the Application

Building the Application

Select Build > Build Main Project, press F11, or right-click the project node and choose Build Project from the context menu.

Running the Application

Select Run > Run Main Project, press F6, or right-click the project node and choose Run Project from the context menu.

The project runs, however, you have to configure your account information every time you run the application, which can be quite tedious.





Let's fix that.


Enhancing the API Calls Demo Application

Create a Properties File to Hold Our Account Configuration Information

  1. Select File > new File, press Ctrl + N, or right-click the project node and choose New > File/Folder...
  2. Select Properties File from the Other Category and select Next.
  3. Name the file keys and select Finish.
  4. The key.prorties file opens in the editor. Add the following properties and update with your eBay credentials:
        devId = <enter you developer ID>
        appId = <enter your application ID>
        certId = <enter your certificate ID>
        token = <enter your token>
        apiServerUrl = https://api.sandbox.ebay.com/wsapi
        epsServerUrl = http://msa-e1.ebay.com/ws/eBayISAPI.dll?EpsBasicApp
                    

Read the Properties from the Application

  1. Open FrameDemo.java
  2. In the constructor, all the following code following the first line provided:
        ApiCredential cred = new ApiCredential();
    
        // Read properties file to load developer credentials
    Properties keys = new Properties();
        try {
            keys.load(new FileInputStream("keys.properties"));
        } catch (IOException e) {
            System.out.println(e);
        }
    
        cred.seteBayToken(keys.getProperty("token"));
        ApiAccount ac = cred.getApiAccount();
        ac.setDeveloper(keys.getProperty("devId"));
        ac.setApplication(keys.getProperty("appId"));
        ac.setCertificate(keys.getProperty("certId"));
                    
  3. Press Alt + Shift + F to fix the missing imports.
  4. Replace the hard-coded strings for API and EPS Server URLs with the following:
        this.apiContext.setApiServerUrl(keys.getProperty("apiServerUrl"));
        this.apiContext.setEpsServerUrl(keys.getProperty("epsServerUrl"));
                    

Build and Run the Application Again

Press F11 to build the application and F6 to run it. The API Account dialog is now properly configured. Select and API from the list box, such as GetSearchResults and press Run.

Note, if you are behind a corporate proxy and get a ConnectException, you can add the following two lines of code to the top of FrameDemo constructor:

System.setProperty("http.proxyHost", "<your proxy host>");
System.setProperty("http.proxyPort", "<your proxy port>");





Debugging the Application

Add a debug target to build.xml

  1. Open build.xml
  2. Scroll to the bottom of the file and add the following target:
    <target name="debug" depends="compile" description="Debug Project">
        <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
        <nbjpdastart name="Sample App" addressproperty="jpda.address" transport="dt_socket">
            <classpath refid="project.class.path"/>
            <sourcepath path="${src}"/>
        </nbjpdastart>
        <java fork="true" classname="apicallsdemo.ApiCallsDemo">
            <jvmarg value="-Xdebug"/>
            <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
            <classpath refid="project.class.path"/>
        </java>
    </target>
            


Set a breakpint and Debug the Application

  1. Click on the left margin on the FrameDemo.java to set a breakpoint.
  2. Right-client the build.xml under the apiCallsDemo project node and run the debug target..
  3. From here you can step though your application, viewing locale variables, setting watches, etc. See Debugging Applications for more information.

↑返回目录
前一篇: J2ME MIDP Device Fragmentation Tutorial with Marv The Miner(2)
后一篇: Meet a NetBeans Module Writer: Jens Trapp