SoapFaultMappingExceptionResolver永远不会受到常规java异常的攻击

时间:2013-03-19 21:26:43

标签: java spring exception soap spring-ws

有人能告诉我为什么我不能用我的解析器捕获常规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();
    }

3 个答案:

答案 0 :(得分:8)

我通过添加

来实现它
<property name="order" value="1"></property>

<bean id="exceptionResolver" class="com.openclass.adapter.ws.resolvers.LisSoapFaultTranslatorExceptionResolver">

答案 1 :(得分: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;
}

如果您希望自定义错误消息(Exception),则应将其注释为:

@SoapFault(faultCode = FaultCode.SERVER)
public class LoginException extends Exception{}

答案 2 :(得分:0)

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

请参阅:Adding detail in a WS SoapFault : my custom ExceptionResolver is not used