Headless Client returning values

The forum to discuss the Headless version of Servoy. Web, Java and Servlet development questions can all be posted here.

Headless Client returning values

Postby Janssenjos » Tue Sep 08, 2009 4:30 pm

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?):

Code: Select all
'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
Code: Select all
function GetSupply()
{
   var data = Packages.com.data;
      
   var response = data.SupplyResponse();
   
   response .sellerParty = "A & B";
   response .product= "C";      
   
   return response;   
}



Java Headless Client.
Code: Select all
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.
Jos Janssen
Software Developer
Axerrio
http://www.axerrio.com
Janssenjos
 
Posts: 148
Joined: Thu Aug 13, 2009 3:55 pm
Location: Bergen op Zoom

Re: Headless Client returning values

Postby ptalbot » Wed Sep 09, 2009 2:34 pm

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,
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC


Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 4 guests