You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Mehdi Rabah <me...@gmail.com> on 2008/04/16 17:37:08 UTC

[axis2 java client] ArrayList cannot be cast to Set

Hi everyone, I'm a new user of webservices/axis/soap, etc.

I've deployed a simple WS (using axis2) which return a set, and I want to
deserialize it in my java client (also using axis2). But I get this error :

Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList
cannot be cast to java.util.Set

Is this a common error ? If so, can you point me some doc which I must
positively absolutely read to avoid basic problems like this ?

Thanks in advance,
--
Mehdi
-------

here is a part of my java lient code

        RPCServiceClient serviceClient = new RPCServiceClient();

        Options options = serviceClient.getOptions();

        EndpointReference targetEPR = new EndpointReference(endPointStr);
        options.setTo(targetEPR);

        QName opFindEntry = new QName(namespaceStr, methodNameStr);

        Object[] opFindEntryArgs = new Object[] { };

        Class[] returnTypes = new Class[] { Set.class };


        Object[] response = serviceClient.invokeBlocking(opFindEntry,
                opFindEntryArgs, returnTypes);

        Set result = (Set) response[0];

Re: [axis2 java client] ArrayList cannot be cast to Set

Posted by Mehdi Rabah <me...@gmail.com>.
Just FYI, I get the exact same error when trying to communicate a Set with
Xfire2 (aka CXF) on both side (client/server), so I'm convinced there's
something I'm doing wrong, but I'm still searching what is it. Again, if you
have some useful documentation I'll be grateful.
--
Mehdi

On Wed, Apr 16, 2008 at 5:47 PM, Michele Mazzucco <
Michele.Mazzucco@ncl.ac.uk> wrote:

> This is a java problem, it has nothing to do with web services. You cannot
> cast an ArrayList to a Set!, they have different features. Try to
> send/receive array of values and work with your set after that.
>
> Michele
>
>
>
> On 16 Apr 2008, at 16:37, Mehdi Rabah wrote:
>
> > Hi everyone, I'm a new user of webservices/axis/soap, etc.
> >
> > I've deployed a simple WS (using axis2) which return a set, and I want
> > to deserialize it in my java client (also using axis2). But I get this error
> > :
> >
> > Exception in thread "main" java.lang.ClassCastException:
> > java.util.ArrayList cannot be cast to java.util.Set
> >
> > Is this a common error ? If so, can you point me some doc which I must
> > positively absolutely read to avoid basic problems like this ?
> >
> > Thanks in advance,
> > --
> > Mehdi
> > -------
> >
> > here is a part of my java lient code
> >
> >        RPCServiceClient serviceClient = new RPCServiceClient();
> >
> >        Options options = serviceClient.getOptions();
> >
> >        EndpointReference targetEPR = new EndpointReference(endPointStr);
> >        options.setTo(targetEPR);
> >
> >        QName opFindEntry = new QName(namespaceStr, methodNameStr);
> >
> >        Object[] opFindEntryArgs = new Object[] { };
> >
> >        Class[] returnTypes = new Class[] { Set.class };
> >
> >
> >        Object[] response = serviceClient.invokeBlocking
> > (opFindEntry,
> >                opFindEntryArgs, returnTypes);
> >
> >        Set result = (Set) response[0];
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [axis2 java client] ArrayList cannot be cast to Set

Posted by Mehdi Rabah <me...@gmail.com>.
Hi Michele, thanks for your answer,

In fact, I'm sending a *Set* from my WebService, so I expect to receive a
*Set*. I've looked what contain the ArrayList I receive and it appear to be
an ArrayList of org.apache.axiom.om.impl.llom.OMTextImpl. It has nothing to
do with the basic Set of Integer I sent! Here is the soap response of my WS:

<ns:getLogEntry2Response
    xmlns:ns="http://eventlogger.ws"
    xmlns:ax21="http://interaction.ws/xsd"
    xmlns:ax22="http://util.java/xsd">
    <ns:return>0</ns:return>
    <ns:return>1</ns:return>
    <ns:return>2</ns:return>
</ns:getLogEntry2Response>

Don't tell me this is a java problem... and Rob, thanks for your kindness...

---
Mehdi


On Wed, Apr 16, 2008 at 5:47 PM, Michele Mazzucco <
Michele.Mazzucco@ncl.ac.uk> wrote:

> This is a java problem, it has nothing to do with web services. You cannot
> cast an ArrayList to a Set!, they have different features. Try to
> send/receive array of values and work with your set after that.
>
> Michele
>
>
>
> On 16 Apr 2008, at 16:37, Mehdi Rabah wrote:
>
> > Hi everyone, I'm a new user of webservices/axis/soap, etc.
> >
> > I've deployed a simple WS (using axis2) which return a set, and I want
> > to deserialize it in my java client (also using axis2). But I get this error
> > :
> >
> > Exception in thread "main" java.lang.ClassCastException:
> > java.util.ArrayList cannot be cast to java.util.Set
> >
> > Is this a common error ? If so, can you point me some doc which I must
> > positively absolutely read to avoid basic problems like this ?
> >
> > Thanks in advance,
> > --
> > Mehdi
> > -------
> >
> > here is a part of my java lient code
> >
> >        RPCServiceClient serviceClient = new RPCServiceClient();
> >
> >        Options options = serviceClient.getOptions();
> >
> >        EndpointReference targetEPR = new EndpointReference(endPointStr);
> >        options.setTo(targetEPR);
> >
> >        QName opFindEntry = new QName(namespaceStr, methodNameStr);
> >
> >        Object[] opFindEntryArgs = new Object[] { };
> >
> >        Class[] returnTypes = new Class[] { Set.class };
> >
> >
> >        Object[] response = serviceClient.invokeBlocking
> > (opFindEntry,
> >                opFindEntryArgs, returnTypes);
> >
> >        Set result = (Set) response[0];
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [axis2 java client] ArrayList cannot be cast to Set

Posted by Martin Gainty <mg...@hotmail.com>.
I agree..
The answer should be
If you want a Set returned to your client by invokeBlocking as with Spring
SetFactoryBean
http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/
beans/factory/config/SetFactoryBean.html
then Please insert enahncement request to jira..

Good Point Andreas and Mehdi
Martin-
----- Original Message -----
From: "Andreas Veithen" <an...@skynet.be>
To: <ax...@ws.apache.org>
Sent: Wednesday, April 16, 2008 7:21 PM
Subject: Re: [axis2 java client] ArrayList cannot be cast to Set


>
> On 16 Apr 2008, at 17:57, Smallwood, Rob wrote:
> > Without being unkind (and I really mean that), I think a java tutorial
> > explaining the fundamentals would fill in the missing gaps..
>
> Rob,
>
> Without being unkind, I think you should read Mehdi's post more
> carefully before referring him to a Java tutorial...
>
> His code contains the following instructions:
>
> Class[] returnTypes = new Class[] { Set.class };
> Object[] response = serviceClient.invokeBlocking(opFindEntry,
> opFindEntryArgs, returnTypes);
>
> The point is actually not that his WS returns a Set (this information
> obviously gets lost when serializing to XML), but that on the client
> side he explicitly specifies the expected Java type as Set and that
> RPCServiceClient#invokeBlocking returns an ArrayList instead. I'm
> neither an expert of RPC nor of ADB, but I'm a bit surprised to see
> this.
>
> The code in Axis2 that causes this behavior can be found in
> org.apache.axis2.databinding.utils.BeanUtil#processObject:
>
> if (SimpleTypeMapper.isCollection(classType)) {
>      return SimpleTypeMapper.getArrayList(omElement);
> }
>
> The logic behind this is indeed a bit questionable, and I think
> Mehdi's question is perfectly relevant.
>
> Regards,
>
> Andreas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [axis2 java client] ArrayList cannot be cast to Set

Posted by Andreas Veithen <an...@skynet.be>.
On 16 Apr 2008, at 17:57, Smallwood, Rob wrote:
> Without being unkind (and I really mean that), I think a java tutorial
> explaining the fundamentals would fill in the missing gaps..

Rob,

Without being unkind, I think you should read Mehdi's post more  
carefully before referring him to a Java tutorial...

His code contains the following instructions:

Class[] returnTypes = new Class[] { Set.class };
Object[] response = serviceClient.invokeBlocking(opFindEntry,  
opFindEntryArgs, returnTypes);

The point is actually not that his WS returns a Set (this information  
obviously gets lost when serializing to XML), but that on the client  
side he explicitly specifies the expected Java type as Set and that  
RPCServiceClient#invokeBlocking returns an ArrayList instead. I'm  
neither an expert of RPC nor of ADB, but I'm a bit surprised to see  
this.

The code in Axis2 that causes this behavior can be found in  
org.apache.axis2.databinding.utils.BeanUtil#processObject:

if (SimpleTypeMapper.isCollection(classType)) {
     return SimpleTypeMapper.getArrayList(omElement);
}

