• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What are the ways to convert java type to xsd type?

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While sending the response from java to axis client. axis throws classcast exception. What are the ways I can map a java type to xsd type in axis. The type to be converted in xsd is complex type.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rtfm
Do you use Axis2?
Hava a look at chapter 16 ADB and chapter 17 JiBX Data Binding of the online documentation.
Apache Axis 2 Documentation
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that links details about how to convert from xsd to java. I want otherwise. Probably java2wsdl is one solution. I am not sure about its working.
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the requirement is to convert java to xsd at runtime. So, java2wsdl will help or not is doubtful.
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
It seems like things are not entirely clear on your part, so:
1. Data binding alternatives, such as ADB, JiBX, JAXB etc. are responsible for both marshalling and unmarshalling, that is creating an XML representation from one or more Java beans and also creating one or more Java beans from an XML representation.
2. Java2WSDL is used to create a WSDL when you are doing code-first web service development in Java.
3. WSDL2Java is used to create stubs, data beans etc. when you are doing WSDL-first development.
The above two are thus only used at development time, not at runtime.

References (these are for Axis 1, but the principle is the same):
http://ws.apache.org/axis/java/user-guide.html#Java2WSDLBuildingWSDLFromJava
http://ws.apache.org/axis/java/user-guide.html#WSDL2JavaBuildingStubsSkeletonsAndDataTypesFromWSDL
Best wishes!
 
Xin Zoo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ivan is absolutely right! I do not understand why you want to dynamically change your WSDL by updating the XSD for different complex types. Maybe you can explain this. I believe this is not a good idea. Because the WSDL should be stable so people can rely on your service and service interface(s).

The only reason i could imagine is, your clients want to send object types which you do not know to your service. But in this case you should rather define a meta model for these objects and declare this in your WSDL. I do not know how complex your objects are, but i could think of some meta model like this:

But i do not know if this applies to your use case.
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I don't want to change WSDL format at runtime or anytime. My java application has done some processing and I want this to be sent back to client as response. Java2Wsdl needs to be run each time to convert java objects to wsdl objects, or that is what I assume (correct me). So, I want thta once application finsihes processing , these java objects should be converted to xsd type by any means, afterwards those xsd types can be send easily through response.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
There seems to be a little misunderstanding on your part, as far as I understand.
A WSDL defines the structure of the data sent in requests to a web service and received in the responses from the web service.
The marshalling and unmarshalling of XML <-> Java objects is taken care of by the web service stack based on the information in the WSDL. This is nothing that you normally should have to care for. So, as a conclusion, from your web service method you only need to return regular Java objects - the marshalling will, as before, be taken care of by the web service stack.
This is not the entire truth, but I do not want to confuse you, or anyone else, with special cases at the moment.

Java2WSDL is a tool that is used to generate artifacts (for instance WSDL, deployment descriptors, etc etc) from annotated Java code that the web service stack needs when deploying a service. It is simply a convenience, instead of you writing all those things by hand each time. This tool is used by the developer and is NOT responsible for marshalling or unmarshalling.
Hope things have become more clear!
Best wishes!
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ivan Krizsan wrote:
The marshalling and unmarshalling of XML <-> Java objects is taken care of by the web service stack based on the information in the WSDL. This is nothing that you normally should have to care for.



I am using axis2. In my application, I am converting all those xsd types to corresponding java types myself. So, after UnMarshalling takes place, I am converting xsd objects to appropriate type of java. Similarly, before marshalling back to user, one way I am seeing is to reconvert all java type to xsd type and then let axis do the marshalling.

N.B.- [Let me be clear that here, marshalling and unmarshalling terms are used from my end. So, marshalling means I am sending the response and unmarshalling means, I am getting the inputs from the request.]

Now, you said that I don't have to take care of marshalling unmarshalling, that is true, but what about the type of objects axis requires to perform those operations. Without converting axis2 throws ClassCast Exception
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic