问题
I am using jaxb2Marshaller for consuming a SOAP service. I am using it inside Spring webServiceTemplate. The marhsalling works fine on windows but not on linux.
The issue only comes for attribute named "ID". Changing the attribute name to "id" or something else works fine.
Is there any difference between marshaling done on windows and linux?
Spring WebserviceTemplate configuration:
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="marshaller" ref="jaxb2Marshaller"></property>
<property name="unmarshaller" ref="jaxb2Marshaller"></property>
<property name="defaultUri"><value>${ws.url}</value></property>
...
</bean>
Now when I am calling the method webServiceTemplate.marshalSendAndReceive(createRequest);
The "CreateRequest" object is getting marshaled into an XML. All the attributes are populated except the attribute named "ID".
SubscriberList.java extends Parent {
protected String abc;
protected String def;
...
}
Parent.java {
protected int ID;
public getID(){return this.id}
public setID(int value){this.id=value}
}
I am consuming this webservice, so changing WSDL is not allowed.
Can someone help me in fixing this issue?
回答1:
Well the issue was little strange. Inside XML the attribute name was "ID", whereas in binding class generated had variable declaration as below:
<element name="ID" minOccurs="0" maxOccurs="1" type="xsd:int" />
@XmlElement(name = "ID")
protected Integer id;
public Integer getID() {
return id;
}
public void setID(Integer value) {
this.id = value;
}
The getxxx() and setxxx() methods generated by plugin were getID() and setID() for attribute "id".
Solution:
1. I manually updated the getID() to getId() and setID() to setId() in generated binding classes.
2. Stopped regenerating the binding classes as WSDL is a fixed contract.
来源:https://stackoverflow.com/questions/44107721/id-attribute-missing-while-marshaling-during-webservicetemplate-convertandsend