WSDL to java code approach generating extra classes - java

Initially I have used bottom-up approach (Code to WSDL) to generate a wsdl file using three classes.
Now using the generated wsdl file I am trying to create the code i.e. top down approach using eclipse and its creating lot of classes than what I have used initially to create a wsdl file. How do I get rid of unnecessary classes and get the original classes which I have written?

You will most likely never get the precise original code if you go with code -> generate WSDL from code (e.g. jax-ws) -> generate code from WSDL (e.g. wsimport) and that is fine because WSDL-driven development and it's counterpart are two different approaches.
With WSDL-driven approach your specify your WSDL contract first and then usually would generate you server/client code from the contract.
With code-first approach you define the service and it's operations in Java and would usually rely on a framework to generate the final WSDL.

Related

Using java to generate WSDL with given parameters

I am looking for some tutorials or resources that may assist me with a problem in Web Service Composition, where I need to a generate WSDL with given inputs and parameters. I want to start from scratch like java with some "element" method that can output a basic WSDL hierarchy. Thank you.
P.S. I did spend a reasonable amount of time looking for above-mentioned stuff but I do consider the probability of encountering an open source implementation from this community.
Have a look at the tools provided in the Apache CXF project, which allows generating WSDL from Java source and vice versa. Similar functionality is provided by Apache Axis2.

Compare two wsdl files to be equal

I have an older webservice and I want to rewrite some code. In the end the new wsdl should be equal/same than the "old" wsdl.
The problem is, that both WSDL files have different ordering of fields ...
How can I gurantee, that users do not have any problems due to the code changes and can still use their clients, because the interface has noc changes? How can I compare both wsdl files, if both have the same meaning/interface? Does someone knows a tool to compare the two wsdl files?

Set up maven build for xjc for multiple schemas in the same xml namespace?

I'm working on a project where we have Jersey/JaxB based serialization system to talk to a web service. The service in question returns data wrapped inside an Atom feed.
An older part of the system wrote a one-off specific to their service XSD for Atom that was hard wired with only their particular elements. I now need to add support for a new service, which is doing a similar thing (using Atom as a "envelope"), but using significantly different elements and content schema.
I don't want to disturb the existing code, so ideally I'd like to do the same thing the previous project did: define my own schema for the parts of Atom that the new service is using.
I'm running into:
org.xml.sax.SAXParseException: 'feed' is already defined
I'm apparently hitting the limitation described in the XJC release notes: It is not legal to have more than one <jaxb:schemaBindings> per namespace.
Is there a way to set things up in our build so that if I have separate xjb files, I can run xjc independently over the two distinct schemas and generate code for each of them into separate packages? How do I work around this limitation?
We're using the maven jaxb plugin.
Just for the record, what we ended up doing was generating the code from the schema separately, and checking in the generated code. Since the ATOM schema's not changing, it was reasonably safe. Annoying to have to do it that way though.

How to create WSDL file given SOAP WSDL operations

I haven't had any experience with web service related development. So, any ideas will be greatly appreciated.
Suppose, I have a file listing draft specification of WSDL operations. Following is one example. How would I go about creating the WSDL file. Is notepad sufficient or do I need to have WSDL editor?
getHostSystemInfo
Returns detailed information about host systems specified via given IDs.
input HostSystemIdCollection(Collection of Strings)
Output HostSystemInfoCollection
HostSystemInfo
Id: mandatory
Properties: Following properties should be provided for host systems
HostSystemName
HostSystemProperty1
HostSystemProperty2
HostSystemProperty3
....
....
If the question is just "how do I create the WSDL" then you could indeed use Notepad and just write it, it's only XML after all. However, writing syntactically correct XML by hand is pretty dull, and error prone. So I would recommend using WSDL aware tooling for example an Eclipse editor
An alternative is to write some Java which expresses the interface, and from it generate the WSDL. There are many ways of doing this, including starting with an EJB and annotating it accordingly. A few googles should help you find what you need.
My experience is that simple POC situations tend to work well starting at the Java. Larger scale projects benfit from considered designs starting at the WSDL.
coding WSDL by hand is a big pain! i used a XML editor for creation of and then generated the stubs with JAXWS. It is important to understand and differences of the WSDL styles, which is not trivial (have a look at WSDL styles). a good help is to import the WSDL schema to your IDE (eclipse, idea) and then work with autocompletion.
just for interest, why are you using WSDL + SOAP. if you have a choice and you use anyway HTTP, have a look at REST. It can make implementation of web-api a LOT easier, both on server side and for api-clients.
If you haven't done any web services before, I would strongly recommend a WSDL Editor. The Netbeans has a plugin that should help.
The other way of doing it, which may be easier is by using the Java annotations defined in JSR 181.
Of course you could use the worst text editor in the world (!) but I'd seriously consider using any decent XML editor or IDE (Eclipse's WSDL support is pretty decent). This will save you a lot of pain and suffer.
Or, if this is an option, you could just annotate a Java class with JAX-WS annotations and have your WSDL dynamically generated from the Java code. Personally, I prefer the WSDL-first approach, the Java-first approach is just a suggestion to get you started.
You could use Axis2 to create that for you.

Working with large wsdl, can we trim it?

My webservice provider give me a large WSDL file, but we are going to use only a few function inside.
I believe that the large WSDL have negative impact to the application performance.
We use the webservice in client appliction, startup time and memory usage are issues.
Large WSDL means that jax-ws will takes longer to do binding and will takes more memory for the stub class.
Is is possible that we trim WSDL file to a lightweight version? Are there any tool for this purpose?
I do not think my webservice provider will generate another WSDL for us. We may have to do it auto in the build script.
In short, your answers are "No tool, but you can DIY".
I wish there are simple tool can do it because my WSDL contains too many unused function and schema of data structure.
If I can automate it, WSDL -> trimmed WSDL -> generate client stubs classes. Nothing unused will be generated, no misuse, no maintenances required, we will not touch on the generated code, and I can really focus on the code which in use. Smaller JAR, shorter XML parse time. If the WSDL get updated, I will had only to rebuild client stubs classes and run unit test.
I tried to keep off from human invoked. It takes time, easily to get mistake, and have to redo every time every little change on the original WSDL.
I am not conversant on the WSDL schema. I am thinking can it be done by XSLT?
The size of the WSDL will have zero impact on performance... unless you are downloading it and/or parsing it for every request. And if you are doing the latter, don't. It need only be processed when the service changes, and the service should always change compatibly, with continuing support of old messages (at least for some overlapping time period).
You should consider processing a WSDL to be a program change, and do it as you would any release, with versioning, and testing, etc.
The problem is not with the size of the WSDL itself. It's the size of the generated code that matters. For instance, if you use Axis2 to generate your code from a large WSDL, you'd end up creating a Request/Response class for every WSDL operation, as well as the classes of their return types. You'd end up with a huge stub class later on, which could affect performance since it would import classes that are required by web service operations that you don't need.
There's no easy tool to do that. I usually use notepad++ to do that, and YES you could always make mistakes while doing it.
Another common mistake is choosing to generate both Sync and Async style methods, when most of the time (In my case at least), you'd only use Sync style methods. This could dramatically increase the size of your stub as well.
I haven't used the tools that you're talking about, but you can successfully execute web service methods without the code ever touching a WSDL file.
This seems like a good time to run a quick test. Cut everything from the WSDL file except what you need to execute one of the simpler methods you plan to use. Reference that copy of the WSDL instead. If it works, you know what to do next!
There is no need to trim the WSDL. If you're set on going down this path, simply delete anything in the stub classes that you don't need. Just make sure to test it as you go to make sure everything is still working.
You could just manually remove the <wsdl:operation> elements corresponding to the methods you don't need and see if that's enough. You should be able to remove those elements without touching the rest of the file.
The physical size of the WSDL should not matter if you generate client stubs classes at compile time (e.g. via AXIS wsdl2java.) If you are downloading the WSDL and parsing it for each request then the download time will likely dwarf the parse time. Consider caching the file locally if the download time becomes an issue. If the parse time becomes an issue you may want to consider trimming the file or caching the parsed objects. Use care when caching or trimming the file as you will need to integrate any changes when your provider issues a new WSDL. Consider updating your cached/trimmed WSDL each time the service is restarted or at some interval.

Categories