java - How to make integer element value in xsd not become zero when no value entered in SOAP XML? -


I have a Java web service application designed with jaxb and spring webservice.

I have a complex type like this in an xsd:

  ...  & Lt; / Sequence & gt; & Lt; / ComplexType & gt; Using the  xjc , I get the Xbox class from XSD:  
  Public class GetRecordsRequest {protected integer MaxRecords; Public Int MXRecs () {Return MaxRecord; } Public Zero Set Maxures (int value) {this.maxRecords = value; }}   

Now, the problem is that if I have entered an empty value for the maxRecords in the soap request xml from the Sopadhila application:

  & lt; Soapenv: envelope xmlns: soapnavi = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: ns1 = "http://www.test.com/ns1" & gt; & Lt; Soapenv: header / & gt; & Lt; Soapenv: body & gt; & Lt; Ns1 also: GetRecordsRequest & gt; & Lt; Ns1 also: maxRecords & gt; & Lt; / Ns1 also: maxRecords & gt; & Lt; / Ns1 also: GetRecordsRequest & gt; & Lt; / Soapenv: Body & gt; & Lt; / Soapenv: envelope & gt;   

The value of maxures is in the webwave endpoint class method. I expected this application to throw an error or an exception because I had set minOccurs = "1" in the adid, I thought it was mandatory.

  @PayloadRoot (Namespace = "http://www.test.com/ns1", Local Part = "GetRecordsRequest") Public JAXBElement & lt; GetRecordsResponse & gt; GetRecordsRequest (JAXBElement & lt; GetRecordsRequest & gt; jaxbGetListMessage) {GetRecordsRequest Request = jaxbGetListMessage.getValue (); Println (request.getMaxRecords ()); // print 0 value ...}   

I also changed minOccurs to xsd, then typing is integer, but the maxRecords value is still 0, I hope this Will be futile

I know that the only way is to convert the type of maxRecords to a string or a token, but I like if there is another solution along with maintaining its integer type. Note: Note: Note: To make the code easier to read, I removed the unrelated parts and used the code above / Simplified XML If you've got a syntax typo, please let me know in the comments section, because I have manually typed most of the code.

I follow the suggestions from others to use PayloadValidatingInterceptor And add something like this in the app. Context XML and it works:

  & lt; Bean class = "org.springframework.ws.server.endpoint.mapping.PayloadRootNnationMethodEndpointMapping" & gt; & Lt; Property Name = "Interceptor" & gt; & Lt; List & gt; & Lt; Ref local = "validation interceptor" /> & Lt; / List & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt; Bean id = "Validation Interceptor" class = "org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor" & gt; & Lt; Property name = "schema" value = "/ web-nf / schema / webservice.xsd" /> & Lt; Property Name = "Validate Values" value = "Correct" /> & Lt; Property Name = "Valid Treatments" Value = "True" /> & Lt; / Bean & gt;   

Thank you for everyone who uses payload validation interceptor.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -