5

谁能告诉我为什么我不能用我的解析器捕获一个常规的 Java 异常,这样我就可以在响应被发回之前对其进行转换?它永远不会被断点击中。如果不可能,我该怎么办?

SoapFaultMappingExceptionResolver

public class LisSoapFaultTranslatorExceptionResolver extends SoapFaultMappingExceptionResolver {

    @Override
    protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {

        SoapFaultDetail detail = fault.addFaultDetail();
    }
}

<sws:annotation-driven />
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" />
<bean id="exceptionResolver"
            class="com.openclass.adapter.ws.resolvers.LisSoapFaultTranslatorExceptionResolver">
            <property name="defaultFault" value="RECEIVER,Server error">
            </property>
            <property name="exceptionMappings">
                <value>java.lang.Exception=SERVER,FaultMsg</value>
        </property>
    </bean>

带有错误的肥皂响应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring xml:lang="en">java.lang.NullPointerException</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

网络服务

@PayloadRoot(localPart="readCourseSectionRequest", namespace="http://www.imsglobal.org/services/lis/cmsv1p0/wsdl11/sync/imscms_v1p0")
    @ResponsePayload
    public ReadCourseSectionResponse readCourseSection(@RequestPayload ReadCourseSectionRequest request, MessageContext messageContext) {

            // Throws error since courseService is null
        ReadCourseSectionResponse openClassResponse = courseService.readCourseSection(request);

        return new ReadCourseSectionResponse();
    }
4

3 回答 3

8

我通过添加使其工作

<property name="order" value="1"></property>

<bean id="exceptionResolver" class="com.openclass.adapter.ws.resolvers.LisSoapFaultTranslatorExceptionResolver">
于 2013-03-19T22:13:20.210 回答
0

我认为您应该在您的异常解析器中覆盖方法 getFaultDefinition,如下所示(假设您的解析器正在扩展 AbstractSoapFaultDefinitionExceptionResolver):

@Override
protected SoapFaultDefinition getFaultDefinition(Object endpoint, Exception ex) {
    if(ex instanceof LoginException){
        SoapFaultDefinition result = new SoapFaultDefinition();
        result.setFaultCode(QName.valueOf("SERVER"));
        return result;
    }
    return null;
}

如果您希望您的故障消息(异常)更加自定义,您应该将其注释为:

@SoapFault(faultCode = FaultCode.SERVER)
public class LoginException extends Exception{}
于 2013-03-19T21:41:37.960 回答
0

我遇到了类似的问题。我解决了它用“soapFaultAnnotationExceptionResolver”替换bean名称/ id“exceptionResolver”。

请参阅:在 WS SoapFault 中添加详细信息:未使用我的自定义 ExceptionResolver

于 2015-06-26T11:57:55.907 回答