【问题标题】:How to throw Custom Faults(faults not declared in wsdl) from Service Endpoint interface如何从服务端点接口抛出自定义故障(未在 wsdl 中声明的故障)
【发布时间】:2016-03-03 06:03:39
【问题描述】:

我有 SEI 类,它会抛出一个在 WSDL 文件中声明的异常。在抛出此异常的处理过程中,SOAP 故障已成功发送到客户端。这里没有问题。 但是,当我们在处理过程中在服务器中遇到任何运行时异常时,我们会创建一个自定义故障并从 SEI 类中抛出相同的故障。 由于这个自定义故障没有在 SEI 中声明,我们添加了故障类来扩展 RuntimeException。但是,当从应用程序代码中抛出此自定义故障时,Websphere 应用程序服务器不会将 SOAP 故障返回给客户端。相反,它会引发异常并将 Http 错误代码 500 发送到客户端。 有没有办法将自定义故障消息发送到客户端,而无需在 WSDL 中声明。

我的网络方法:

public CustomerDetails enquireCustomer(Customer customer)
        throws CustomerFault
{
    try
    {
       // SOME LOGIC HERE
    }
    catch (Exception exception)
    {
        if (exception instanceof CustomerFault)
        throw ((CustomerFault) exception );

        if (localException instanceof CustomerFault)
        {
        FaultDetails faultDetails = new FaultDetails();
        faultDetails.setErrorId(1);
        faultDetails.setErrorDescription(errorDescription);
        throw new CustomerFault("Failed in Processing and other details here... ", faultDetails);
        }
    }
        }

我的错误类

import javax.xml.ws.WebFault;
@WebFault(name="CustomerFault", targetNamespace="http://www.mycompany.com")
public class CustomerFault extends RuntimeException 
{
    private static final long serialVersionUID = 1L;
    private FaultDetails faultDetails;
    public ServiceExecutionFault(String message, FaultDetails faultDetails) {
        super(message);
        this.faultDetails = faultDetails;
    }

    public ServiceExecutionFault(String message)
    {
    super(message);
    }
    public ServiceExecutionFault(String message, FaultDetails faultDetails, 
           Throwable cause) {
        super(message, cause);
        this.faultDetails = faultDetails;
    }
    public FaultDetails getFaultInfo() {
        return faultDetails;
    }
}

这个问题似乎只存在于 Websphere 中。在 weblogic 中尝试时,同样可以正常工作,没有任何问题。有没有我在这里遗漏的标准。

【问题讨论】:

    标签: java web-services soap websphere-8


    【解决方案1】:

    在这里找到答案:

    JAX-WS server-side SOAPHandler that returns fault gets "Internal Error" on WebSphere v8

    通过禁用 websphere 中的统一故障处理,这可以正常工作。 添加以下 JVM 属性。

    -Dwebservices.unify.faults=false
    

    这可以从管理控制台设置:

    服务器 -> 服务器类型 -> Websphere 应用服务器 -> 进程 定义 -> Java 虚拟机 -> 自定义属性

    【讨论】:

      猜你喜欢
      • 2014-05-29
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多