i have some issues with serializations.
One of my class is made of an array of another class.
Here is the class i'm talking about :
public class Category
{
private int Id = 0;
private String name;
private CategoryInfo[] data;
private int shared = 0;
private int userid = 0;
// methods here
}
public class CategoryInfo
{
private int ownerId=0;
private String name;
private String type;
private int userid=0;
// methods here
}
One of my webservices will add the content of the Category class into a database.
It is in a class named SqlGenerator, in the package webservices.sql.generator.
Here is the function i'm calling :
public Category insert(Category obj, String str) throws Exception, InternalException
{
try
{
if (SqlMisc.checkUserIsConnect(SqlMisc.decode(str)) == 0)
throw new Exception("Todo : add here an exception saying that the user is not connected");
if (obj.getData() == null )
throw new Exception("Todo : DATA = ""> if (obj.getData().length == 0 )
throw new Exception("Todo : LENGTH = 0");
CategoryGenerator cat = new CategoryGenerator();
cat.setCategory(obj);
obj.setId(cat.generateCategory());
cat.generateCategoryInfo();
DbConnection.getInstance ().getConnection().commit();
return obj;
}
catch (InternalException e)
{
DbConnection.getInstance().getConnection().rollback();
throw new InternalException( TablesExceptions.getInstance().getUserMessage(e.getMessage()));
}
}
I call my service by calling this function :
public static Category testAddCategory() throws Exception
{
Category cat = new Category();
CategoryInfo catInfo = new CategoryInfo();
CategoryInfo catInfo2 = new CategoryInfo();
cat.setName("BBBBBBB");
cat.setShared(0);
cat.setUserid (1);
catInfo.setName("NAME1");
catInfo.setType("Text");
catInfo2.setName("NAME2");
catInfo2.setType("Doc");
cat.setData(catInfo);
cat.setData(catInfo2);
System.out.println(cat.getData().length);
try
{
String endpoint = " http://localhost:8080/axis/services/SqlGenerator ";
Service service = new Service();
Call call = (Call) service.createCall();
QName qn = new QName("ns:Category", "Category");
call.registerTypeMapping(objects.Category.class, qn,
new org.apache.axis.encoding.ser
.BeanSerializerFactory(objects.Category.class, qn),
new org.apache.axis.encoding.ser.BeanDeserializerFactory (objects.Category.class, qn));
QName qn3 = new QName("ns:CategoryInfo", "CategoryInfo");
call.registerTypeMapping(objects.CategoryInfo.class, qn3,
new org.apache.axis.encoding.ser.BeanSerializerFactory(objects.CategoryInfo.class, qn3),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(objects.CategoryInfo.class, qn3));
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName(" http://webservices.sql.generator.SqlGenerator ", "insert"));
call.addParameter("arg1", qn3, ParameterMode.IN);
call.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType ( qn);
cat = (Category)(call.invoke( new Object[] {cat, encode("1:1:yahoo")} ));
System.out.println("Result for TestAddCategory : " + cat.toString() + "'");
return cat;
}
catch (Exception e) {
System.err.println("error : ");
e.printStackTrace();
}
return null;
}
My wsd file is declare like this :
<deployment
xmlns="http://xml.apache.org/axis/wsdd/ "
xmlns:java=" http://xml.apache.org/axis/wsdd/providers/java">
<!-- Services from SqlGeneratorService WSDL service -->
<service name="SqlGenerator" provider="java:RPC" style="rpc" use="encoded">
<parameter name="className" value="webservices.sql.generator.SqlGenerator"/>
<parameter name="allowedMethods" value="*"/>
<typeMapping
xmlns:ns="http://exceptions"
qname="ns:InternalException"
type="java: exceptions.InternalException"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory "
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/ "
/>
<typeMapping
xmlns:ns="http://objects"
qname="ns:CategoryInfo"
type="java:objects.CategoryInfo"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
/>
<typeMapping
xmlns:ns="http://objects "
qname="ns:Category"
type="java: objects.Category"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
/>
<arrayMapping
xmlns:ns=" http://objects"
qname="ns:ArrayOf_tns2_CategoryInfo"
type="java:objects.CategoryInfo[]"
innerType="cmp-ns:CategoryInfo" xmlns:cmp-ns=" http://objects "
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
/>
</service>
</deployment>
When i call the service, the array received by the webservice is always empty, and so, it throws me the exception saying "Todo : LENGTH = 0"
How is it possible, since we can see that the content of the array is here in the soap message :
POST /axis/services/SqlGenerator HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: 192.168.1.101:8080
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 3016
<?xml version=" 1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance ">
<soapenv:Body>
<ns1:insert soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1=" http://webservices.sql.generator.SqlGenerator ">
<arg1 href=""> <arg2 xsi:type="xsd:string">:²Wd¶Òqç•</arg2>
</ns1:insert>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Category" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="ns:Category">
<data soapenc:arrayType="ns3:CategoryInfo[2]" xsi:type="soapenc:Array" xmlns:ns3="ns:CategoryInfo">
<data href=""> <data href=""> </data>
<id href=""> <name xsi:type="soapenc:string">BBBBBBB</name>
<shared href=""> <userid href=""> </multiRef>
<multiRef id="id5" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/ ">1</multiRef>
<multiRef id="id2" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/ " xsi:type="ns4:CategoryInfo" xmlns:ns4="ns:CategoryInfo" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">
<name xsi:type="soapenc:string">NAME2</name>
<ownerId href=""> <type xsi:type="soapenc:string">Doc</type>
<userid href=""> </multiRef>
<multiRef id="id4" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/ " xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">0</multiRef>
<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:CategoryInfo" xmlns:ns5="ns:CategoryInfo" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">
<name xsi:type="soapenc:string">NAME1</name>
<ownerId href=""> <type xsi:type="soapenc:string">Text</type>
<userid href=""> </multiRef>
<multiRef id="id3" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">0</multiRef>
<multiRef id="id9" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">0</multiRef>
<multiRef id="id6" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/ ">0</multiRef>
<multiRef id="id7" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/ " xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/ ">0</multiRef>
<multiRef id="id8" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/ ">0</multiRef>
</soapenv:Body>
</soapenv:Envelope>
I hope someone will be able to help me on this !
Best regards, and thanks in advance.
new org.apache.axis.encoding.ser.BeanDeserializerFactory (objects.Category.class, qn));
QName qn3 = new QName("ns:CategoryInfo", "CategoryInfo");
call.registerTypeMapping(objects.CategoryInfo.class, qn3,
new org.apache.axis.encoding.ser.BeanSerializerFactory(objects.CategoryInfo.class, qn3),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(objects.CategoryInfo.class, qn3));
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName(" http://webservices.sql.generator.SqlGenerator ", "insert"));
call.addParameter("arg1", qn3, ParameterMode.IN);
call.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType ( qn);
cat = (Category)(call.invoke( new Object[] {cat, encode("1:1:yahoo")} ));
System.out.println("Result for TestAddCategory : " + cat.toString() + "'");
return cat;
}
catch (Exception e) {
System.err.println("error : ");
e.printStackTrace();
}
return null;
}
My wsd file is declare like this :
<deployment
xmlns="http://xml.apache.org/axis/wsdd/ "
xmlns:java=" http://xml.apache.org/axis/wsdd/providers/java">
<!-- Services from SqlGeneratorService WSDL service -->
<service name="SqlGenerator" provider="java:RPC" style="rpc" use="encoded">
<parameter name="className" value="webservices.sql.generator.SqlGenerator"/>
<parameter name="allowedMethods" value="*"/>
<typeMapping
xmlns:ns="http://exceptions"
qname="ns:InternalException"
type="java: exceptions.InternalException"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory "
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/ "
/>
<typeMapping
xmlns:ns="http://objects"
qname="ns:CategoryInfo"
type="java:objects.CategoryInfo"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
/>
<typeMapping
xmlns:ns="http://objects "
qname="ns:Category"
type="java: objects.Category"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
/>
<arrayMapping
xmlns:ns=" http://objects"
qname="ns:ArrayOf_tns2_CategoryInfo"
type="java:objects.CategoryInfo[]"
innerType="cmp-ns:CategoryInfo" xmlns:cmp-ns=" http://objects "
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/"
/>
</service>
</deployment>
When i call the service, the array received by the webservice is always empty, and so, it throws me the exception saying "Todo : LENGTH = 0"
How is it possible, since we can see that the content of the array is here in the soap message :
POST /axis/services/SqlGenerator HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: 192.168.1.101:8080
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 3016
<?xml version=" 1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/ " xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance ">
<soapenv:Body>
<ns1:insert soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1=" http://webservices.sql.generator.SqlGenerator ">
<arg1 href=""> <arg2 xsi:type="xsd:string">:²Wd¶Òqç•</arg2>
</ns1:insert>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Category" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="ns:Category">
<data soapenc:arrayType="ns3:CategoryInfo[2]" xsi:type="soapenc:Array" xmlns:ns3="ns:CategoryInfo">
<data href=""> <data href=""> </data>
<id href=""> <name xsi:type="soapenc:string">BBBBBBB</name>
<shared href=""> <userid href=""> </multiRef>
<multiRef id="id5" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/ ">1</multiRef>
<multiRef id="id2" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/ " xsi:type="ns4:CategoryInfo" xmlns:ns4="ns:CategoryInfo" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">
<name xsi:type="soapenc:string">NAME2</name>
<ownerId href=""> <type xsi:type="soapenc:string">Doc</type>
<userid href=""> </multiRef>
<multiRef id="id4" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/ " xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">0</multiRef>
<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns5:CategoryInfo" xmlns:ns5="ns:CategoryInfo" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">
<name xsi:type="soapenc:string">NAME1</name>
<ownerId href=""> <type xsi:type="soapenc:string">Text</type>
<userid href=""> </multiRef>
<multiRef id="id3" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">0</multiRef>
<multiRef id="id9" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/">0</multiRef>
<multiRef id="id6" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/ ">0</multiRef>
<multiRef id="id7" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/ " xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/ ">0</multiRef>
<multiRef id="id8" soapenc:root="0" soapenv:encodingStyle=" http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/ ">0</multiRef>
</soapenv:Body>
</soapenv:Envelope>
I hope someone will be able to help me on this !
Best regards, and thanks in advance.
