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
utArr")
@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
utObj")
@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
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
@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
@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