Headless Client returning values

Hi,

I have the following situation:

I exposed my Servoy Solution as a Webservice using Java. This all goes well.
Now have I defined a Class in Java which I fill in Servoy. Now as a result of the webCall this object must be passed back to the client.

But when I do that I get the following errormessage (isn’t it the same object?):

'Fault is: com.data.SupplyResponse cannot be cast to com.data.SupplyResponse java.lang.ClassCastException: com.data.SupplyResponse cannot be cast to com.data.SupplyResponse'

The code, which both uses the same SupplyResponse Object:

Servoy

function GetSupply()
{
	var data = Packages.com.data;
		
	var response = data.SupplyResponse();
	
	response .sellerParty = "A & B";
	response .product= "C";		
	
	return response;	
}

Java Headless Client.

public SupplyResponse ExecuteMethod(MessageContext mc, String solutionName, String formName, String methodName, Object[] parameters)
    {
        SupplyResponse returnObject = null;

        HttpServletRequest request = ((HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST));
        HttpSession session = ((HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();

        if(session == null)
            throw new WebServiceException("No session available in the webservice context");

        if(request == null)
               throw new WebServiceException("Request is null");

        ISessionBean servoy_hc = (ISessionBean) session.getAttribute("servoy");

        try
        {
            if(servoy_hc == null)
            {
                //Aanmaken van de Headless client session.
                servoy_hc = HeadlessClientFactory.createSessionBean(request,solutionName,null,null);
                
                session.setAttribute("servoy", servoy_hc);
            }
            boolean ok = servoy_hc.setMainForm(formName);

            if(!ok)
                throw new WebServiceException("Error: Cannot work on required form: " + solutionName);

            //Here it goes wrong
            returnObject = (SupplyResponse) (servoy_hc.executeMethod(null, methodName, parameters ));
        }   
        catch(Exception ex)
        {
            throw new WebServiceException("1: Fault is: " + ex.getMessage() + " " + ex.toString()  );
        }
        finally
        {

            session.setAttribute("servoy",null);
        }

        return returnObject;
    }

What can I be doing wrong, or is there a better solution to achieve this.

I’m not sure I follow your code here, but I would say that it’s quite possible that the object you get as a response is not exactly the one you expect. Usually when you deal with web service you deal with proxy objects.

Meaning that to fix your code, you will probably need to define an interface with all the public methods you need and then implements that interface in your SupplyResponse class.

What you will get will then be more safely converted by a cast to that same interface. That’s how it should be done, really…

Hope this helps,