Generate WSDL dynamically - java

I have meta data that can be used to describe several hundred new web services and would like to dynamically create WSDL files from within my own Java class. I see many ways to do this when you have Java methods you want to expose as web services. Unfortunately that approach does not work for me as I have a single runtime method that can service many different operations and services. It's dynamic and as such does not have static classes that can be bound via map.xml. My plan is to generate WSDL files that will allow incoming SOAP envelopes to be received via HTTP POST, recognized, transformed and handled by my existing method.
This is to allow web service access is a 20 year old proprietary dynamically callable back end. I am certain that the meta data for each service can be easily presented to the outside world as web services and operations.
I could always write a custom builder by appending text to a StringBuilder but that least desirable choice. It would be far more reliable if there was an API I could use that would take in the essential items and attributes and when complete, validate and render a properly formed WSDL file.
I would like this to be generic and not require proprietary add on classes from others like what I might find in WebSphere.

In such case I would consider implementing web service using Provider API (standard part of JAX-WS).

In the end we built a WSDL generator using the .NET 4 System.Xml.Schema and System.Web.Services.Description namespaces. The generated WSDL is used in both Java and .NET to build client and server interface classes. It took a while but we have most of the services up and running, and they are totally platform agnostic.

I prefer to use Spring Web Services. Where it can take an XSD with reasonable defaults and turn it into a WSDL.
See sws:dynamic-wsdl in http://docs.spring.io/spring-ws/site/reference/html/server.html#server-automatic-wsdl-exposure

Related

Is there a way to build a java rest service so that wsdl can be autogenerated from it?

One problem that continuously comes up at my workplace is creating clients for Java rest services that we create. We have 4 different programming languages to support and it is costly to create clients for each programming language. Often this means our web services aren't available in a cross platform manner since we rarely have time to build all of the clients.
SOAP provides this type of discovery and machine created client mechanism based off of tools that consume WSDL but our architectural direction is to write REST based services in Java instead of SOAP services.
We would also prefer not to write WSDL documents by hand that expose these REST web services. In a .NET environment, WCF and ASMX web services automatically create the WSDL for consumption in other applications, but this is not a direction my team is allowed to pursue.
Can this be done in some fashion for a Java based REST service?
How can this be done without having to invest a lot of manual labor?
We're currently using spring controllers but might be able to argue for a different Java framework if it provides better velocity.
Jersey (JAX-RS implementation) has support for WADL. You can use Jersey to automatically generate a WADL and there is also some support for generating Java clients from the WADL.
That's for Java, and I don't know if it's more than basic support, but I doubt you can pull it off for 4 different programming languages.
You might want to read these first though (tl;dr: REST is more than a CRUD style Web API and is different than SOAP):
Do we need WADL?
Why the slow WADL uptake?
You may want to check third party tools like swagger (http://swagger.io/) and mashery. I know swagger has support for client generation.

GWT and SOAP classes

I have a Web Server which uses SOAP to communicate with a several resources.
I'm using pure JavaScript for the Web App interface. There are allot of data changing between the client and server which includes classes returned by SOAP requests.
I use GSON to create JSON objects from the SOAP responses (which can be all sorts of custom classes) and in JavaScript and just need to access the JSON fields.
Now I was thinking about using GWT on the client but started to have some doubts when planning the implementation.
If I use GWT all the classes generated for the SOAP interface must be accessible to the GWT compiler as I wont be using JSON but the classes directly through Assync Requests.
Now the problem is that there are allot of possible versions of this classes depending on the resource software version itself.
If I continue to use JavaScript that's not a very strong issue because the JSON encoded by the Server using GSON can be of any kind and if it doesn't have a particular attribute that's ok due to JavaScript type free nature (I can just check JsonSoapResponse.field22 != undefined).
If I use GWT will I need to have as much class versions as there are in the server side?
I thought about using JavaScript Overlay types but won't that require rewriting almost all SOAP classes to extend JavaScriptObject and expose their methods?
You could take a look at the AutoBean mechanism.
You will not beed JavaScript Overlay types anymore, just interfaces and the GWT Compiler will do the rest.
see: http://code.google.com/p/google-web-toolkit/wiki/AutoBean

Calling a webservice (asmx) from different language

from a non technical intermediary I got a question for a number of files (.xsd and .wsdl) for an external organization that wil be using our webservice.
This is de first time for me that i've written a webservice for an external party that wil be using a different technique other than .NET (it will be java).
as read in the post: How to generate XSD files for web service I think only sending the wsdl file wil be sufficient.
Can someone tell me if i'm right. If not so. How do i generate a fitting xsd with this wsdl?
For what I know, exposing WSDL is enough.
Every language able to read wsdl could create proxies, wrappers and/or classes to make it easier to access/consume your webservice.
As described in Wikipedia page
The WSDL describes services as collections of network endpoints, or
ports. The WSDL specification provides an XML format for documents for
this purpose. The abstract definitions of ports and messages are
separated from their concrete use or instance, allowing the reuse of
these definitions. A port is defined by associating a network address
with a reusable binding, and a collection of ports defines a service.
Messages are abstract descriptions of the data being exchanged, and
port types are abstract collections of supported operations. The
concrete protocol and data format specifications for a particular port
type constitutes a reusable binding, where the operations and messages
are then bound to a concrete network protocol and message format. In
this way, WSDL describes the public interface to the Web service.
WSDL
is often used in combination with SOAP and an XML Schema to provide
Web services over the Internet. A client program connecting to a Web
service can read the WSDL file to determine what operations are
available on the server. Any special datatypes used are embedded in
the WSDL file in the form of XML Schema. The client can then use SOAP
to actually call one of the operations listed in the WSDL file using
XML or HTTP.
Just expose a test url to them. You should do that anyway for them to be able to really test things as they develop their client. After this is done it's just a matter of getting them to retrieve http://[insert url]?wsdl

Is it possible to consume an EJB 3 Web Service form a Java client without first generating client stubs/proxies?

In most tutorials that I have seen so far people are using wsconsume or something like that to create classes that clients can use to access an EJB 3 Web Service.
Is this the only possible option? As my EJB's interface is annotated with WebMethod, WebParam, etc. isn't it possible to create a dynamic proxy or use runtime bytecode enhancement to create the proxies, etc. on the fly? E.g.:
MyWebService webService = WebServiceEnhance.getWebService(MyWebService.class);
webService.webMethod("foo");
A link to good reference material is also highly appreciated.
One way is to deal with pure XML request/response. You can trap sample request/response for the web service you want to consume using either SoapUI or Fiddler and then use these samples as templates within your client.

clarification on the concept of "web service"

Im a little confused on the varying definitions and implementations of web services available as implementations. Need some clarification please.
Ones I have used till now:
If a vendor gives me a specific format of XML that I can send populated with data to request and I make a simple HTTP POST over the internet passing in the XML String as the payload, is this a web service call ? If so, is there a specific name to it, this kind of web service ? Because obviously, it does not use anything like Axis, WSDL or SOAP to establish this connection.
A variant of this is If the vendor gives me an XSD, I use JAXB to make a java class out of it and pass in the serialized version of the object, which eventually works out to be the same as option 1.
RESTful web service: Vendor gives me a URL like http://restfulservice/products and I can make HTTP Requests to the URL and depending on what HTTP verb I use, the appropropriate action is called and the response sent over the wire.
Ones I have only read about\ have a vague idea about
SOAP. How does this work?.. Ive read the W3Schools tutorial and I undertsand that there is a very specific form of XML that is standardized according to W3C standards that we use to pass the same kind of messages as we did in option 1. But how does this work in real life? Vendor sends me what? Do I generate classes? Do I serialize some objects and http post them over to an address? Or do the generated objects themselves have connection methods that will do them for me?
What about WSDL? When does a vendor send me WSDL and what do I do with it ? I guess I can generate classes from it. If yes, then what do I do with the generated classes ?
When do I need that axis jar to generate classes from something that the vendor sends ?
As you can see, I have some clear and other mostly vague ideas about the different kinds of web services available. would help if someone ould clarify and\or point to more real-world resources. I've looked a little bit into Java Web Services on the internet and the numerous four letter acronyms that get thrown at me make me dizzy.
Thanks
If a vendor gives me a specific format
of XML that I can send populated with
data to request and I make a simple
HTTP POST over the internet passing in
the XML String as the payload, is this
a web service call ? If so, is there a
specific name to it, this kind of web
service ?
This is still a web service, yes. It doesn't have an "official" name, I usually refer to it as XML-over-HTTP, mainly because I can't think of a better name.
SOAP. How does this work?.. Ive read
the W3Schools tutorial and I
undertsand that there is a very
specific form of XML that is
standardized according to W3C
standards that we use to pass the same
kind of messages as we did in option 1
SOAP provides a standard wrapper layer around the sort of messages you were sending in (1). This wrapper provides information such as an indication as to which operation you are invoking. It can also provide security services, transaction information, and so on. It's a pretty thin layer, usually.
What about WSDL? When does a vendor
send me WSDL and what do I do with it
? I guess I can generate classes from
it. If yes, then what do I do with the
generated classes ?
Again, WSDL is a pretty thin layer, this time around an XML Schema. It defines the operations that SOAP messages will invoke at runtime, as well as the Schema types of the requests and responses. Its a way of formalising the XML document exchange interface.
Say, for example, you had an XML Schema, and have a web service as you described
Using JAXB to generate java source from the schema
Send XML documents conforming to that schema over HTTP to the web service
With WSDL and SOAP, you would extend this a bit :
Write a thin WSDL wrapper around the XML Schema, formalising which operations are available.
Use a WSDL import tool to generate client/server stubs for that WSDL/Schema. In Java, this often incorporates JAXB.
Use a SOAP client/server to invoke the web service
As you can see, it's essentially the same process. The difference is that SOAP/WSDL provides additional information and context to the tools, allowing those tools to do more of the work for you. It's not hugely different, though.
If you get a WSDL document from somewhere, all you really need to know is that it defines a service interface. You run it through your favourite language's binding generator to make some code that you can use to call the service. Typically that means you'll be talking over the wire to the service using SOAP messages over HTTP. SOAP's just a wrapper round sending pretty arbitrary XML messages.
Axis is a library for doing this stuff in Java (both client and server side). I suspect that there are better implementations in other libraries.

Categories