Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generated web services client classes with no setters

Tags:

java

I've created a client for SOAP web service, but in the generated code some classes miss setter methods.

WSDL for the objects looks like:

<xsd:complexType name="UserDefinedFieldArray">
<xsd:sequence>
<xsd:element name="userDefinedField" minOccurs="0" maxOccurs="unbounded"  
           type="ns0:UserDefinedField"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="UserDefinedField">
<xsd:sequence>
<xsd:element name="fieldName" type="xsd:string"/>
<xsd:element name="fieldValue" type="xsd:string"/>
<xsd:element name="listId" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>

Those objects have only setXXX(), and Java Docs insist on this:

"This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the JAXB object. This is why there is not a set method for the testSuiteUdfs property. For example, to add a new item, do as follows: getTestSuiteUdfs().add(newItem); "

Though my logic says to me, that the updated list cannot get to the server until u send it there?

The only related thing I managed to find: http://www-01.ibm.com/support/docview.wss?uid=swg21440294. But it was not helpful at all.

Can anyone, please, tell me which way to dig? Cause I don't understand at all how this is supposed to work. Thanks!

like image 476
buxter Avatar asked Jul 26 '12 17:07

buxter


1 Answers

Updating a domain object mapped by JAXB does not cause communication with the server. JAXB (JSR-222) is a standard for converting objects to/from XML. It is leveraged by JAX-WS (SOAP) and JAX-RS (RESTful) frameworks to produce/consume messages sent over the wire between clients an servers.

UPDATE

" any modification you make to the returned list will be present inside the JAXB object."

All this means is that the List you get is the real List and not a copy. You can test this out with the following code:

System.out.println(customer.getPhoneNumbers().size());  // returns x
customer.getPhoneNumbers().add(new PhoneNumber());
System.out.println(customer.getPhoneNumbers().size());  // returns x + 1
like image 113
bdoughan Avatar answered Oct 02 '22 01:10

bdoughan