Devilluminati
Devilluminati

Reputation: 338

CXF generating SEI and java classes from wsdl

There a several ways of generating java classes from wsdl e.g. Apache CXF, JAXB and JAX-WS.

I need one solution that works with maven and a catalog file.

My problem is that I have two Maven modules A and B. One of the modules (module A) contains the logic classes and the other module (module B) contains the xsd files as resource. Now I want to generate the classes from the logic module (module A) and the xsd files should not be added to this module as resources.

I have already created a catalag.cat file that contains the namespace as PUBLIC and points to the mavenmodule.

An abstract on the catalag file:

PUBLIC "http://www.bipro.net/namespace/basis" "maven:de.bipro:bipro-common-libs:jar::!/bipro/BiPRO-Schemas/bipro-basis-2.7.0.xsd"
PUBLIC "http://www.bipro.net/namespace/beteiligungsverhaeltnis" "maven:de.birpo:bipro-common-libs:jar::!/bipro/BiPRO-Schemas/bipro-beteiligungsverhaeltnis-2.7.0.xsd"
PUBLIC "http://www.bipro.net/namespace/datentypen" "maven:de.bipro:bipro-common-libs:jar::!/bipro/BiPRO-Schemas/bipro-datentypen-2.7.0.xsd"
PUBLIC "http://www.bipro.net/namespace/evb" "maven:de.bipro:bipro-common-libs:jar::!/bipro/BiPRO-Schemas/bipro-evb-2.7.0.xsd"
PUBLIC "http://www.bipro.net/namespace/fahrzeug" "maven:de.bipro:bipro-common-libs:jar::!/bipro/BiPRO-Schemas/bipro-fahrzeug-2.7.0.xsd"
PUBLIC "http://www.bipro.net/namespace/foerderung" "maven:de.bipro:bipro-common-libs:jar::!/bipro/BiPRO-Schemas/bipro-foerderung-2.7.0.xsd"
PUBLIC "http://www.bipro.net/namespace/fragen" "maven:de.bipro:bipro-common-libs:jar::!/bipro/BiPRO-Schemas/bipro-fragen-2.7.0.xsd"

The POM:

<plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>3.2.2</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <extraargs>
                                    <extraarg>-catalog</extraarg>
                                    <extraarg>${basedir}/src/main/resources/bipro.cat</extraarg>
                                </extraargs>
                                <wsdl>${basedir}/src/main/resources/TransferService/TransferService_2.7.0.1.0.wsdl</wsdl>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated/cxf</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

The WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
              xmlns:wsp200212="http://schemas.xmlsoap.org/ws/2002/12/policy"
              xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
              xmlns:bipro="http://www.bipro.net/namespace"
              xmlns:wsu200207="http://schemas.xmlsoap.org/ws/2002/07/utility"
              xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
              xmlns:allg="http://www.bipro.net/namespace/allgemein"
              xmlns:xf="http://www.bipro.net/namespace/transfer"
              xmlns:wsoma="http://www.w3.org/2007/08/soap12-mtom-policy"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:partner="http://www.bipro.net/namespace/partner"
              xmlns:sepa="http://www.bipro.net/namespace/sepa"
              xmlns:nachr="http://www.bipro.net/namespace/nachrichten"
              xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
              xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/"
              targetNamespace="http://www.bipro.net/namespace"
              bipro:Name="TransferService_2.7.0.1.0.wsdl"
              bipro:Version="2.7.0.1.0">
   <wsdl:types>
  <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema"
              targetNamespace="http://www.bipro.net/namespace"
              attributeFormDefault="qualified"
              elementFormDefault="qualified">
     <xsd:include schemaLocation="TransferService_2.7.0.1.0.xsd"/>
  </xsd:schema>
 </wsdl:types>
   <wsdl:message name="listShipmentsRequest">
   <wsdl:part name="parameters" element="xf:listShipments"/>
   </wsdl:message>
   <wsdl:message name="listShipmentsResponse">
   <wsdl:part name="parameters" element="xf:listShipmentsResponse"/>
   </wsdl:message>
   <wsdl:message name="getShipmentRequest">
   <wsdl:part name="parameters" element="xf:getShipment"/>
   </wsdl:message>
   <wsdl:message name="getShipmentResponse">
   <wsdl:part name="parameters" element="xf:getShipmentResponse"/>
   </wsdl:message>
   <wsdl:message name="acknowledgeShipmentRequest">
   <wsdl:part name="parameters" element="xf:acknowledgeShipment"/>
   </wsdl:message>
   <wsdl:message name="acknowledgeShipmentResponse">
   <wsdl:part name="parameters" element="xf:acknowledgeShipmentResponse"/>
   </wsdl:message>
   <wsdl:message name="setShipmentRequest">
   <wsdl:part name="parameters" element="xf:setShipment"/>
   </wsdl:message>
  <wsdl:message name="setShipmentResponse">
  <wsdl:part name="parameters" element="xf:setShipmentResponse"/>
  </wsdl:message>
  <wsdl:message name="BiproException">
  <wsdl:part name="parameters" element="nachr:BiproException"/>
  </wsdl:message>
  <!-- Rest of definition -->
</wsdl:definitions>

The XSD contain in WSDL:

