In a Spring Boot application I am using maven-jaxb2-plugin to generate classes from WSDL file:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>AUTODETECT</schemaLanguage>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>*.wsdl</include>
</schemaIncludes>
<generatePackage>pl.pantuptus.app.integration</generatePackage>
</configuration>
</plugin>
The WSDL file contains sales field defined as:
<s:element minOccurs="1" maxOccurs="1"
name="sales" type="s:decimal" />
which is transformed by maven-jaxb2-plugin into a BigDecimal property of a generated class:
@XmlElement(name = "sales", required = true)
protected BigDecimal sales;
I configure the JAXB Marshaller explicitly in a configuration component:
@Configuration
public class IntegrationConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("pl.pantuptus.app.integration");
return marshaller;
}
@Bean
public MyClient myClient(Jaxb2Marshaller marshaller) {
MyClient client = new MyClient();
client.setDefaultUri("http://localhost:8080/ws");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
My problem is that when I call the WS endpoint from the client:
getWebServiceTemplate().marshalSendAndReceive(url, request)
I receive an object with null value of sales property.
My guess is that JAXB is not able to parse this property correctly because it has comma-based format in the response.
<sales>23 771,08</sales>
And here comes the question: how can I tell the Jaxb2Marshaller (or any other Marshaller implementation) how to convert such string into BigDecimal?
After adding validator to the marshaller in IntegrationConfig :
marshaller.setValidationEventHandler(new MyValidationEventHandler());
I discovered that the SOAP document (with commas in the sales values) is not validated against the WSDL:
iswlMyValidationEventHandler : LINKED EXCEPTION: java.lang.NumberFormatException
I think the only solution for that is to request for a proper WSDL file or for a proper WS response to the service provider.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.