当使用WSDL优先方法生成java存根时,有没有办法使异常扩展RuntimeException而不是Exception? [英] When using a WSDL-first approach to generate java stubs, is there a way to make exceptions extend RuntimeException instead of Exception?

查看:156
本文介绍了当使用WSDL优先方法生成java存根时,有没有办法使异常扩展RuntimeException而不是Exception?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法强制JAXB生成在使用WSDL优先方法时扩展java.lang.RuntimeException而不是Exceptions的异常?

Is there a way to force JAXB to generate exceptions which extend java.lang.RuntimeException instead of Exceptions when using a WSDL-first approach?

我正在为我的Java Web服务项目使用WSDL优先方法。存根是由CXF的wsdl2javaMaven插件生成的,该插件由JAXB驱动。它能够从我的WSDL生成存根,包括基于我的WSDL中定义的错误生成~150个不同的异常类。但是,所有这些异常都会扩展java.lang.Exception。对于这个特定项目,我的偏好是这些异常扩展了java.lang.RuntimeException。

I'm using a WSDL-first approach for my Java web services project. The stubs are generated with CXF's "wsdl2java" Maven plugin, which is driven by JAXB. It's able to generate stubs from my WSDL, including generating ~150 different exception classes based on the faults defined in my WSDL. However, all of these exceptions extend java.lang.Exception. For this particular project, it's my preference that these exceptions extend java.lang.RuntimeException.

看起来类似于< javaType>注释的东西可能有效,但我正在挖掘规范我还没有找到任何东西。

It seems like something similar to the <javaType> annotation might work, but I'm digging through the spec and I haven't found anything yet.

推荐答案

现在还没办法。如果你想提交一个补丁,它会在wsdl2java工具中添加像-exceptionSuper = ....这样的标志,我们肯定会考虑它。如果您查看tools / wsdlto / frontend / jaxws / src / main / java / org / apache / cxf / tools / wsdlto / frontend / jaxws / generators / FaultGenerator.java中的CXF源代码,您可以看到我们尝试确定的位置要使用的超类。拉开一个标志我们的上下文将是相当直接的。

There isn't a way right now. If you want to submit a patch that would add a flag like -exceptionSuper=.... to the wsdl2java tool, we could definitely consider it. If you look in the CXF source in tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/FaultGenerator.java you can see where we try and determine a superclass to use. Pulling a flag our of the context there would be fairly straight forward.

这篇关于当使用WSDL优先方法生成java存根时,有没有办法使异常扩展RuntimeException而不是Exception?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