<?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:bipro="http://www.bipro.net/namespace"
    xmlns:allg="http://www.bipro.net/namespace/allgemein" xmlns:xf="http://www.bipro.net/namespace/transfer"
    xmlns:partner="http://www.bipro.net/namespace/partner" xmlns:sepa="http://www.bipro.net/namespace/sepa"
    xmlns:nachr="http://www.bipro.net/namespace/nachrichten" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.bipro.net/namespace" elementFormDefault="qualified"
    attributeFormDefault="qualified" version="1.0" bipro:Version="2.7.0.1.0"
    bipro:Name="TransferService_2.7.0.1.0.xsd">
     <xsd:import namespace="http://www.bipro.net/namespace/nachrichten" />
     <xsd:import namespace="http://www.bipro.net/namespace/allgemein" />
     <xsd:import namespace="http://www.bipro.net/namespace/partner" />
     <xsd:import namespace="http://www.bipro.net/namespace/sepa" />
     <xsd:import namespace="http://www.bipro.net/namespace/transfer" />
    </xsd:schema>

This result in:

  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}acknowledgeShipmentResponse> referenced Type <{http://www.bipro.net/namespace/transfer}acknowledgeShipmentResponse> can not be found in the schemas
  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}acknowledgeShipmentRequest> referenced Type <{http://www.bipro.net/namespace/transfer}acknowledgeShipment> can not be found in the schemas
  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}getShipmentResponse> referenced Type <{http://www.bipro.net/namespace/transfer}getShipmentResponse> can not be found in the schemas
  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}getShipmentRequest> referenced Type <{http://www.bipro.net/namespace/transfer}getShipment> can not be found in the schemas
  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}BiproException> referenced Type <{http://www.bipro.net/namespace/nachrichten}BiproException> can not be found in the schemas
  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}listShipmentsRequest> referenced Type <{http://www.bipro.net/namespace/transfer}listShipments> can not be found in the schemas
  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}setShipmentRequest> referenced Type <{http://www.bipro.net/namespace/transfer}setShipment> can not be found in the schemas
  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}listShipmentsResponse> referenced Type <{http://www.bipro.net/namespace/transfer}listShipmentsResponse> can not be found in the schemas
  [ERROR] Part <parameters> in Message <{http://www.bipro.net/namespace}setShipmentResponse> referenced Type <{http://www.bipro.net/namespace/transfer}setShipmentResponse> can not be found in the schemas

With Apache CXF the service endpoint interface with wsimport is created correctly. With xjc the abstract classes as well as the concrete classes are created correctly but no SEI. For this, however, the xsd files must be in the same module.

With JAXB, the service endpoint interface is not generated and only the abstract and not the concrete classes. For this I used the plugin "maven-jaxb2-plugin" and jaxb2-maven-plugin".

With JAX WS the service endpoint interface is generated but also only the abstract and not the concrete classes. Also, the "catalog.cat" file does not work here.

Either I have not understood it correctly or I'm doing something totally wrong.

Can anybody help me please and share the right maven configuration?

Upvotes: 0

Views: 1352

Answers (1)

Devilluminati
Devilluminati

Reputation: 338

After searching i found the solution.

I use the maven-jaxb2-plugin with catalog file. But i have to add the missing namespaces from the concrete classes.

The POM:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <episode>false</episode>
                <extension>true</extension>
                <strict>false</strict>
                <catalog>src/main/resources/bipro.cat</catalog>
                <schemaDirectory>src/main/resources/TransferService</schemaDirectory>
                <schemaIncludes>
                    <include>*.wsdl</include>
                </schemaIncludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/generated-sources/xjc</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

The XSD:

  <?xml version="1.0" encoding="UTF-8"?>
   <xsd:schema xmlns:bipro="http://www.bipro.net/namespace"
        xmlns:allg="http://www.bipro.net/namespace/allgemein"
        xmlns:xf="http://www.bipro.net/namespace/transfer"
        xmlns:partner="http://www.bipro.net/namespace/partner"
        xmlns:sepa="http://www.bipro.net/namespace/sepa"
        xmlns:nachr="http://www.bipro.net/namespace/nachrichten"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:erw="http://www.xbav.net/namespace/bipro/transfer/erweiterung"
        targetNamespace="http://www.bipro.net/namespace"
        elementFormDefault="qualified"
        attributeFormDefault="qualified"
        version="1.0"
        bipro:Version="2.7.0.1.0"
        bipro:Name="TransferService_2.7.0.1.0.xsd">
        <!-- Hier werden die für den Service benötigten BiPRO-Modelle importiert. -->
        <xsd:import namespace="http://www.bipro.net/namespace/basis" />
        <xsd:import namespace="http://www.bipro.net/namespace/nachrichten"/>
        <xsd:import namespace="http://www.bipro.net/namespace/allgemein" />
        <xsd:import namespace="http://www.bipro.net/namespace/partner" />
        <xsd:import namespace="http://www.bipro.net/namespace/sepa" />
        <xsd:import namespace="http://www.bipro.net/namespace/transfer" />
        <xsd:import namespace="http://www.bipro.net/namespace/transfer/gevo" />
        <xsd:import namespace="http://www.bipro.net/namespace/transfer/vertrag" />
        <xsd:import namespace="http://www.bipro.net/namespace/versicherung/produktmodell/leben" />
        <xsd:import namespace="http://www.bipro.net/namespace/versicherung/produktmodell" />
        <xsd:import namespace="http://www.xbav.net/namespace/bipro/transfer/erweiterung"/>


    </xsd:schema>

Upvotes: 1

Related Questions