Using the SOAP Web Service APIs

KonaKart has five major interface types - the direct POJO interface, the SOAP interface, and, if you have the Enterprise Edition, the JSON interface, the JAXWS interface and the RMI interface. The Business Edition has all the interfaces the Enterprise Edition has except RMI. Each of these support exactly the same interface calls. Which one you choose will depend on many factors but the best performance is likely to come from the direct interface, whereas the SOAP, JAXWS, RMI and JSON interfaces give greater flexibility in distributed implementations and inter-operability. Using JSON over low-bandwidth networks and on mobile devices will probably give the best performance in these environments.

It's remarkably simple to use KonaKart's SOAP interfaces. Although it is easier to use the SOAP engines that are already available in the KonaKart jars (see later for the recommended approach) if your IDE can create client stubs from WSDL then you can use that to create your SOAP clients or, if you prefer, you can use AXIS as in the downloadable example which follows.

There are two WSDL definitions; one for the KonaKart Application API, and the other for the KonaKart Admin API. They can be seen at these URLs:

Enable the SOAP Web Services

Since version 3.2.0.0 of KonaKart, the SOAP APIs are disabled during the installation process. The purpose of this decision is to make the KonaKart engines more secure. The process for enabling the APIs is very simple and can be achieved by running an ant target called enableWebServices in the KonaKart/custom directory as shown below. (An equivalent ANT task called enable_JSON is provided to enable JSON).


C:\KonaKart\custom>.\bin\ant enableWebServices
Buildfile: build.xml

enableWebServices:
     [echo] Allow all methods in WSDD files:

BUILD SUCCESSFUL
Total time: 0 seconds

The ant target modifies the files called server-config.wsdd present in the WEB-INF directory of the KonaKart store front and admin applications. The modification is simple:


The line

<parameter name="allowedMethods" value="none"/>

is changed to

<parameter name="allowedMethods" value="*"/>

Securing the SOAP Web Services

KonaKart web services use the AXIS 1 web services framework in a standard manner. This allows you to add handlers in the request and response pipelines of the web service message processors for a variety of purposes. Two common examples are for web service monitoring and security.

A step-by-step guide to implementing WS-Security for the KonaKart web services is provided in the download kits under java_soap_examples in a document called KonaKart-WS-Security.txt.

