SoapFaultMappingExceptionResolver never gets hit w

2020-06-19 03:18发布

Can anyone tell me why I cant catch a regular Java exception with my resolver so I can transform it before the response is sent back? It never gets hit with a breakpoint. If its not possible, how can I?

SoapFaultMappingExceptionResolver

public class LisSoapFaultTranslatorExceptionResolver extends SoapFaultMappingExceptionResolver {

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

        SoapFaultDetail detail = fault.addFaultDetail();
    }
}

Bean

<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 Response With Error

<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>

Web Service

@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条回答
老娘就宠你
2楼-- · 2020-06-19 03:19

I encountered a similar problem. I solved it replacing the bean name/id "exceptionResolver" by "soapFaultAnnotationExceptionResolver".

See: Adding detail in a WS SoapFault : my custom ExceptionResolver is not used

查看更多
劳资没心,怎么记你
3楼-- · 2020-06-19 03:24

I think you should, in your exception resolver, override the method getFaultDefinition, something like this (Assuming your resolver is extending 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;
}

And if you want your fault message (Exception) more customized, you should annotate it like:

@SoapFault(faultCode = FaultCode.SERVER)
public class LoginException extends Exception{}
查看更多
放我归山
4楼-- · 2020-06-19 03:34

I got it working by adding

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

to the

<bean id="exceptionResolver" class="com.openclass.adapter.ws.resolvers.LisSoapFaultTranslatorExceptionResolver">
查看更多
登录 后发表回答