50

I'm trying to create a web service client using CXF to consume a WCF web service. When I use wsdl2java it generates objects with JAXBElement types instead of String.

I read about using a jaxb bindings.xml file to set generateElementProperty="false" to try to fix the problem, but the web service I'm consuming contains 7 imported schemas.

How can I specify the generateElementProperty="false" on all seven schemas, or is there a way to apply it to all schemas?

Jens
  • 67,715
  • 15
  • 98
  • 113
ScArcher2
  • 85,501
  • 44
  • 121
  • 160

3 Answers3

73

You have to create a binding file as below, this will get applied globally and use it as wsdl2java - b "bindings.txt" "wsdl"

<jaxb:bindings version="2.1" 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
   <jaxb:globalBindings generateElementProperty="false"/> 
</jaxb:bindings> 
priya
  • 950
  • 1
  • 10
  • 15
  • 8
    http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html For instructions on how to set a bindings file using the maven plugin. – ScArcher2 Jan 19 '11 at 16:36
  • 1
    It would be better to use a more specific file extensions for the mapping file such as `.xml`or `.xjb` as proposed here http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html#wp148366 – schnatterer Apr 11 '14 at 07:18
  • 1
    And if you already have a jaxb:globalBindings in your XSD or WSDL, just add the generateElementProperty="false" attribute to that node. No need to add another binding.xml in this case. – Alain Pannetier May 17 '15 at 07:00
  • @ScArcher2 Awesome.. Thanks.. I am using third party wsdl so made this xml file as shown in the main answer and defined it in pom.xml as shown in the link. It worked. – Mital Pritmani Aug 04 '15 at 13:38
  • If I use this binding file the data posted and returned is empty. – Panu Haaramo Sep 09 '15 at 08:40
  • For creating a dynamic client, use the following: `JaxWsDynamicClientFactory.newInstance().createClient("wsdl", Arrays.asList("bindings.txt"))` – Gat Mar 18 '18 at 10:03
0

Note that in my case I had to use <xjc:simple in my jaxb binding file to get rid of the JAXBElement request and response wrappers in the @Endpoint:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified" attributeFormDefault="unqualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
    <xs:annotation>
        <xs:appinfo>
            <jaxb:globalBindings>
                <xjc:simple /><!-- it did only work after adding this -->
            </jaxb:globalBindings>
        </xs:appinfo>
    </xs:annotation>
</xs:schema>
yglodt
  • 13,807
  • 14
  • 91
  • 127
0

If we are using a CXF version compatible with Jakarta EE, we should change the syntax to:

<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings xmlns:jaxws="https://jakarta.ee/xml/ns/jaxws"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <jxb:globalBindings generateElementProperty="false"/>
</jaxws:bindings>
JuanMoreno
  • 2,498
  • 1
  • 25
  • 34