当前位置: 首页 > 知识库问答 >
问题:

CXF从wsdl生成SEI和java类

柴瀚昂
2023-03-14

有几种从wsdl生成java类的方法,例如Apache CXF、JAXB和JAX-WS。

我需要一个解决方案,工作与maven和曲库文件。

我的问题是,我有两个Maven模块A和B。其中一个模块(模块A)包含逻辑类,另一个模块(模块B)包含作为资源的xsd文件。现在我想从逻辑模块(模块A)生成类,xsd文件不应该作为资源添加到此模块。

我已经创建了一个catalag。包含公共名称空间并指向mavenmodule的cat文件。

目录文件上的摘要:

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"

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>

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>

XSD在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>

这导致:

  [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

使用ApacheCXF可以正确创建带有wsimport的服务endpoint接口。使用xjc可以正确创建抽象类和具体类,但没有SEI。然而,对于这一点,xsd文件必须在同一个模块中。

使用JAXB,服务endpoint接口不会生成,只有抽象类而不是具体类。为此,我使用了插件“maven-jaxb2-plugin”和jaxb2-maven-plugin”。

使用JAX WS生成服务endpoint接口,但也只生成抽象类,而不生成具体类。此外,“catalog.cat”文件在这里不起作用。

要么我没有正确地理解它,要么我在做完全错误的事情。

有谁能帮我分享一下正确的maven配置吗?

共有1个答案

太叔航
2023-03-14

经过搜索,我找到了解决办法。

我使用带有目录文件的maven-jaxb2-plugin。但我必须添加具体类中缺少的名称空间。

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>

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>
 类似资料:
  • 问题内容: 我有一个带有“逻辑”类的包(例如CheckAuthenticationDataLogic.java,GetVocabulariesLogic.java)。还有另一个类- ApiService.java用于生成wsdl。ApiService.java充满了这样的方法: 如您所见,它只是一个代理方法…所以我想避免做两次相同的工作,而无需编写ApiService.java就直接从逻辑类生成W

  • 问题内容: 我正在努力开发一个android应用程序。我需要使用网络服务。我有一个wsdl文件,但我想将其转换为java,以便可以在Java程序中使用其功能。有什么方法可以将wsdl文件转换为Java? 问题答案: 是的,您可以使用: WSDL2Java Eclipse插件 有了这些,您只需提供wsdl,就会自动为您生成Java类的客户端。

  • 有没有什么方法可以从wsdl生成xsd。任何链接或工具也可以。最简单的方法是什么?

  • 我非常感谢你在这个问题上的帮助。 配置为Eclipse Juno、CXF 3.0.3运行时和Tomcat v7。我已经使用CXF从现成的WSDL方法创建了自上而下的Web服务。但在Tomcat上部署服务时,我会遇到以下错误: 违规资源:ServletContext资源[/WEB-INF/cxf-beans.xml];嵌套异常是org.springframework.beans.factory.Be

  • 我试图从WSDL生成web服务客户机,我对这一点一无所知,所以无法找出错误。我试过: 这给了我一个错误: 我还尝试了apache cxf 3.1.1在eclipse中生成Web服务客户端,但得到这个错误: 我的WSDL文件是: 请帮我找出任何方式的错误,无论是wsimport还是apache cxf。我会非常感激的。

  • 在从wsdl和xsd生成java类时,我面临这个问题。请建议。 错误消息:执行模式1-生成目标org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.14.0:生成失败 尝试了什么?Eclipse安装jre设置为jdk 尝试将jaxb插件从org.jvnet.jaxb2.maven2更改为org.codehaus.moj但仍然不变 我有多个wsdls,他们有xsds