How do I prevent JAXBElement<String> from being generated in a CXF Web Service client?
Asked Answered
C

3

49

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?

Cordalia answered 10/12, 2010 at 21:1 Comment(0)
O
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> 
Organize answered 3/1, 2011 at 11:4 Comment(6)
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.Cordalia
It would be better to use a more specific file extensions for the mapping file such as .xmlor .xjb as proposed here docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/…Hallway
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.Ricoriki
@Cordalia 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.Epidaurus
If I use this binding file the data posted and returned is empty.Decibel
For creating a dynamic client, use the following: JaxWsDynamicClientFactory.newInstance().createClient("wsdl", Arrays.asList("bindings.txt"))Kappenne
H
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>
Henshaw answered 13/6, 2019 at 7:2 Comment(0)
D
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>
Dock answered 25/2, 2023 at 15:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.