Step-by-step guide to using the SOAP APIs:

  1. The SOAP examples kit that is provided in every KonaKart download kit (you can find them under the installation directory in a directory called java_soap_examples) contains everything you need to build a simple SOAP client from the KonaKart Application WSDL. First verify that you have the kit in your version of KonaKart.

  2. Next, ensure that KonaKart is running on your machine. After the default installation you should be able to start KonaKart by clicking on the "Start KonaKart Server" start-up icon (on Windows) or by executing the {Konakart Home}/bin/startkonakart.sh script (on *nix). You need KonaKart to be running in order to get responses so your SOAP calls that you will make with the examples.

  3. Check that the KonaKart server has started OK - a quick way would be to see if the application appears at http://localhost:8780/konakart

  4. Open up a console window and change directory to the location of the java_soap_examples, for example this would be:

    C:\> cd C:\KonaKart\java_soap_examples on Windows.

  5. Ensure that the environment variable JAVA_HOME is set correctly. On Windows, a suitable setting might be:

    JAVA_HOME=C:\jdk1.6.0_22

  6. Ensure that the JAVA_HOME/bin directory appears on your PATH. On Windows, this might look something like this:

    Path=C:\jdk1.6.0_22\bin;C:\WINDOWS\system32;C:\WINDOWS

    {You could also check that when you issue "java -version" you get the java version you expect}

  7. If you already have ANT installed, ANT_HOME is defined and ANT's bin directory is on your PATH you can skip the next two sections. If you don't have ANT installed you can use the cut-down version of ANT that we include in the KonaKart download kit, but you must set the following environment variables. Ensure that the environment variable ANT_HOME is set correctly in the command shell that you are executing (you probably don't want to change the environment variable globally). On Windows, if you installed KonaKart to the default location (C:\Program Files\KonaKart), it would be (note the slashes):

    ANT_HOME=C:/Program Files/KonaKart/custom/bin

  8. Ensure that the ANT_HOME/bin directory appears on your PATH. On Windows, this might look something like this:

    Path=C:\jdk1.6.0_22\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\KonaKart\custom\bin

    As a sanity check that you are set up ready to build the examples, check that you see the following when you issue a "ant -p" command:

    
    C:\KonaKart\java_soap_examples>ant -p
    Buildfile: build.xml
    
    Main targets:
    
     axis_client_generation  Generate client stubs from the WSDL
     build                   Creates the SOAP clients, compiles and runs a little example
     clean                   Clears away everything that's created during a build
     compile                 Compile the examples
     run                     Run the little example program
    Default target: build
    
    

    [The KonaKart download kit contains just enough of ANT for you to build the examples. For subsequent development using ANT you should consider installing a complete ANT installation - check the Apache ANT site for details]

  9. Simply execute the "ant" command to compile, then run, the simple SOAP example.

    If all is well you should see the following output:

    
    C:\KonaKart\java_soap_examples>..\custom\bin\ant
    Buildfile: build.xml
    
    clean:
         [echo] Cleanup...
    
    axis_client_generation:
         [echo] Create the KonaKart client stubs from the WSDL
    
    compile:
         [echo] Compile the examples
        [mkdir] Created dir: C:\KonaKart\java_soap_examples\classes
        [javac] Compiling 59 source files to C:\KonaKart\java_soap_examples\classes
        [javac] Note: Some input files use unchecked or unsafe operations.
        [javac] Note: Recompile with -Xlint:unchecked for details.
    
    run:
         [java] First the low-level version...
         [java]
         [java] There are 239 countries
         [java] There are 10 manufacturers
         [java] The default currency is: USD
         [java] 29 products found
         [java] 29 length of product array
         [java]
         [java] Next the recommended high-level version...
         [java]
         [java] There are 239 countries
         [java] There are 10 manufacturers
         [java] The default currency is: USD
         [java] 29 products found
         [java] 29 length of product array
    
    build:
    
    BUILD SUCCESSFUL
    Total time: 10 seconds
    
    

    The code is very simple; here are a couple of extracts from AxisExample.java. This is the lower-level version:

    
    KKWSEngIf port = new KKWSEngIfServiceLocator().getKKWebServiceEng();
    
    // make some example calls
    
    Country[] countries = port.getAllCountries();
    System.out.println("There are " + countries.length + " countries");
    
    Manufacturer[] manufacturers = port.getAllManufacturers();
    System.out.println("There are " + manufacturers.length + " manufacturers");
    
    Currency curr = port.getDefaultCurrency();
    System.out.println("The default currency is: " + curr.getCode());
    
    

    This is the recommended higher-level version:

    
    EngineConfigIf engConfig = new EngineConfig();
    engConfig.setMode(EngineConfig.MODE_SINGLE_STORE);
                
    KKEngIf engine = new KKWSEng(engConfig);
    
    // make some example calls
    
    CountryIf[] countries = engine.getAllCountries();
    System.out.println("There are " + countries.length + " countries");
    
    ManufacturerIf[] manufacturers = engine.getAllManufacturers();
    System.out.println("There are " + manufacturers.length + " manufacturers");
    
    CurrencyIf curr = engine.getDefaultCurrency();
    System.out.println("The default currency is: " + curr.getCode());
    
    

    Notes:

    • If you've installed to a port other than 8780 and you wish to generate your client code you will have to modify the konakart.wsdl file to match (change the port number right at the end of the file) then re-run the client stub generation in the ANT file as above.

    • If you've installed to a port other than 8780 but do not wish to generate your client code (as in the case of using the recommended higher-level technique) you will have to modify the konakart_axis_client.properties and konakartadmin_axis_client.properties file to define your SOAP endpoint locations.

    • The files konakart_axis_client.properties and konakartadmin_axis_client.properties are used to define the locations of the respective web services. Therefore if these locations are not the default URLs you will need to modify these files as appropriate.

    • If you get "connection refused" - check that your firewall isn't blocking your client calls and that the endpoints defined in the konakart_axis_client.properties and konakartadmin_axis_client.properties are actually responding correctly.

    • Remember you have to enable the web services - see above for enabling the web services .