草庐IT

java - 我想在 CXF codegen 上添加 @XmlRoot 注释

coder 2024-03-31 原文

我有一个包含以下条目的 WSDL 文件:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:CP_Ablakido" xmlns:s0="urn:CP_Ablakido" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
    <xsd:schema elementFormDefault="qualified" targetNamespace="urn:CP_Ablakido">
      <xsd:element name="GetList_11" type="s0:InputMapping1"/>
      <xsd:complexType name="InputMapping1">
        <xsd:sequence>
          <xsd:element name="Qualification" type="xsd:string"/>
          <xsd:element name="startRecord" type="xsd:string"/>
          <xsd:element name="maxLimit" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:element name="GetList_11Response" type="s0:OutputMapping1"/>
      <xsd:complexType name="OutputMapping1">
        <xsd:sequence>
          <xsd:element maxOccurs="unbounded" name="getListValues">
            <xsd:complexType>....

我使用具有以下设置的 CXF Codegen 插件:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${basedir}/target/generated-sources/wsdl2java</sourceRoot>
                <encoding>UTF-8</encoding>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

生成的 java 代码如下所示:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "OutputMapping1", propOrder = {
    "getListValues"
})
public class OutputMapping1 {

    @XmlElement(required = true)
    protected List<OutputMapping1 .GetListValues> getListValues;

问题是这里缺少@XmlRootElement。还有另一个类似的问题,例如

  1. maven-cxf-codegen-plugin using Jaxb binding to add inheritance for all generated classes
  2. Annotating CXF (wsdl2java) generated package
  3. externally create jaxb annotations for class

正如其他答案提到的,我可以放置绑定(bind)文件。 所以我创建了一个包含以下内容的绑定(bind)文件:

<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:annox="http://annox.dev.java.net"
version="2.0">
        <jaxb:bindings node="//xsd:element[@name='GetList_11Response']">
            <annox:annotate target="class">
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="GetList_11Response"/>
          </annox:annotate>
        </jaxb:bindings>
</jaxb:bindings>

我已将以下 block 添加到 POM.XML:

<wsdlOptions>
    <wsdlOption>
        <wsdl>${basedir}/src/main/resources/wsdl/CP_Ablakido_1.wsdl</wsdl>
        <bindingFiles>                                       
            <bindingFile>${basedir}/src/main/resources/wsdl/CP_Ablakido_1.xjb
            </bindingFile>
        </bindingFiles>
    </wsdlOption>
</wsdlOptions>

之后我收到错误信息:

com.sun.istack.SAXParseException2; systemId: file:/Project/icp-integration/icpiCameI/src/main/resources/wsdl/CP_Ablakido_1.xjb; lineNumber: 9; columnNumber: 72; XPath evaluation of "//xs:element[@name='GetList_11Response']" results in empty target node
    at com.sun.tools.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:624)
    at com.sun.tools.xjc.reader.internalizer.Internalizer.reportError(Internalizer.java:618)
    at com.sun.tools.xjc.reader.internalizer.Internalizer.buildTargetNodeMap(Internalizer.java:294)
    at com.sun.tools.xjc.reader.internalizer.Internalizer.buildTargetNodeMap(Internalizer.java:390)
    at com.sun.tools.xjc.reader.internalizer.Internalizer.transform(Internalizer.java:146)

所以我不知道如何准确描述当 complexType 为 OutputMapping1 时,然后将 @XmlRootElement 放入名为“GetList_11Response”的 OutputMapping1.java 中。

最佳答案

我找到了解决方案。这很棘手,因为:

  1. 必须处理 XSD 内嵌在 WSDL 中的问题。 (诀窍是 schemaLocation="CP_Ablakido_1.wsdl#types1"。它告诉 JAXB 在 WSDL 文件中使用节点。)
  2. 必须配置 CXF 才能使用 XJC 插件 (annox)。

必须将以下片段添加到 POM.XML:

<wsdlOption>
    <wsdl>${basedir}/src/main/resources/wsdl/CP_Ablakido_1.wsdl</wsdl>
    <bindingFiles>
        <bindingFile>${basedir}/src/main/resources/wsdl/CP_Ablakido_1.xjb</bindingFile> 
    </bindingFiles>
    <extraargs><extraarg>-xjc-Xannotate</extraarg></extraargs>
</wsdlOption>

依赖项必须添加到插件中:

<dependency>
    <groupId>org.jvnet.jaxb2_commons</groupId>
    <artifactId>jaxb2-basics-annotate</artifactId>
    <version>0.6.0</version>
</dependency>   

<dependency>
    <groupId>org.apache.cxf.xjcplugins</groupId>
    <artifactId>cxf-xjc-ts</artifactId>
    <version>3.0.5</version>
</dependency>

XJB 文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.0" 
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    jaxb:extensionBindingPrefixes="annox xjc"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:annox="http://annox.dev.java.net"
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance">

  <jaxb:bindings schemaLocation="CP_Ablakido_1.wsdl#types1" node="/xs:schema"> 
       <jaxb:bindings node="//xs:complexType[@name='InputMapping1']">
            <annox:annotate target="class">
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="GetList_11"/>
          </annox:annotate>
      </jaxb:bindings>    
      <jaxb:bindings node="//xs:complexType[@name='OutputMapping1']">
            <annox:annotate target="class">
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="GetList_11Response"/>
          </annox:annotate>
      </jaxb:bindings>
   </jaxb:bindings>
</jaxb:bindings>

关于java - 我想在 CXF codegen 上添加 @XmlRoot 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34239587/

有关java - 我想在 CXF codegen 上添加 @XmlRoot 注释的更多相关文章

  1. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  2. ruby - 将 Bootstrap Less 添加到 Sinatra - 2

    我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它

  3. ruby - 续集在添加关联时访问many_to_many连接表 - 2

    我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以

  4. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  5. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  6. ruby - 可以通过多少种方法将方法添加到 ruby​​ 对象? - 2

    当谈到运行时自省(introspection)和动态代码生成时,我认为ruby​​没有任何竞争对手,可能除了一些lisp方言。前几天,我正在做一些代码练习来探索ruby​​的动态功能,我开始想知道如何向现有对象添加方法。以下是我能想到的3种方法:obj=Object.new#addamethoddirectlydefobj.new_method...end#addamethodindirectlywiththesingletonclassclass这只是冰山一角,因为我还没有探索instance_eval、module_eval和define_method的各种组合。是否有在线/离线资

  7. ruby - 如何在 Ruby 中向现有方法定义添加语句 - 2

    我注意到类定义,如果我打开classMyClass,并在不覆盖的情况下添加一些东西我仍然得到了之前定义的原始方法。添加的新语句扩充了现有语句。但是对于方法定义,我仍然想要与类定义相同的行为,但是当我打开defmy_method时似乎,def中的现有语句和end被覆盖了,我需要重写一遍。那么有什么方法可以使方法定义的行为与定义相同,类似于super,但不一定是子类? 最佳答案 我想您正在寻找alias_method:classAalias_method:old_func,:funcdeffuncold_func#similartoca

  8. ruby-on-rails - 添加回形针新样式不影响旧上传的图像 - 2

    我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司

  9. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  10. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

随机推荐