Generating Java Exceptions from XSD / binding Exceptions with JAXB2

丶灬走出姿态 提交于 2019-12-24 07:26:20

问题


For webservices we usually generate java beans with the maven-jaxb2-plugin and use JAXB2 marshalling in Spring. I am wondering how to handle (SOAP-)faults that are declared in the WSDL/XSD best. In the application I would like to use Java exceptions that are marshalled to the faults. Is this possible? I haven't found a way to generate exceptions with the sourcecode generation of the maven-jaxb2-plugin. Thanks!

Update: I'd like to use spring-ws. But I guess the main problem is how to generate java exceptions with jaxb2 source generator.


回答1:


XFire (now CXF) lets you bind SOAP excpetions declared in the WSDL to particular Java exception as described here. These Java exceptions are hand created through, not generated via JAXB. I don't know if there's an equivalent in Spring-WS.




回答2:


Jaxb2-plugin generates beans from XSD only. You can use jaxws-maven-plugin instad of maven-jaxb2-plugin.

Try using this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>generate-from-wsdl<
            <goals>
                <goal>wsimport</
            </goals>
        </execution>
    </executions>

    <configuration>
        <wsdlDirectory>src/main/resources/wsdl/</wsdlDirectory>
        <keep>true</keep>
        <sourceDestDir>target/generated-sources/wsimport</sourceDestDir>
    </configuration>
</plugin>

Just simply invoke command mvn clean install, you'll find generated resources in target/generated-sources/wsimport on two packages:

  • types-generated java beans same as from jaxb
  • wsdl-classes, exceptions, interfaces generated from wsdl


来源:https://stackoverflow.com/questions/2070422/generating-java-exceptions-from-xsd-binding-exceptions-with-jaxb2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!