简体   繁体   English

多模块Maven项目中的Axis2 Web服务

[英]Axis2 web-service in a multi module maven project

I've got an axis2 web-service generated from the WSDL file in a multi module maven project. 我已经在多模块Maven项目中从WSDL文件生成了axis2 Web服务。

wsdl2java has generated the stubs and basic skeleton for me. wsdl2java为我生成了存根和基本框架。

What's the best way to integrate those generated stubs into the exsisting business logic? 将那些生成的存根集成到现有业务逻辑中的最佳方法是什么?

I've got several considerations: 我有几个注意事项:

  • The easiest way is to implement the business logic inside the stub. 最简单的方法是在存根内部实现业务逻辑。 But I believe that will lead into trouble: 但是我相信这会带来麻烦:
    • the stubs now are being generated as part of mvn clean install command. 现在,这些存根已作为mvn clean install命令的一部分生成。 Maven clean deletes the generated source folder. Maven clean删除生成的源文件夹。 I will have to protect the stub with the implemented business logic from deletion. 我将不得不保护已实现业务逻辑的存根以免被删除。
    • I don't want to commit anything from generated stubs into VCS. 我不想将生成的存根中的任何内容提交到VCS中。 I'd like to keep it clean. 我想保持干净。
  • There is an option to extend the stub class in another source folder. 有一个选项可以在另一个源文件夹中扩展存根类。 This eliminates the cons of the previous approach, but brings something new to the stage: 这消除了先前方法的弊端,但为舞台带来了新的东西:
    • As I understood from the AXIS2 docs, I have to specify the service class in the services.xml (and that's generated with maven-axis2 plugin). 正如我从AXIS2文档中了解到的那样,我必须在services.xml指定服务类(该类由maven-axis2插件生成)。 So again some parts of the generated stubs should be protected from modification. 因此,应再次保护所生成的存根的某些部分,使其免受修改。

Is there a way to somehow avoid this? 有办法避免这种情况吗? Something like specifying the service class implementation in the web.xml? 像在web.xml中指定服务类实现? or anything similar? 或类似的东西?

Axis2 is JAX-WS compliant, therefore you can use the wsimport tool instead of wsdl2java . Axis2兼容JAX-WS ,因此可以使用wsimport工具代替wsdl2java I assume you've taken the contract first approach and you are generating the stubs from the WSDL file. 我假设您已采用合同优先的方法,并且正在根据WSDL文件生成存根。 Here is the doc to the wsimport maven plugin. 这是wsimport maven插件的文档 A lot of things can be changed ( destDir for instance). 许多事情都可以更改(例如destDir )。

Maven clean deletes the generated source folder. Maven clean删除生成的源文件夹。 I will have to protect the stub with the implemented business logic from deletion. 我将不得不保护已实现业务逻辑的存根以免被删除。

You can actually generate the stubs to your regular package structure (perhaps to its own package) and add include (or exclude) the generated files in the maven clean plugin configuration . 实际上,您可以将存根生成为常规的包结构(也许是其自身的包),并在maven clean plugin 配置中添加包含(或排除)生成的文件。 If you use this mvn plugin , your IDE should add the generated files to the project classpath. 如果使用此mvn插件 ,则IDE应该将生成的文件添加到项目类路径。

If I were you, I would definitely try to do as much as possible as JAX-WS compliant, because if you do so, you won't be vendor locked-in to Axis2. 如果您是我,那么我绝对会尽可能地做到与JAX-WS兼容,因为如果这样做,您将不会被厂商锁定到Axis2。 But you can switch to CXF, Metro or Jboss WS in the future. 但是将来您可以切换到CXF,Metro或Jboss WS。 The services.xml file is Axis2 specific. services.xml文件特定于Axis2。

So again some parts of the generated stubs should be protected from modification. 因此,应再次保护所生成的存根的某些部分,使其免受修改。

You can mark those resources as ignored by your SCM system. 您可以将那些资源标记为SCM系统忽略。 And mark them as derived in the Eclipse. 并将它们标记为在Eclipse中派生。 Here is mvn plugin for it. 这是mvn插件 If you do so, devs will be notified when trying to change them. 如果您这样做,则在尝试更改开发人员时会通知他们。 There must be something similar in IntelliJ IDEA as well. IntelliJ IDEA中也必须有类似的东西。

What you have to do it is to configure maven pom, in order to let maven does the work. 您要做的是配置maven pom,以便让maven进行工作。

First step 第一步

First of all you configure a maven properties, let's call it outputDirectory , the folder should be located inside the maven target folder, which I usually don't commit in the SCM. 首先,您配置一个maven属性,将其outputDirectory ,该文件夹应位于maven目标文件夹中,而我通常不在SCM中提交该文件夹。

Then you have to configure Axis maven plugin in order to generate stub sources into the target folder, as follow 然后,您必须配置Axis maven插件 ,以便将存根源生成到目标文件夹中,如下所示

<build>
   <plugins>
      ...
          <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                    <configuration>
                        ... your configuration ..
                        <generateServerSide>true</generateServerSide>                                     
                        <generateServerSideInterface>true</generateServerSideInterface>
                        <outputDirectory>${outputDirectory}</outputDirectory>
                         ...
                    </configuration>
                </execution>
             </executions>
          </plugin>
          ...
      </plugins>
  </build>

with generateServerSideInterface to true the plugin generates an interface named XXXSkeleton that you can implement. generateServerSideInterface为true时,插件将生成一个可以实现的名为XXXSkeleton的接口。

Second Step 第二步

Then you have to configure maven build helper plugin , in order to include the generated sources. 然后,您必须配置maven build helper插件 ,以包括生成的源。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>add-source</id>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${outputDirectory}</source>
                </sources>
            </configuration>
        </execution>
    </executions>      
</plugin>

my personal opinion is that axis is not the better chioce for java Web Service, JAX-WS compliant framework are the best choice, here are the how with jax-ws maven plugin , the generate sources are far better and clean then axis sources. 我个人的观点是,Axis不是Java Web Service的更好选择,JAX-WS兼容框架是最佳选择,这是jax-ws maven插件的使用方式 ,生成源要比axis源好得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM