gpt4 book ai didi

java - SOAP - 抛出 ServerSOAPFaultException 而不是适当的 @WebFault 异常

转载 作者:行者123 更新时间:2023-12-02 03:12:57 27 4
gpt4 key购买 nike

我已经从 WSDL 模式生成了 POJO,但错误似乎没有映射到适当的 @Webfault 异常。我收到的是 ServerSOAPFaultException,而不是 AXLError

生成的异常文件:

package com.cisco.axlapiservice;

import javax.xml.ws.WebFault;


/**
* This class was generated by Apache CXF 3.1.8
* 2016-11-13T14:30:37.692+02:00
* Generated source version: 3.1.8
*/

@WebFault(name = "axlError", targetNamespace = "http://www.cisco.com/AXL/API/11.5")
public class AXLError extends Exception {

private com.cisco.axl.api._11.AXLError axlError;

public AXLError() {
super();
}

public AXLError(String message) {
super(message);
}

public AXLError(String message, Throwable cause) {
super(message, cause);
}

public AXLError(String message, com.cisco.axl.api._11.AXLError axlError) {
super(message);
this.axlError = axlError;
}

public AXLError(String message, com.cisco.axl.api._11.AXLError axlError, Throwable cause) {
super(message, cause);
this.axlError = axlError;
}

public com.cisco.axl.api._11.AXLError getFaultInfo() {
return this.axlError;
}
}

服务器返回的响应:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>Cannot insert or update pattern. A DN exists with the same pattern and partition.</faultstring>
<detail>
<axlError>
<axlcode>4052</axlcode>
<axlmessage>Cannot insert or update pattern. A DN exists with the same pattern and partition.</axlmessage>
<request>addLine</request>
</axlError>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

抛出以下异常:

com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Cannot insert or update pattern. A DN exists with the same pattern and partition. Please see the server log to find more detail regarding exact cause of the failure.
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:124)
at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:238)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:189)
at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:276)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:104)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
at com.sun.proxy.$Proxy135.addLine(Unknown Source)
at com.company.product.provisioning.AxlApi.addLine(AxlApi.java:243)
...

您能指出为什么我从未收到 AXLError 吗?

最佳答案

这是 CXF 映射 @WebFault 的标准方法。如果您尝试/捕获接收 WebFault 的 WebService 方法,它将引发 AXLError 异常,其中将包含 com.cisco.axl.api._11.AXLError 中的故障详细信息getFaultInfo()。

我没有看到堆栈跟踪中调用 CXF 类。看来您的客户端正在使用 JDK 中包含的 JAX-WS 的内部实现。也许您忘记将 CXF jar 添加到运行时依赖项中?如果您使用 Maven,您可以使用以下代码片段将它们添加到您的类路径中:

<properties>
<cxf.version>3.1.8</cxf.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>

关于java - SOAP - 抛出 ServerSOAPFaultException 而不是适当的 @WebFault 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40769618/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com