Hi all.


 


I’m trying to create a Adobe Flex 2 client which has to
communicate with a cxf service exposed through Json.  I used the following code 
for the initialization of the service.


 


ServerFactoryBean sf = new ServerFactoryBean();


 


Class serviceClass = 
JsonServiceBean.class.getClassLoader().loadClass(getServiceClass());


sf.setServiceClass(serviceClass);


 


Object instance;


if (getServiceBeanInstance() == null) { 


Class serviceImplClass =
JsonServiceBean.class.getClassLoader().loadClass(getServiceBean());


    instance = serviceImplClass.newInstance();


 


} else {


    instance =
getServiceBeanInstance();


}


 


sf.setServiceBean(instance);


 


sf.setAddress(getAddress());


 


 


sf.setBindingId("http://cxf.apache.org/bindings/xformat";);


sf.setTransportId("http://schemas.xmlsoap.org/wsdl/http/";);


 


sf.getServiceFactory().setWrapped(isWrapped());


Map<String, Object> properties = new
HashMap<String, Object>();


properties.put("Content-Type",
"text/plain");


 


// Set up the JSON StAX implementation


Map<String, String> nstojns = new HashMap<String,
String>();


nstojns.put("http://cxf.apache.org/bindings/xformat";,
"xformat");


 


Iterator<Entry<String, String>> iter =
getNamespaces().entrySet().iterator();


 


while (iter.hasNext()) {


    Entry<String,
String> entry = (Entry<String, String>) iter.next();


   
nstojns.put(entry.getKey(),entry.getValue());


}


 


MappedXMLInputFactory xif = new
MappedXMLInputFactory(nstojns);


properties.put(XMLInputFactory.class.getName(), xif);


 


org.codehaus.jettison.mapped.Configuration conf = new
org.codehaus.jettison.mapped.Configuration();


conf.setXmlToJsonNamespaces(nstojns);


 


 


MappedXMLOutputFactory xof = new
MappedXMLOutputFactory(conf);


properties.put(XMLOutputFactory.class.getName(), xof);


 


sf.setProperties(properties);


Server server = sf.create();


 


The signature of the remote method is:


 


Result createUser(Token token, String email, String userPwd,
String name, String surname);


 


The generated wsdl has as expected the following schema of
the message element


 


<xs:element name="createUser">


 <xs:complexType>


  <xs:sequence>


   <xs:element
name="arg00" nillable="true"
type="tns:token"/>


   <xs:element
name="arg11" nillable="true"
type="xs:string"/>


   <xs:element
name="arg22" nillable="true"
type="xs:string"/>


   <xs:element
name="arg33" nillable="true" type="xs:string"/>


   <xs:element
name="arg44" nillable="true"
type="xs:string"/>


 </xs:sequence>


 </xs:complexType>


</xs:element>


            


With the following JSON request:


 


{createUser:{token:{"token":"12345678"},
email:[EMAIL PROTECTED], userPwdID:pwd, name:Luca, surname:Ceppelli}}


 


the service works fine.


 


 


 


But, when the Flex 2 Client generates the request, the
parameters order is not respected. 
Following the code I used for the JSON service invocation:


 


import com.adobe.serialization.json.JSON;


 


…


 


httpService.request = JSON.encode({createUserss:{token:token,
email:emailID.text, userPwdID:userPwdID.text, name:nameID.text,
surname:surnameID.text}});


 


 


The problem is related with the Action Scripts Object: the
properties: token, name, email, ecc are stored in an internal map of the
root object. When the JSON.encode() static method accesses to the map
for retrieving the properties, theirs order is not respect. (I suspect that the
same problem could be happening also with a JAVA Script client).


 


I think that the easy solution is to use, instead of the SEQUENCE
complex type, the ALL complex type. What do you think about?


 


How is it possible to specify to use ALL instead of SEQUENCE
when the JSON service is created?


 


Have you other idea/suggestions to overcome this problem?


 


Thanks,


Luca.



      ___________________________________ 
L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail: 
http://it.docs.yahoo.com/nowyoucan.html

Reply via email to