Passing an Array of Objects to an Axis2 Web Service

C

carmelo

Hi everybody,
I'm developing an Axis2 web service, which needs to receive an input
Array. The problem is that when the client sends the array to the web
service, it receives an empty or null array.

I tried both passing directly an array of Objects and passing a bean
which contains it. On the first case, the web service receives an
array with 0 length, on the second case (passing the bean) it receives
a NULL array.

The stub was generated by Netbeans 6.7.

Here is the code I used:

- Web Service

//WSList.java
public class WSList {
//passing MyArray bean which contains Object[]
public String putArr(MyArray ma)
{
if(ma.arr==null)
return "empty";
else
return "non empty";
}
//passing directly Object[]
public int putObj(Object []o)
{
return o.length;
}
}

//MyArray.java
public class MyArray {
public Object []arr;
}

- Client

//WSList_Client.java
public class WSList_Client {
public static void putArr()
{
try { // Call Web Service Operation
wslist.WSList service = new wslist.WSList();
wslist.WSListPortType port =
service.getWSListSOAP12PortHttp();
// TODO initialize WS operation arguments here
wslist.xsd.MyArray ma = new wslist.xsd.MyArray();

ma.getArr().add(new Integer(1));
ma.getArr().add(new Integer(2));
System.out.println(ma.getArr().size());

// TODO process result here
java.lang.String result = port.putArr(ma);
System.out.println("Result = "+result);
} catch (Exception ex) {
System.err.println(ex);
}
}

public static void putObj()
{
try { // Call Web Service Operation
wslist.WSList service = new wslist.WSList();
wslist.WSListPortType port =
service.getWSListSOAP12PortHttp();
// TODO initialize WS operation arguments here
java.util.List<java.lang.Object> o = new
java.util.ArrayList<java.lang.Object>();

o.add(new Integer(1));
o.add(new Integer(2));

// TODO process result here
java.lang.Integer result = port.putObj(o);
System.out.println("Result = "+result.intValue());
} catch (Exception ex) {
System.err.println(ex);
}
}
}

//WSListPortType.java
@WebService(name = "WSListPortType", targetNamespace = "http://
wslist/")
@XmlSeeAlso({
ObjectFactory.class
})
public interface WSListPortType {

@WebMethod(action = "urn:putArr")
@WebResult(targetNamespace = "http://wslist/xsd")
@RequestWrapper(localName = "putArr", targetNamespace = "http://
wslist/xsd", className = "wslist.xsd.PutArr")
@ResponseWrapper(localName = "putArrResponse", targetNamespace =
"http://wslist/xsd", className = "wslist.xsd.PutArrResponse")
public String putArr(
@WebParam(name = "ma", targetNamespace = "http://wslist/xsd")
MyArray ma);

@WebMethod(action = "urn:putObj")
@WebResult(targetNamespace = "http://wslist/xsd")
@RequestWrapper(localName = "putObj", targetNamespace = "http://
wslist/xsd", className = "wslist.xsd.PutObj")
@ResponseWrapper(localName = "putObjResponse", targetNamespace =
"http://wslist/xsd", className = "wslist.xsd.PutObjResponse")
public Integer putObj(
@WebParam(name = "o", targetNamespace = "http://wslist/xsd")
List<Object> o);
}

//PutArr.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"ma"
})
@XmlRootElement(name = "putArr")
public class PutArr {

@XmlElementRef(name = "ma", namespace = "http://wslist/xsd", type
= JAXBElement.class)
protected JAXBElement<MyArray> ma;

public JAXBElement<MyArray> getMa() {
return ma;
}

public void setMa(JAXBElement<MyArray> value) {
this.ma = ((JAXBElement<MyArray> ) value);
}

}

//PutObj.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"o"
})
@XmlRootElement(name = "putObj")
public class PutObj {

@XmlElement(nillable = true)
protected List<Object> o;

public List<Object> getO() {
if (o == null) {
o = new ArrayList<Object>();
}
return this.o;
}

}


I hope you can help me. Thank you guys
 
Joined
Dec 15, 2009
Messages
1
Reaction score
0
Java Web Service

Carmelo,

Did you ever find an answer to your question?

I have a similar problem. I am using Java Web Services, and one of the custom objects I made does not go through Java Web Services correctly. It has an instance of a HASHMAP class in it, and whenever it goes from client to server, it is null on the server side.

-javaSven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top