CMDBuild Forum

Problem connecting to web services.

Hi, I'm developing a client to communicate with CMDBuild web services according to the supplied java example.

I generated the sources from a wsdl file using Axis2 1.6.2. Also installed rampart 1.6.2

My client test code is below.

The problem is that I'm getting the error:

Exception in thread "main" java.lang.ClassCastException: org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory cannot be cast to org.apache.axiom.om.impl.builder.OMFactoryEx

on the line 

configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:/Apache_Software_Foundation/axis2-1.6.2/repository", null);

Can anyone help me?

 

Thanks!

 

package cmdbuild.ws.client;

import java.io.FileNotFoundException;

import javax.xml.stream.XMLStreamException;

import org.apache.axiom.om.impl.builder.StAXOMBuilder;

import org.apache.axis2.AxisFault;

import org.apache.axis2.client.Options;

import org.apache.axis2.context.ConfigurationContext;

import org.apache.axis2.context.ConfigurationContextFactory;

import org.apache.neethi.PolicyEngine;

import org.apache.rampart.RampartMessageData;

import org.cmdbuild.services.soap.Card;

import org.cmdbuild.services.soap.CardList;

import org.cmdbuild.services.soap.GetCardList;

import org.cmdbuild.services.soap.GetCardListResponse;

import org.cmdbuild.services.soap.impl.GetCardListImpl;


public class TestClient {


    public void test() {

        try {


            ConfigurationContext configContext = null;

            configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:/Apache_Software_Foundation/axis2-1.6.2/repository", null);


            WebservicesImplServiceStub stub = new WebservicesImplServiceStub(configContext);


            StAXOMBuilder builder = new StAXOMBuilder("C:/Apache_Software_Foundation/axis2-1.6.2/repository/conf/policy.xml");


            Options options = stub._getServiceClient().getOptions();

            options.setUserName("admin");

            options.setPassword("admin");

            options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, PolicyEngine.getPolicy(builder.getDocumentElement()));


            GetCardList list = new GetCardListImpl(null);

            list.setClassName("Computer");

            GetCardListResponse response = (GetCardListResponse) stub.getCardList(list);

            CardList card = response.getReturn();

            Card[] cardArr = card.getCardsArray();


            for (int i = 0; i < cardArr.length; i++) {

                System.out.println(cardArr[i].getId());

            }


        } catch (Exception ex) {

            ex.printStackTrace();

        }

    }


    public static void main(String[] args) 

    {

        TestClient tc = new TestClient();

        tc.test();

    }

}

 

Previously Claudia wrote:

Hi, I'm developing a client to communicate with CMDBuild web services according to the supplied java example.

I generated the sources from a wsdl file using Axis2 1.6.2. Also installed rampart 1.6.2

My client test code is below.

The problem is that I'm getting the error:

Exception in thread "main" java.lang.ClassCastException: org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory cannot be cast to org.apache.axiom.om.impl.builder.OMFactoryEx

on the line 

configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:/Apache_Software_Foundation/axis2-1.6.2/repository", null);

Can anyone help me?

 

Thanks!

 

package cmdbuild.ws.client;

import java.io.FileNotFoundException;

import javax.xml.stream.XMLStreamException;

import org.apache.axiom.om.impl.builder.StAXOMBuilder;

import org.apache.axis2.AxisFault;

import org.apache.axis2.client.Options;

import org.apache.axis2.context.ConfigurationContext;

import org.apache.axis2.context.ConfigurationContextFactory;

import org.apache.neethi.PolicyEngine;

import org.apache.rampart.RampartMessageData;

import org.cmdbuild.services.soap.Card;

import org.cmdbuild.services.soap.CardList;

import org.cmdbuild.services.soap.GetCardList;

import org.cmdbuild.services.soap.GetCardListResponse;

import org.cmdbuild.services.soap.impl.GetCardListImpl;


public class TestClient {


    public void test() {

        try {


            ConfigurationContext configContext = null;

            configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("C:/Apache_Software_Foundation/axis2-1.6.2/repository", null);


            WebservicesImplServiceStub stub = new WebservicesImplServiceStub(configContext);


            StAXOMBuilder builder = new StAXOMBuilder("C:/Apache_Software_Foundation/axis2-1.6.2/repository/conf/policy.xml");


            Options options = stub._getServiceClient().getOptions();

            options.setUserName("admin");

            options.setPassword("admin");

            options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, PolicyEngine.getPolicy(builder.getDocumentElement()));


            GetCardList list = new GetCardListImpl(null);

            list.setClassName("Computer");

            GetCardListResponse response = (GetCardListResponse) stub.getCardList(list);

            CardList card = response.getReturn();

            Card[] cardArr = card.getCardsArray();


            for (int i = 0; i < cardArr.length; i++) {

                System.out.println(cardArr[i].getId());

            }


        } catch (Exception ex) {

            ex.printStackTrace();

        }

    }


    public static void main(String[] args) 

    {

        TestClient tc = new TestClient();

        tc.test();

    }

}

 
This exception may get thrown if some of Axiom jars are mismatched or missing. Axiom is used by Axis2. You may want to verify that both axiom-impl and axiom-api jar files are on the classpath and of the same version, for example: axiom-api-1.2.13 and axiom-impl-1.2.13. I've seen this exception when the build had different version of files, e.g. axiom-api-1.2.14 while axiom-impl-1.2.13. Changing the api version to 1.2.13 fixed the problem. Hope it helps