The logic behind this is indeed a bit questionable, and I think  
Mehdi's question is perfectly relevant.

Regards,

Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: [axis2 java client] ArrayList cannot be cast to Set

Posted by "Smallwood, Rob" <Ro...@sage.com>.
> Object[] response = serviceClient.invokeBlocking
> (opFindEntry,
>                 opFindEntryArgs, returnTypes);
>
>         Set result = (Set) response[0];

Try casting the ArrayList to a "Collection" and then use an iterator on
the Collection..

Without being unkind (and I really mean that), I think a java tutorial
explaining the fundamentals would fill in the missing gaps..


-----Original Message-----
From: Michele Mazzucco [mailto:Michele.Mazzucco@ncl.ac.uk] 
Sent: 16 April 2008 16:48
To: axis-user@ws.apache.org
Subject: Re: [axis2 java client] ArrayList cannot be cast to Set

This is a java problem, it has nothing to do with web services. You  
cannot cast an ArrayList to a Set!, they have different features. Try  
to send/receive array of values and work with your set after that.

Michele


On 16 Apr 2008, at 16:37, Mehdi Rabah wrote:
> Hi everyone, I'm a new user of webservices/axis/soap, etc.
>
> I've deployed a simple WS (using axis2) which return a set, and I  
> want to deserialize it in my java client (also using axis2). But I  
> get this error :
>
> Exception in thread "main" java.lang.ClassCastException:  
> java.util.ArrayList cannot be cast to java.util.Set
>
> Is this a common error ? If so, can you point me some doc which I  
> must positively absolutely read to avoid basic problems like this ?
>
> Thanks in advance,
> --
> Mehdi
> -------
>
> here is a part of my java lient code
>
>         RPCServiceClient serviceClient = new RPCServiceClient();
>
>         Options options = serviceClient.getOptions();
>
>         EndpointReference targetEPR = new EndpointReference 
> (endPointStr);
>         options.setTo(targetEPR);
>
>         QName opFindEntry = new QName(namespaceStr, methodNameStr);
>
>         Object[] opFindEntryArgs = new Object[] { };
>
>         Class[] returnTypes = new Class[] { Set.class };
>
>
>         Object[] response = serviceClient.invokeBlocking
> (opFindEntry,
>                 opFindEntryArgs, returnTypes);
>
>         Set result = (Set) response[0];


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org

If you've received this email by mistake, we're sorry for bothering you. It may contain information that's confidential, so please delete it without sharing it. And if you let us know, we can try to stop it from happening again. Thank you. 

We may monitor any emails sent or received by us, or on our behalf. If we do, this will be in line with relevant law and our own policies.

Sage (UK) Limited. Registered in England at North Park, Newcastle upon Tyne, NE13 9AA. Registered number 1045967.

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [axis2 java client] ArrayList cannot be cast to Set

Posted by Michele Mazzucco <Mi...@ncl.ac.uk>.
This is a java problem, it has nothing to do with web services. You  
cannot cast an ArrayList to a Set!, they have different features. Try  
to send/receive array of values and work with your set after that.

Michele


On 16 Apr 2008, at 16:37, Mehdi Rabah wrote:
> Hi everyone, I'm a new user of webservices/axis/soap, etc.
>
> I've deployed a simple WS (using axis2) which return a set, and I  
> want to deserialize it in my java client (also using axis2). But I  
> get this error :
>
> Exception in thread "main" java.lang.ClassCastException:  
> java.util.ArrayList cannot be cast to java.util.Set
>
> Is this a common error ? If so, can you point me some doc which I  
> must positively absolutely read to avoid basic problems like this ?
>
> Thanks in advance,
> --
> Mehdi
> -------
>
> here is a part of my java lient code
>
>         RPCServiceClient serviceClient = new RPCServiceClient();
>
>         Options options = serviceClient.getOptions();
>
>         EndpointReference targetEPR = new EndpointReference 
> (endPointStr);
>         options.setTo(targetEPR);
>
>         QName opFindEntry = new QName(namespaceStr, methodNameStr);
>
>         Object[] opFindEntryArgs = new Object[] { };
>
>         Class[] returnTypes = new Class[] { Set.class };
>
>
>         Object[] response = serviceClient.invokeBlocking
> (opFindEntry,
>                 opFindEntryArgs, returnTypes);
>
>         Set result = (Set) response[0];


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [axis2 java client] ArrayList cannot be cast to Set

Posted by Mehdi Rabah <me...@gmail.com>.
Hi Luciana,

I've also seen that you can parse the OMElement ArrayList and get the values
that were in the set, but I'm working with objects which contains sets, so I
get an error before being able to parse that.. :

xception in thread "main" java.lang.IllegalArgumentException: argument type
mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at
org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:391)
    at
org.apache.axis2.databinding.utils.BeanUtil.processObject(BeanUtil.java:655)
    at
org.apache.axis2.databinding.utils.BeanUtil.ProcessElement(BeanUtil.java:603)
    at
org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:535)
    at
org.apache.axis2.rpc.client.RPCServiceClient.invokeBlocking(RPCServiceClient.java:103)
    at ClientAxis2.run(ClientAxis2.java:89)
    at ClientAxis2.main(ClientAxis2.java:99)

I'm starting to run out of ideas.
No one ever transmistted an object with a set using AXIS ??? (and I'm afraid
to talk about (hash)maps)

Regards,
--
Mehdi


On Thu, Apr 17, 2008 at 2:56 PM, Lucy T. <lu...@gmail.com> wrote:

>
> I have partially resolved the problem:
>
> Server side (web service):
>
> import java.util.HashSet;
> import java.util.Set;
>
> public class ProvaSet {
>
>        public Set<String> provaSet()
>        {
>                Set<String> s = new HashSet<String>();
>                s.add("Pippo");
>                s.add("Pluto");
>                s.add("Paperino");
>                s.add("Topolino");
>
>                return s;
>        }
>
> }
>
>
> Client invocation:
>
> RPCServiceClient serviceClient;
>                try {
>                         serviceClient = new RPCServiceClient();
>
>                        Options options = serviceClient.getOptions();
>                         EndpointReference targetEPR = new
> EndpointReference(webServiceURI);
>                        options.setTo(targetEPR);
>                        QName opProvaSet =  new QName("http://proveLuciana",
> "provaSet");
>
>                        Object[] opProvaSetArgs = new Object[] { };
>                 Class[] returnTypes = new Class[] { Set.class };
>
>                 Object[] response =
> serviceClient.invokeBlocking(opProvaSet,
>                                opProvaSetArgs, returnTypes);
>
>                Collection result =  (Collection) response[0];
>                System.out.println("\nTipo dell'oggetto result: " +
> result.getClass());
>                Iterator iter = (Iterator) result.iterator();
>
>
>                while (iter.hasNext())
>                {
>
>                                OMText s = (OMTextImpl) iter.next();
>
>                }
>
>                } catch (AxisFault e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                }
>
>
>
> Now the problem is that returns only the first element of Set Collection
> (that is element "Pippo").
> I'm working on this.
>
> Hope this helps.
>
> Regards,
> Luciana
>
> --
> View this message in context:
> http://www.nabble.com/-axis2-java-client--ArrayList-cannot-be-cast-to-Set-tp16726826p16743976.html
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [axis2 java client] ArrayList cannot be cast to Set

Posted by "Lucy T." <lu...@gmail.com>.
I have partially resolved the problem:

Server side (web service):

import java.util.HashSet;
import java.util.Set;

public class ProvaSet {
	
	public Set<String> provaSet()
	{
		Set<String> s = new HashSet<String>();
		s.add("Pippo");
		s.add("Pluto");
		s.add("Paperino");
		s.add("Topolino");
		
		return s;
	}

}


Client invocation:

RPCServiceClient serviceClient;
		try {
			serviceClient = new RPCServiceClient();

			Options options = serviceClient.getOptions();
			EndpointReference targetEPR = new EndpointReference(webServiceURI);
			options.setTo(targetEPR);
			QName opProvaSet =  new QName("http://proveLuciana", "provaSet");
			
			Object[] opProvaSetArgs = new Object[] { };
	        Class[] returnTypes = new Class[] { Set.class };
	        
	        Object[] response = serviceClient.invokeBlocking(opProvaSet,
	        		opProvaSetArgs, returnTypes);
	        
	        Collection result =  (Collection) response[0];
	        System.out.println("\nTipo dell'oggetto result: " +
result.getClass());
	        Iterator iter = (Iterator) result.iterator();

	        
	        while (iter.hasNext())
	        {

	        		OMText s = (OMTextImpl) iter.next();

	        }

		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}



Now the problem is that returns only the first element of Set Collection
(that is element "Pippo").
I'm working on this.

Hope this helps.

Regards,
Luciana

-- 
View this message in context: http://www.nabble.com/-axis2-java-client--ArrayList-cannot-be-cast-to-Set-tp16726826p16743976.html
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org