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 Rosén Håkan <ha...@kvadrat.se> on 2004/02/27 14:48:21 UTC
How to return array of beans
Hi
I try to deploy a service but i'm stuck halfways.
I have written a small service that takes a javabean (Album) as input and
returns an array of the same bean (Album[]) as output,
I can call my service with a bean-parameter but when I return the array I
get a ClassCastException.
I think my problem is that i have to descibe the returning Array as well,
but i don't know how
the method in my service looks like :
public Album[] getAlbums( Album anAlbum ) {
wsdd-file:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:album="http://www.soapinterop.org/Album">
<service name="Album" provider="java:RPC">
<namespace>http://www.soapinterop.org/Album</namespace>
<parameter name="className" value="com.nice.service.AlbumService"/>
<parameter name="allowedMethods" value="getAlbums"/>
</service>
<beanMapping qname="album:Album"
languageSpecificType="java:company.beans.Album"/>
</deployment>
Extact from client-code:
Album[] result = new Album[0];
call.removeAllParameters();
call.setTargetEndpointAddress(endpointURL);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.soapinterop.org/Album");
QName albumqn = new QName("http://www.soapinterop.org/Album",
"Album");
Class cls = Album.class;
call.registerTypeMapping(cls,
albumqn,
BeanSerializerFactory.class,
BeanDeserializerFactory.class);
call.setOperationName( new QName("http://www.soapinterop.org/Album",
"getAlbums" ));
QName albumRetqn = new
QName("http://www.soapinterop.org/Album","ArrayOfAlbum");
call.registerTypeMapping(result.getClass(), albumRetqn,
ArraySerializerFactory.class, ArrayDeserializerFactory.class);
call.addParameter( "anAlbum", albumqn, ParameterMode.IN );
call.setReturnType(albumRetqn);
//invoking the call return in a ClassCastException
Object ret = call.invoke(new Object[] { anAlbum });
regards
/Håkan
Re: How to return array of beans
Posted by Tony Blair <hr...@yahoo.com>.
Hi there,
I have a similar sample code. It takes a bean as an input but it returns a Collection of beans as oppose to an Array of beans. Is it possible for you to use Collection?
Cheers,
Tony.
Ros�n_H�kan <ha...@kvadrat.se> wrote:
Hi
I try to deploy a service but i'm stuck halfways.
I have written a small service that takes a javabean (Album) as input and
returns an array of the same bean (Album[]) as output,
I can call my service with a bean-parameter but when I return the array I
get a ClassCastException.
I think my problem is that i have to descibe the returning Array as well,
but i don't know how
the method in my service looks like :
public Album[] getAlbums( Album anAlbum ) {
wsdd-file:
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:album="http://www.soapinterop.org/Album">
http://www.soapinterop.org/Album
languageSpecificType="java:company.beans.Album"/>
Extact from client-code:
Album[] result = new Album[0];
call.removeAllParameters();
call.setTargetEndpointAddress(endpointURL);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.soapinterop.org/Album");
QName albumqn = new QName("http://www.soapinterop.org/Album",
"Album");
Class cls = Album.class;
call.registerTypeMapping(cls,
albumqn,
BeanSerializerFactory.class,
BeanDeserializerFactory.class);
call.setOperationName( new QName("http://www.soapinterop.org/Album",
"getAlbums" ));
QName albumRetqn = new
QName("http://www.soapinterop.org/Album","ArrayOfAlbum");
call.registerTypeMapping(result.getClass(), albumRetqn,
ArraySerializerFactory.class, ArrayDeserializerFactory.class);
call.addParameter( "anAlbum", albumqn, ParameterMode.IN );
call.setReturnType(albumRetqn);
//invoking the call return in a ClassCastException
Object ret = call.invoke(new Object[] { anAlbum });
regards
/H�kan
---------------------------------
Do you Yahoo!?
Get better spam protection with Yahoo! Mail