SoapFaultMappingExceptionResolver never gets hit with regular java exception

与世无争的帅哥 提交于 2019-12-06 05:48:32

问题


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();
    }

回答1:


I got it working by adding

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

to the

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



回答2:


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



回答3:


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



来源:https://stackoverflow.com/questions/15510743/soapfaultmappingexceptionresolver-never-gets-hit-with-regular-java-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!