Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixed Content for JAXB not working from WSDL

I'm using NetBeans and I have two projects:

  • A EJB Module to generate a webservice and deploy it to GlassFish
  • A simple console client to test and consume this webservice

For the webservice, I'm using an XSD with mixed content elements. Adding a binding file for JAXB import with the following code worked:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings
 xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
 xmlns:xjc= "http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc"
 jaxb:version="2.0">
  <jaxb:globalBindings generateMixedExtensions="true"/>
</jaxb:bindings>

It generated this code:

@XmlMixed
@OverrideAnnotationOf
protected List<Serializable> contentOverrideForED;

I can live with this generated code, although it's not ideal.

My problem is with the client, for which I've added a Web Service Reference to my generated and deployed webservice, running simply on localhost.

Using the same binding file in WSDL Customization: External Binding File doesn't yield the content code, nor does using it directly as an option for Wsimport, nor using it as a Jaxb option. I have a feeling that this setting is being disregarded somehow, but how?

And why does the initial JAXB generation include it and why doesn't wsimport use it? I'm kind of puzzled here.

like image 445
Davio Avatar asked Nov 29 '13 15:11

Davio


1 Answers

Great question! I and my collegaues spent many hours to solve mixed type in class which I generated with wsimport. I try many adjust and get List<Object>, List<Serializable> or List<String>. We used simple wsimport and we didn't know about:

<jaxb:globalBindings generateMixedExtensions="true"/>

Now, I offer you to create simple wsimport batch script and this released for customer. I think you can use external binding file (-b parameter) in wsimport script.


Martin Grebac wrote great article about this topic:

it is a good decision to avoid use of mixed content, especially when designing a large schema with a lot of type extensions. Mapping that kind of schema to any binding framework is usually complex and leads to complications and slowdown of development. JAXB has never been designed to handle these cases in a convenient way - it is a Java <-> XML mapping framework, and it's not possible to represent this kind of content in a hierarchy of Java objects.

I fully agreed with a Martin. The JAXB is simple Java <-> XML mapping framework. But It is existing one customization which solved problem with multiple mixed type in one XSD. That is generateMixedExtensions="true". This customization is change the behaviour of JAXB.


I'd really like to know why wsimport does this differently from xjc  

I think you are change behavior of JAXB when use xjc and wsimport use simple JAXB without this customization.

Please check wsimport 2.0 or wsimport 2.1 documetntation for parameters. Here is link about mixed content model and if you use xs:any in mixed type can you adjust it.

like image 50
herry Avatar answered Sep 23 '22 06:09

herry