Skip to main content

Wrong value set in a binding object in a web service

1 reply [Last post]
danid_d
Offline
Joined: 2010-12-21
Points: 0

Hello,
I am getting wrong values in my object when it is received at the server side:
I have the following input that I send to my web service:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tns:uploadRequest
xmlns:tns="namespace1..."
xmlns="namespace2...">
<tns:uploads>
<discounts>
<data>
<line time="2010-11">109.80</line>
<line time="2010-12">11.0</line>
</data>
</discounts>
</tns:uploads>
</tns:uploadRequest>
I have written XSD files to describe my xml documents, and used them to generate the binding classes with JAXB. The element "line" is a double according to my xsd schema.
I have a test client with fire this message:
String file = "C://data//test.xml";
try {
URL url = new URL(Configuration.UPLOAD);
MyUploadService service = new MyUploadService (url, TestToolkit.WS__SERVICE_NAME);
Dispatch<Source> dispatch = service.createDispatch(TestToolkit.WS__PORT_NAME, Source.class,
Service.Mode.PAYLOAD);
String xmlIn = TestToolkit.read(file);
StringReader reader = new StringReader(xmlIn);
Source sourceIn = (Source) new StreamSource(reader);
Source sourceOut = dispatch.invoke(sourceIn);
String xmlOut = TestToolkit.getXmlFromSource(sourceOut);
System.out.println("xmlOut " + xmlOut);
} catch (Exception e) {
e.printStackTrace();

}
I have a web service that expect an input which is defined in one of the xsd schema's and wsdl. In my Server I implemented the service and it look like:
public XmlUploadResponseType getUpload(XmlUploadRequestType uploadRequest) throws UploadException {
//....
}
The XmlUploadRequestType Object describes the root element of the XML file and is generated.
Now, if I change the value of the element "line" to a non double (not a valid value) I get a zero value for that element in my server side. Can anyone explain me how this happens?
Somewhere is the xml file transformed to binding classes. According to the xsd it should not be possible to have a non double and the zero is set instead. Can I set the validation somewhere to only receive valid objects in the server?
Thanks a lot,

Danid

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
danid_d
Offline
Joined: 2010-12-21
Points: 0

I found the solution. The validation can be set on in the class that implements the web service by using @SchemaValidation() annotation:
@EJB(...)
@WebService(...)
@BindingType("http://schemas.xmlsoap.org/wsdl/soap/http")
@SchemaValidation()
@HandlerChain(file = "HandlerChain.xml")
public class UploadServiceImpl implements UploadEndPoint {
}
this Link was useful:
http://java.sys-con.com/node/952429