Rop
Rop

Reputation: 3409

spring-ws -- how to create java-interface from WSDL?

I'm creating a WSDL-first webservice with spring-ws in gradle.

Some examples I have been looking at (e g https://spring.io/guides/gs/producing-web-service/ ) it seems they will only generate the java-classes from the XSD-schema, but no java-interface (or abstract-class) from the WSDL service-operations?

Also, in the spring-ws doc, it says "... in Spring-WS, writing the WSDL by hand is not required ...".

I would like to ensure the full WSDL is correctly and completely implemented...

Upvotes: 2

Views: 5061

Answers (3)

Ashu Kanaujia
Ashu Kanaujia

Reputation: 259

If you want only interfaces from WSDL just use wsimport command. Its part of jdk so no extra things needed.

run the commend: wsimport -keep wsdlUrl it will generate all the interfaces and client code (.java as well as .class)to hit the web service. just search your interface.

Let your generated URL is :http://www.host.com/testservice?WSDL

then commend will be wsimport -keep http://www.host.com/testservice?WSDL there are much more options with wsimport commend use as you want. http://docs.oracle.com/javase/7/docs/technotes/tools/share/wsimport.html

Upvotes: 1

user6075038
user6075038

Reputation:

ws import generate all the client side code. asn wellm as much more things try wsimport, wsgen for more details

Upvotes: 0

malaguna
malaguna

Reputation: 4233

With spring-ws you can build contract first WS, although it is not necessary to build your WSDL, because it can generate it dynamically.

For java objects, spring-ws allows you to marshall/unmarshall using jaxb2 or similar. This way, you can obtain java classes from XSD, but this code generation is made by the marshaller.

From a server point of view, you create WS Endpoints that match WSDL operations. That Endpoints are annotated and bound to a request/response java objects. Thus, spring can generate dynamically WSDL, but you can use your own WSDL.

From a client point of view, you need a WSTemplate that needs to retrieve a WSDL (static or dynamic, it doesn't mind). Using this way, WSTemplate ensure you can call all server endpoints, without implementing client stubs or generated code.

I rather prefer to use static WSDL, because dynamic generation can't ensure that your WSDL change if you upgrade Spring or so, and this could break compatibility with your clients.

However, while I am developing I use dynamic WSDL, for the shake of simplicity. Once I have the service I want, I get dynamically generated WSDL (customize if I need) and use it as static. That WSDL is full for all the endpoints.

Hope it helps!

Upvotes: 1

Related Questions