如何从 Axis Web 服务返回(自定义)SOAPFault?

发布于 2024-11-15 10:59:01 字数 1662 浏览 6 评论 0原文

我有一些 WSDL,需要从中生成 Web 服务实现。我正在使用Eclipse和Axis1.4,并在Weblogic9.2上运行。

生成服务器存根一切顺利,并且我已经实现了我需要的代码。但是,为了与我们正在模拟的现有实现兼容,我需要针对某些指定的错误条件返回 SOAP 错误。

也就是说,我需要响应的 SOAP 主体看起来像这个例子:

<soapenv:Body>
    <soapenv:Fault>
        <faultcode xmlns:ns1="foobar">ns1:1234</faultcode>
        <faultstring>The supplied parameter name ABCD is not recognised.</faultstring>
        <detail>
            <FaultDetail>An error processing the web service [MyService]: Unknown parameter:ABCD</FaultDetail>
            <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">planet</ns2:hostname>
        </detail>
    </soapenv:Fault>
</soapenv:Body>

通过(大量)谷歌搜索,我认为我应该能够通过抛出 SOAPFaultException 来做到这一点。但消息存根仅抛出 java.rmi.RemoteException,因此我尝试将 SOAPFaultException 传递给 RemoteException。这给了我这样的信息:

   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>soapenv:Server.userException</faultcode>
         <faultstring>java.rmi.RemoteException: My remote exception; nested exception is: 
    javax.xml.rpc.soap.SOAPFaultException: soap fault string</faultstring>
         <detail>
            <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">myhostname</ns1:hostname>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>

...换句话说,它没有导致 SOAP 错误。

我尝试了很多其他的东西,但我几乎陷入困境。那么有人可以告诉我(最好是一个示例)如何在我的环境中返回包含我可以指定的内容的 SOAP 错误响应?

我并不热衷于使用 Axis(但我在这方面的经验比其他任何东西都丰富)。如果您建议替代方案,请注意我需要在 Web 服务方法中调用另一个(经过身份验证的)Web 服务,而我只能让它在 Axis1.4 中工作...

I have some WSDL from which I need to generate a web service implementation. I'm using Eclipse, and Axis1.4, and running on Weblogic9.2.

Generating the server stubs goes fine, and I've implemented the code I need to. However, for compatibility with the exising implementation we are emulating, I need to return SOAP faults for some specified error conditions.

That is, I need the SOAP body of the response to look like this example:

<soapenv:Body>
    <soapenv:Fault>
        <faultcode xmlns:ns1="foobar">ns1:1234</faultcode>
        <faultstring>The supplied parameter name ABCD is not recognised.</faultstring>
        <detail>
            <FaultDetail>An error processing the web service [MyService]: Unknown parameter:ABCD</FaultDetail>
            <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">planet</ns2:hostname>
        </detail>
    </soapenv:Fault>
</soapenv:Body>

From (much) googling, I think I should be able to do this by throwing a SOAPFaultException. But the message stub throws only java.rmi.RemoteException, so I've tried passing the SOAPFaultException to the RemoteException. That gives me something like this:

   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>soapenv:Server.userException</faultcode>
         <faultstring>java.rmi.RemoteException: My remote exception; nested exception is: 
    javax.xml.rpc.soap.SOAPFaultException: soap fault string</faultstring>
         <detail>
            <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">myhostname</ns1:hostname>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>

... in other words, it hasn't resulted in a SOAP fault.

I've tried a lot of other stuff, and I'm pretty much stuck. So can someone tell me (ideally with an example) how to return a SOAP fault response with content I can specify, in my environment?

I'm not wedded to using Axis (but I've more experience with that than anything else). If you suggest an alternative, please note I need in the web service method to invoke another (authenticated) web service, and I've only been able to get that to work in Axis1.4...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然#的苍凉 2024-11-22 10:59:01

您的第二个代码帖子是 SOAP 错误(请注意 soapenv:Body 内的 soapenv:Fault)。

基本上,所有框架的默认行为都是返回标准 SOAP 错误,并让您能够在错误代码、错误字符串和错误详细信息字段中输入自己的信息。

请参阅有关 Axis 1 异常的文档: http:// ws.apache.org/axis/java/apiDocs/org/apache/axis/AxisFault.html

它具有用于设置各个字段的 qname 的构造函数,因此您应该能够在那里引用您自己的项目。

许多人会使用故障详细信息字段并使用 DOM 在其中序列化自己的 XML 类型。

最后但并非最不重要的一点是,Axis1 的黄金时期大约是 2000 年至 2004 年,您会发现很难获得有关它的答案和支持。大多数人已经从 Axis1 迁移到 Apache CXFAxis2,或者直接向上
JAX-WS(现已包含在 JDK6+ 中)。还有 Spring Web Services 项目,它提供了对堆栈(编组、执行哪个 bean 等)。

所有这些框架都使用 WSS4J 来保证 Web 服务安全,并且可以支持标准用户名令牌、x509 令牌等。不过,一旦您获得来回传递的基本消息,您就会可能必须解决 WS-Security 的细节。

Your second code post is a SOAP fault (note the soapenv:Fault inside the soapenv:Body).

Basically all of the frameworks's default behavior is to return the standard SOAP fault and provide you the ability to enter your own information in the fault code, fault string, and fault detail fields.

See the docs on the Axis 1 exception: http://ws.apache.org/axis/java/apiDocs/org/apache/axis/AxisFault.html

It has constructors for setting the qname of various fields, so you should be able to reference your own items there.

Many people will use the fault detail field and serialize their own XML type inside it using DOM.

Last but not least Axis1's prime time was circa 2000-2004, you will find it difficult to get answers and support around it. Most people have moved from Axis1 to Apache CXF, Axis2, or just straight up
JAX-WS (now included in JDK6+). There is also the Spring Web Services project, which provides full customization of all of the behaviors in the stack (marshalling, which bean gets executed, etc).

Just all of these frameworks use WSS4J for their web service security, and can support the standard username token, x509 token, etc. Nevertheless, once you get the basic messages being passed back and forth, you'll likely have to work through the details of WS-Security.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文