JAX-WS return empty lists

2019-02-26 06:11发布

I'm new in web services. I have faced some problem. At the server side i'm using spring-ws. At the client side i'm using jax-ws. With wsimport tool i have generated java classes according to my wsdl.

Everything works fine, but for some reason jax-ws does not parse arrays and list correctly, all lists are empty

I'm absolutely sure, that response is form correctly, tested it with soapui, also i'm using logging interceptor to log outcomming responses.

Below is the snippets of response

response looks like

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <firstElementResponse>
         <name>hello world text</name>
         <name>hello world text</name>
         <name>hello world text</name>
      </firstElementResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

and the snippets of wsdl

<xs:complexType name="sayHelloResponseType">
  <xs:sequence>
    <xs:element maxOccurs="unbounded" minOccurs="0" name="name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

To generate client code i use wsimport.

SayHelloResponseType resp = serv.sayHello(r);
List<String> name = resp.getName();
System.out.println(name.size());

Thank you. Any help will be highly appreciated.

2条回答
甜甜的少女心
2楼-- · 2019-02-26 06:37

Seems it's just an invalid body of response, that does not math wsdl shema. Neither spring-ws neither jax-ws throws exception. It simply parse invalid data to empty list without any warrnings.

org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor saved my day

probably i have to tweak logging for jax-ws to avoid it next time

查看更多
何必那么认真
3楼-- · 2019-02-26 06:53

I just answered a similar question in How can I handle Castor unmarshaling of SOAP messages when the namespace is defined inside the operation tag? - if you're using Spring-WS, you're writing contract-first web services, so make sure you really nail that contract down. Put all your elements in a namespace, make sure your XSD schema expects elements to be qualified, and declare ns-uri and ns-prefixes in your Castor mappings. It's worth the effort.

查看更多
登录 后发表回答