Excluding XSD while generating Java files by WSDL2Java in CXF via Ant - java

I have 2 WSDL for 2 different services which uses same XSD for Input and Output messages. Now I want to use CXF WSDL2Java by ANT target and create the server java file out of it one by one, but I don't want to recreate the java files in 2nd time which created earlier in 1st time. As both uses same XSD and almost all Input and Output parameter is same but the purpose of the service is different.
Kindly help me how can I achieve this by CXF and ANT.

As CXF documentation says you can configure Ant to parse your XSD: http://cxf.apache.org/docs/wsdl-to-java.html
Maybe you can define two targets, one that results in your XSD files parser and java files created and a second one that does not need to do this. Later you can integrate these two targets with your Ant workflow as you need.

Related

Java : Working with multiple versions of XML Schemas

I have an application that receives an XML message and then parses it to perform further processing.In order to have this working in my application, after receiving the XML string, I call the JAXB marshaller to marshal it in to java POJOs and the processing takes from here after.
This thing works well till the time I have one version of XML.
Problem
But the problem comes when there are more than one versions of the same XSD. And my application has to deal with both version of messages. Clients to my application may send a old version xml or they may send a latest version XML.
For JAXB I have to convert the XSD into java pojos using JAVA XJC tool, and the problem arises when I convert the latest version of XSD it has the same class names as the previous version, but internal fields and hierarchy of the class is different. this causes problems even if i put the XJC outputs in different jars for each version.
Expected Solution
This change in version is expected to happen every 6 months and I have to make my system able to read the newer version XMLs also alongwith the old versions.
I want to know how to manage this XML processing in JAVA with JAXB or some other framework.
Shall I use SAX Parser? I have read that its not that efficient as compared to JAXB. And after working on SAX parser for last few days, i found out that it can be error prone as it involves looking for each element and getting values out of it and putting it into a java structure of our own and that is a lot of effort as compared to JAXB.
*
Question
Is there any simple solution similar like JAXB ?
*
Temporary Solution Used
I have used a temporary solution, with which i am not happy as a good solution. What I did is, I created a seperate jar for each XSD version using XJC tool. And created different packages ion each jar e.g.
1. Pojos for version 1.2 are in a jar with base package com.cgs.v_12
2. Pojos for version 2.0 are in a different jar with base package com.cgs.v_20
i have added both as a maven dependancy to my system and using them for processing different versions.
For JAXB/ any other solution that maps between XSD -> POJOs, this will be a 1-1 mapping, especially if the POJOs are generated.
Do you have to
(1) map the entire XML to POJO, or
(2) a subset of that XML to a static/ fixed POJO model?
If (1), since the changes in the subsequent versions cannot be anticipated, I believe the solution for the above will be use a strategy pattern to select the correct JAXB artifacts based on the version
If (2), you can explore using XPATH, defining XPATH mappings per version.

WSDL to java code approach generating extra classes

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.

Webservices :Understanding the task assigned

I am a complete newbie to web services and I am working alone. My lead mailed me a task to complete. I think he has hard coded the information and he wants me to replace the hard coded data from web services.
He has mailed me a WSDL file and said
Make the jar file from the wsdl.
What does this mean ?
There are tools which will generate Java code to talk to web services, performing serialization and deserialization effectively, so that your client code can talk in terms of Java objects rather than raw SOAP.
You should find out which of these tools is being used in your project, and apply it to the WSDL provided.
(Also, it's a good idea to get used to asking for more information when you don't understand the assignment. A good team leader - or anyone, really - should be more than happy to help you.)
Generate the Java stubs from the wsdl.
wsdl2Java
wsdl2Java
If you are familiar with eclipse, then the task can be completed easily. I think he is asking for the jar of client stub which can be produced from the wsdl.
In that case do: In eclipse, make sure you have webservices plugin. Follow this after that
You will have few .java files being exported. Try to compile them and generate the .class files. Now jar the .class files using command in command prompt
jar -cvf <Name of the jar>.jar *

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 parse wsdl and xsd files?

I've been looking for a way to programmatically parse WSDL and associated XSD files to get values from annotation / documentation tags. I managed to get values from wsdl using wsdl4j, but how do i do this for XSD files? I tried to use XSOM but for some reason i always get null.
1). Hope this link will be useful for you to choose the best parser, Parse WSDL Effectively.
I have tried using Apache Woden, WSDL4J and Membrane SOA. Among these, Membrane SOA seems to be developer friendly.
2). Place the dependent XSD's in the folder where you have placed the WSDL. Then try parsing your WSDL, it should work fine.
Maybe the JWSDL help will be of service. It also makes calls to the services.
Here a discussion on the subject

Categories