【发布时间】: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