简体   繁体   English

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

[英]How do I return a (custom) SOAPFault from an Axis web service?

I have some WSDL from which I need to generate a web service implementation.我有一些 WSDL 需要从中生成 web 服务实现。 I'm using Eclipse, and Axis1.4, and running on Weblogic9.2.我正在使用 Eclipse 和 Axis1.4,并在 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.但是,为了与我们正在模拟的现有实现兼容,我需要针对某些指定的错误条件返回 SOAP 故障。

That is, I need the SOAP body of the response to look like this example:也就是说,我需要响应的 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>

From (much) googling, I think I should be able to do this by throwing a SOAPFaultException.通过(大量)谷歌搜索,我认为我应该能够通过抛出 SOAPFaultException 来做到这一点。 But the message stub throws only java.rmi.RemoteException, so I've tried passing the SOAPFaultException to the RemoteException.但是消息存根只抛出 java.rmi.RemoteException,所以我尝试将 SOAPFaultException 传递给 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. ...换句话说,它没有导致 SOAP 故障。

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?那么有人可以告诉我(最好举个例子)如何在我的环境中返回带有我可以指定的内容的 SOAP 故障响应?

I'm not wedded to using Axis (but I've more experience with that than anything else).我并不热衷于使用 Axis(但我在这方面的经验比其他任何事情都多)。 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 服务,而我只能让它在 Axis1.4 中工作......

Your second code post is a SOAP fault (note the soapenv:Fault inside the soapenv:Body ).您的第二个代码帖子是 SOAP 故障(注意soapenv:Fault内的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.基本上所有框架的默认行为都是返回标准的 SOAP 故障,并让您能够在故障代码、故障字符串和故障详细信息字段中输入您自己的信息。

See the docs on the Axis 1 exception: http://ws.apache.org/axis/java/apiDocs/org/apache/axis/AxisFault.html请参阅轴 1 异常的文档: http://ws.apache.org/axis/java/apiDocs/org/apache/axis/AxisFault.ZFC35FDC70D5FC69D269883A822C7A53

It has constructors for setting the qname of various fields, so you should be able to reference your own items there.它具有用于设置各种字段的 qname 的构造函数,因此您应该能够在那里引用自己的项目。

Many people will use the fault detail field and serialize their own XML type inside it using DOM.很多人会使用故障详细信息字段并使用 DOM 在其中序列化自己的 XML 类型。

Last but not least Axis1's prime time was circa 2000-2004, you will find it difficult to get answers and support around it.最后但并非最不重要的一点是 Axis1 的黄金时间大约是 2000-2004 年,您会发现很难获得答案和支持。 Most people have moved from Axis1 to Apache CXF , Axis2 , or just straight up大多数人已经从 Axis1 移动到Apache CXFAxis2 ,或者直接向上
JAX-WS (now included in JDK6+). JAX-WS (现在包含在 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).还有Spring Web 服务项目,它提供了堆栈中所有行为的完全自定义(编组,哪个 bean 被执行等)。

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.只是所有这些框架都使用 WSS4J 来实现其 web 服务安全性,并且可以支持标准的用户名令牌、 x509令牌等。然而,一旦你得到了来回传递的基本消息,你可能不得不处理细节WS-安全性。

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

相关问题 如何从轴2 Web服务(REST)返回自定义HTTP响应(400或401)? - How do I return custom HTTP response (400 or 401) from axis 2 web service (REST)? 如何从轴Web服务返回复杂对象 - How to return a complex object from an axis web service 如何从Web服务(Axis2-java)返回矩阵? - How to return a matrix from Web Service (Axis2-java)? 如何从过滤器将SOAPFault返回给客户端? - How to return SOAPFault to the client from the Filter? Java JAX-WS Web Service 调用Axis2 客户端,如何添加自定义http 请求头? - Java JAX-WS Web Service calls Axis2 client, how do I add custom http request header? 如何从Web服务返回自定义对象的arraylist? - how to return arraylist of custom object from web service? 如何使Web服务在return语句之前执行? - How do I get the web service to execute before return statement? 如何删除 <return> Axis2 Web服务响应中的JSON或XML标签? - how to remove <return> tag from Axis2 web service response in JSON or XML? 如何在axis2 Web服务客户端中实现TLS? - How do I implement TLS in my axis2 web service client? 如何使用axis2编写客户端以将序列化的xml对象发送到Web服务? - How Do I write a client using axis2 to send a serialized xml object to a web service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM