Integration of jaxb binding file using CXF to generate client based on WSDL

bhcmoney picture bhcmoney · Jun 5, 2015 · Viewed 9.2k times · Source

I am trying to incorporate a JAXB binding file when using CXF XJC plugin to call wsdl2java. So I actually am generating the wsdl and using

-createxsdimports

to create external schema files so I can then execute the JAXB binding on that specific file rather then having to use a JAXWS binding. I am looking for some help on the error I am getting or an alternate solution such as using a JAXWS binding file without externalizing etc.

Here is my WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="TestImplService" targetNamespace="http://service.logging.a/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://service.logging.a/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
  <import namespace="http://service.logging.a/" schemaLocation="TestImpl_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="method">
    <wsdl:part name="parameters" element="tns:method">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="methodResponse">
    <wsdl:part name="parameters" element="tns:methodResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="Test">
    <wsdl:operation name="method">
      <wsdl:input name="method" message="tns:method">
    </wsdl:input>
      <wsdl:output name="methodResponse" message="tns:methodResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="TestImplServiceSoapBinding" type="tns:Test">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="method">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="method">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="methodResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="TestImplService">
    <wsdl:port name="TestImplPort" binding="tns:TestImplServiceSoapBinding">
      <soap:address location="http://localhost:9090/TestImplPort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Here is TestImpl_schema1.xsd:

<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://service.logging.a/" elementFormDefault="unqualified" targetNamespace="http://service.logging.a/" version="1.0">
<xs:element name="method" type="tns:method"/>
<xs:element name="methodResponse" type="tns:methodResponse"/>
<xs:complexType name="method">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="tns:foo"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="foo">
    <xs:sequence>
      <xs:element name="map">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="entry">
              <xs:complexType>
                <xs:sequence>
                  <xs:element minOccurs="0" name="key" type="xs:string"/>
                  <xs:element minOccurs="0" name="value" type="xs:anyType"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="methodResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="tns:foo"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

Here is my binding.xml file:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1">
  <jaxb:bindings schemaLocation="wsdl/TestImpl_schema1.xsd">
    <jaxb:bindings node="//xs:complexType[@name='foo']//xs:element[@name='map']">
      <jaxb:property>
        <jaxb:baseType name="java.util.HashMap;" />
      </jaxb:property>
    </jaxb:bindings>
  </jaxb:bindings>
 </jaxb:bindings>

Here is my Maven dependency:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>

                <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/resources/META-INF/wsdl/TestImpl.wsdl</wsdl>
                        <bindingFiles>
                            <bindingFile>${basedir}/src/main/resources/META-INF/wsdl/binding.xml</bindingFile>
                        </bindingFiles>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

And here is the error I am getting when attempting to run the plugin:

[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.7.13:wsdl2java (generate-sources) on project Test-Client: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:2.7.13:wsdl2java failed. IllegalArgumentException: Illegal character in opaque part at index 2: C:\..\Tester-Client/src/main/resources/META-INF/wsdl/binding.xml -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

Answer

bhcmoney picture bhcmoney · Jun 8, 2015

Nothing actually needed to change. In the CXF plugin I had the wrong path to my binding.xml file. After correcting the path everything seemed to work as expected.