• Welcome to KonaKart Community Forum. Please login or sign up.
 

SOAP and admin

Started by sdyck, April 21, 2009, 09:09:52 pm

Previous topic - Next topic

sdyck

Hi, would anyone know why I always get null as my sessionID when calling KKWSAdminIf port.login(default,default)???  I was able to launch the Axis example fine but when I created a new test soap to insert a product into the db I keep getting this error:



faultDetail:
   {http://xml.apache.org/axis/}hostname:konakart.com

java.rmi.RemoteException: Exception Message = The String parameter called sessionId (value=null) must be given a value. It cannot be set to null or be left empty.; nested exception is:
   com.konakartadmin.app.KKAdminException: Exception Message = The String parameter called sessionId (value=null) must be given a value. It cannot be set to null or be left empty.
   at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
   at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
   at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
   at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
   at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
   at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
   at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
   at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
   at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
   at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
   at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
   at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
   at org.apache.axis.client.Call.invoke(Call.java:2767)
   at org.apache.axis.client.Call.invoke(Call.java:2443)
   at org.apache.axis.client.Call.invoke(Call.java:2366)
   at org.apache.axis.client.Call.invoke(Call.java:1812)
   at com.konakartadmin.ws.KKWSAdminSoapBindingStub.insertProduct(KKWSAdminSoapBindingStub.java:7124)
   at com.konakart.InsertProduct.main(InsertProduct.java:144)

heidi

You will of course need a valid sessionId to be able to call many of the interfaces on the engines.

So, the obvious question is, are you using a valid username and password?



sdyck

Yes of course I am .... below is the source to my InsertProduct.java I am using to test ... I used the wsdl from web to generate the proxy classes:


package com.konakart;

import java.math.BigDecimal;
import java.util.Date;

import com.konakartadmin.app.AdminCategory;
import com.konakartadmin.app.AdminProduct;
import com.konakartadmin.app.AdminProductAttribute;
import com.konakartadmin.app.AdminProductDescription;
import com.konakartadmin.ws.KKWSAdminIf;
import com.konakartadmin.ws.KKWSAdminIfServiceLocator;



public class InsertProduct{

   private static String DEFAULT_USERNAME = "admin@konakart.com";

    private static String DEFAULT_PASSWORD = "princess";
   
   public InsertProduct(){
      
   }
   
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        try
        {

           
           
           KKWSAdminIf port = new KKWSAdminIfServiceLocator().getKKWSAdmin();
           
           
            /*
             * Instantiate an AdminProduct object and set some of its attributes
             */
            AdminProduct prod = new AdminProduct();
            // Assuming we have a manufacturer in the DB with id==1
            prod.setManufacturerId(1);
            // Image that will be used in the application for the product
            prod.setImage("test/test.gif");
            // Product model
            prod.setModel("test model");
            // Product price before applying tax
            prod.setPriceExTax(new BigDecimal(55.99));
            // Quantity of product in stock
            prod.setQuantity(20);
            // Product status: 1=active, 0=inactive
            prod.setStatus((byte) 1);
            // The tax class of the product. Used to determine how much tax to apply.
            prod.setTaxClassId(1);
            // Weight of product. Can be used to calculate shipping cost.
            prod.setWeight(new BigDecimal(5));
            // Defines when the product will be available
            //prod.setDateAvailable(new Date());
            // Custom attribute. Can contain custom data.
            prod.setCustom1("custom1");
            // Custom attribute. Can contain custom data.
            prod.setCustom2("custom2");
            // Custom attribute. Can contain custom data.
            prod.setCustom3("custom3");
            // Custom attribute. Can contain custom data.
            prod.setCustom4("custom4");
            // Custom attribute. Can contain custom data.
            prod.setCustom5("custom5");

            /*
             * An Admin Product object has an array of AdminProductDescription objects, each one of
             * which contains a name, description and url for a different language. The url is
             * language dependent since it can point to the home page of the product for the country
             * in question.
             */
            AdminProductDescription[] descriptions = new AdminProductDescription[2];
            descriptions[0] = new AdminProductDescription();
            descriptions[0].setDescription("Test prod - English");
            descriptions[0].setLanguageId(1);
            descriptions[0].setName("Test Prod - E");
            descriptions[0].setUrl("www.testprod.co.uk");
            descriptions[1] = new AdminProductDescription();
            descriptions[1].setDescription("Test prod - German");
            descriptions[1].setLanguageId(2);
            descriptions[1].setName("Test Prod - D");
            descriptions[1].setUrl("www.testprod.de");
            prod.setDescriptions(descriptions);

            /*
             * An Admin Product may belong to one or more categories. We create an array of
             * categories and add one category to the array which we then add to the product.
             */
            AdminCategory cat = new AdminCategory();
            // Assuming we have a category with id==1 in the database
            cat.setId(1);
            AdminCategory[] catArray = new AdminCategory[1];
            catArray[0] = cat;
            prod.setCategories(catArray);

            /*
             * The following Admin Product Attributes are optional. They are used if the product has
             * options which can be selected to configure the product. These options may add or
             * subtract a value from the final price. i.e. Size "extra small" may be -$10.00 from
             * the product price while size "extra large" may be +$10.00.
             */

            // We will add two attributes
            AdminProductAttribute[] attrs = new AdminProductAttribute[2];

            // Attribute 1
            AdminProductAttribute prodAttr1 = new AdminProductAttribute();
            // This points to the option in the products_options table with id = 4 (Memory in demo
            // DB)
            prodAttr1.setOptionId(4);
            // This points to the option value in the products_options_values table with id = 1 (4MB
            // in demo DB)
            prodAttr1.setOptionValueId(1);
            // This option costs an extra 20 if selected
            prodAttr1.setPrice(new BigDecimal(20));
            prodAttr1.setPricePrefix("+");
            attrs[0] = prodAttr1;

            // Attribute 2
            AdminProductAttribute prodAttr2 = new AdminProductAttribute();
            // This points to the option in the products_options table with id = 3 (Model in demo
            // DB)
            prodAttr2.setOptionId(3);
            // This points to the option value in the products_options_values table with id = 5
            // (Value model
            // in demo DB)
            prodAttr2.setOptionValueId(5);
            // The product price is reduced by 10 if this option is selected
            prodAttr2.setPrice(new BigDecimal(10));
            prodAttr2.setPricePrefix("-");
            attrs[1] = prodAttr2;

            // Add the attributes to the product
            prod.setAttributes(attrs);
           
           
            String sessionId = port.login(DEFAULT_USERNAME, DEFAULT_PASSWORD);
            // Insert the product and get the product Id
            int prodId = port.insertProduct(null, prod);

            System.out.println("Product Id of inserted product = " + prodId);

            // Read the product from the database
            prod = port.getProduct(sessionId, prodId);

            if (prod != null)
            {
                /*
                 * Note that the name and description of the admin product object are set to null
                 * because they are in the AdminProductDescription array for each language. If the
                 * same product is read through the KonaKart application API, the name and
                 * description will be set to the values defined by the chosen language.
                 */
                System.out.println(prod.toString());
            } else
            {
                System.out.println("The product could not be read from the DB");
            }

        } catch (Exception e)
        {
            e.printStackTrace();
        }

    }

}

sdyck

err .. btw I am passing sessionId to the int prodId = port.insertProduct(sessionId, prod); call

sdyck

Found it ... I was using the default url that is generated from the wsdl, changed it to use my local and all's good

;D