8

我有一个 SOAP 服务,如果我为 XML 元素指定错误的输入,请求和响应会按预期工作,输入良好

在请求正文中:

...
<ns:myIntegerElement>asdf</ns:myIntegerElement>
...

我的异常解析器被调用,这个解析器只是异常解析器的一个实现,所以它没有异常映射,只是抽象方法中的几个System.out

<bean id="exceptionResolver" class="com.mycompany.ws.MyExceptionResolver">

但是,如果我发送一个看起来更像这样的请求:

...
    <ns:myIntegSOMETHINGGOTTOTALLYMESSUP!!!ent>asdf</ns:myIntegerElement>
...

我的解析器根本没有执行

我将 log4j 设置为具有根调试级别并查看以下输出:

2010-08-09 10:30:01,900 [线程:http-8080-2] 调试 [org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter] - 接受传入 [org.springframework.ws.transport.http.HttpServletConnection@c46dcf ] 到 [ http://localhost:8080/myws/MyWebServices/] 错误:'元素类型“ns:MESSEDUPELEMENT”必须由匹配的结束标记“”终止。' 2010-08-09 10:30:01,920 [线程:http-8080-2] 调试 [org.springframework.ws.transport.http.MessageDispatcherServlet] - 无法完成请求 org.springframework.ws.soap.saaj.SaajSoapMessageException:无法访问信封:无法从给定来源创建信封:;嵌套异常是 com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:无法从给定源创建信封:在 org.springframework.ws.soap.saaj.support.SaajUtils.getSaajVersion(SaajUtils.java:162) 在 org .springframework.ws.soap.saaj.SaajSoapMessage.getImplementation(SaajSoapMessage.java:251) 在 org.springframework.ws.soap.saaj.SaajSoapMessage.(SaajSoapMessage.java: 在 org.springframework.ws.soap.saaj.support.SaajUtils.getSaajVersion( SaajUtils.java:159) ... 24 更多原因:javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: 元素类型“smm:smm-aid”必须由匹配的结束标记“终止”。在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:719) 在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl. java:313) 在 com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer.transform(EfficientStreamingTransformer.java:393) 在 com.sun.xml。internal.messaging.saaj.soap.EnvelopeFactory.createEnvelope(EnvelopeFactory.java:102) ... 27 更多原因:org.xml.sax.SAXParseException:元素类型“smm:smm-aid”必须由匹配终止结束标签“”。在 com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231) 在 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java: 522)在 org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333) 在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:636) 在 com .sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707) ... 30 更多 createEnvelope(EnvelopeFactory.java:102) ... 27 更多原因:org.xml.sax.SAXParseException:元素类型“smm:smm-aid”必须由匹配的结束标记“”终止。在 com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231) 在 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java: 522)在 org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333) 在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:636) 在 com .sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707) ... 30 更多 createEnvelope(EnvelopeFactory.java:102) ... 27 更多原因:org.xml.sax.SAXParseException:元素类型“smm:smm-aid”必须由匹配的结束标记“”终止。在 com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231) 在 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java: 522)在 org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333) 在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:636) 在 com .sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707) ... 30 更多 元素类型“smm:smm-aid”必须以匹配的结束标签“”结束。在 com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231) 在 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java: 522)在 org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333) 在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:636) 在 com .sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707) ... 30 更多 元素类型“smm:smm-aid”必须以匹配的结束标签“”结束。在 com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231) 在 com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java: 522)在 org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333) 在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:636) 在 com .sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707) ... 30 更多

似乎 spring 在这里缺少一个可能的异常,并且没有包装它,但是在我看来,这样一个基本的错误条件没有被捕获似乎不太可能。谁能帮我找到这个问题的根源?

我也会包含 web.xml 和 servlet.xml:

网页.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <init-param>
            <param-name>transformWsdlLocations</param-name>
            <param-value>true</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>ws</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

小服务程序上下文:

<context:component-scan base-package="com.mycomp.proj.ws" />
    <bean id="smmService" class="com.mycomp.proj.ws.SMMRequestHandlingServiceStubImpl"/>

    <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
    <bean class="org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
        <constructor-arg ref="marshaller"/>
    </bean>
    <bean id="marshaller" class="org.springframework.oxm.castor.CastorMarshaller">
        <property name="mappingLocations">
            <list>
                <value>classpath:mapping.xml</value>
                <value>classpath:hoursOfOperationMapping.xml</value>
            </list>
        </property>
    </bean>

    <bean id="smmws" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
        <property name="schema" ref="schema" />
        <property name="portTypeName" value="SMM" />
        <property name="locationUri" value="/SMMWebServices/"/>
        <property name="targetNamespace" value="http://mycomp.proj.com" />
    </bean>

    <bean id="exceptionResolver" class="com.wdp.smm.ws.MyExceptionResolver"/>

    <bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
        <property name="xsd" value="/WEB-INF/ws.xsd" />
    </bean>
4

8 回答 8

7

MessageDispatcherServlet 默认创建自己的两个 EnpointExceptionResolver 实例,即 SoapFaultAnnotationExceptionResolver@1 和 SimpleSoapExceptionResolver@2

并且当它解决异常时,SimpleSoapExceptionResolver@2 将停止任何其他已注册的 EnpointExceptionResolver 来处理异常。

我花了很长时间才弄清楚,但答案很简单,在你的 servlet 上下文中你必须这样做:

<bean id="exceptionResolver" class="com.wdp.smm.ws.MyExceptionResolver">
    <property name="order" value="1"/>
</bean>
于 2013-01-28T20:41:08.923 回答
5

我仔细研究了你的问题,我想我知道发生了什么。你的异常处理程序没有被调用,因为它在肥皂处理中的更高级别。您会看到,WebServiceMessageReceiverHandlerAdapter 尝试将传入的字符串解码为 XML,然后再将其发送到编组器进行处理。由于 XML 无效,因此调用失败。而且由于 WebServiceMessageReceiverHandlerAdapter 不支持异常处理程序,它只是重新抛出异常“SaajSoapMessageException”。

现在您可以做的是创建一个扩展 WebServiceMessageReceiverHandlerAdapter 的新类,但它还将 handleConnection() 包装在 try/catch 中,当抛出异常时使用您的异常处理程序。


顺便说一句,在调试此类问题时,我的方法是在 log4j 中输出方法名称和行号。以及下载 Spring 源代码。

于 2010-08-20T12:18:10.873 回答
3

我认为@thierry-dimitri-roy 解释的是正确的,但是我在实际实现它时遇到了很多问题。例如,仅仅包装handleconnection 方法是不够的,因为没有抛出noendpointfoundexception。由于这是更好地处理异常的更普遍的问题,因此我将代码放在这里以减轻后代的痛苦。这是用 spring-ws 2.1.3 和 JBoss AS7 测试的。

我的消息处理程序将所有问题转换为响应代码为 200 的肥皂错误。

package fi.eis.applications.spring.soap.server.transport.http;

import java.io.IOException;
import java.net.URISyntaxException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ws.FaultAwareWebServiceMessage;
import org.springframework.ws.InvalidXmlException;
import org.springframework.ws.NoEndpointFoundException;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.context.DefaultMessageContext;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.support.DefaultStrategiesHelper;
import org.springframework.ws.transport.EndpointAwareWebServiceConnection;
import org.springframework.ws.transport.FaultAwareWebServiceConnection;
import org.springframework.ws.transport.WebServiceConnection;
import org.springframework.ws.transport.WebServiceMessageReceiver;
import org.springframework.ws.transport.context.DefaultTransportContext;
import org.springframework.ws.transport.context.TransportContext;
import org.springframework.ws.transport.context.TransportContextHolder;
import org.springframework.ws.transport.http.HttpServletConnection;
import org.springframework.ws.transport.http.HttpTransportConstants;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter;
import org.springframework.ws.transport.support.TransportUtils;

/**
 * Adapter to map XML parsing and other low-level errors to SOAP faults instead of
 * server standard error pages. Also, this class will always use return code HTTP_OK
 * (status 200) to requests, even if there are errors.
 *  
 */
public class MyWebServiceMessageReceiverHandlerAdapter
    extends WebServiceMessageReceiverHandlerAdapter
    implements HandlerAdapter, Ordered, InitializingBean, ApplicationContextAware {

    private ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
        this.context = applicationContext;
    }

    @Override
    public void afterPropertiesSet() {
        DefaultStrategiesHelper defaultStrategiesHelper = new DefaultStrategiesHelper(MessageDispatcherServlet.class);
        WebServiceMessageFactory factory = defaultStrategiesHelper
                .getDefaultStrategy(WebServiceMessageFactory.class, context);
        setMessageFactory(factory);
    }

    public ModelAndView handle(HttpServletRequest httpServletRequest,
                               HttpServletResponse httpServletResponse,
                               Object handler) throws Exception {
        if (HttpTransportConstants.METHOD_POST.equals(httpServletRequest.getMethod())) {
            WebServiceConnection connection = new MyWebServiceConnection(httpServletRequest, httpServletResponse);
            try {
                overriddenHandleConnection(connection, (WebServiceMessageReceiver) handler);
            } catch (InvalidXmlException ex) {
                handleInvalidXmlException(httpServletRequest, httpServletResponse, handler, ex);
            } catch (Exception ex) {
                handleGeneralException(httpServletRequest, httpServletResponse, handler, ex);
            }
        }
        else {
            handleNonPostMethod(httpServletRequest, httpServletResponse, handler);
        }
        return null;
    }


    /**
     * Overridden version of handleConnection from WebServiceMessageReceiverObjectSupport to be able to handle
     * missing endpoint ourselves. That method is final, so we need to use another method here.
     * 
     * This has been reported as https://jira.springsource.org/browse/SWS-850
     * 
     * @param connection
     * @param receiver
     * @throws Exception
     */
    protected void overriddenHandleConnection(WebServiceConnection connection, WebServiceMessageReceiver receiver)
            throws Exception {
        logUri(connection);
        TransportContext previousTransportContext = TransportContextHolder.getTransportContext();
        TransportContextHolder.setTransportContext(new DefaultTransportContext(connection));

        try {
            WebServiceMessage request = connection.receive(getMessageFactory());
            MessageContext messageContext = new DefaultMessageContext(request, getMessageFactory());
            receiver.receive(messageContext);
            if (messageContext.hasResponse()) {
                WebServiceMessage response = messageContext.getResponse();
                if (response instanceof FaultAwareWebServiceMessage &&
                        connection instanceof FaultAwareWebServiceConnection) {
                    FaultAwareWebServiceMessage faultResponse = (FaultAwareWebServiceMessage) response;
                    FaultAwareWebServiceConnection faultConnection = (FaultAwareWebServiceConnection) connection;
                    faultConnection.setFault(faultResponse.hasFault());
                }
                connection.send(messageContext.getResponse());
            }
        }
        catch (NoEndpointFoundException ex) {
            if (connection instanceof EndpointAwareWebServiceConnection) {
                ((EndpointAwareWebServiceConnection) connection).endpointNotFound();
            }
            throw ex;
        }
        finally {
            TransportUtils.closeConnection(connection);
            TransportContextHolder.setTransportContext(previousTransportContext);
        }
    }

    private void logUri(WebServiceConnection connection) {
        if (logger.isDebugEnabled()) {
            try {
                logger.debug("Accepting incoming [" + connection + "] at [" + connection.getUri() + "]");
            }
            catch (URISyntaxException e) {
                // ignore
            }
        }
    }



    private void handleGeneralException(
            HttpServletRequest httpServletRequest,
            HttpServletResponse response, Object handler,
            Exception ex) throws IOException {
        writeErrorResponseWithMessage(response, ex.getClass().getName() + ": " + ex.getMessage());
    }

    /**
     * By default, sets SC_BAD_REQUEST as response in Spring, so overwritten to
     * provide HTTP_OK and reasonable SOAP fault response.
     */
    protected void handleInvalidXmlException(
            HttpServletRequest httpServletRequest,
            HttpServletResponse response, Object handler, InvalidXmlException ex)
            throws IOException {
        writeErrorResponseWithMessage(response, ex.getClass().getName() + ": " + ex.getMessage());
    }

    /**
     * By default, sets SC_METHOD_NOT_ALLOWED as response in Spring, so overwritten to
     * provide HTTP_OK and reasonable SOAP fault response.
     */
    protected void handleNonPostMethod(HttpServletRequest httpServletRequest,
                                       HttpServletResponse response,
                                       Object handler) throws Exception {
        writeErrorResponseWithMessage(response, "HTTP Method not allowed");
    }

    private void writeErrorResponseWithMessage(HttpServletResponse response, String message)
            throws IOException {
        String errorXml = String.format(
                 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                +"    <SOAP-ENV:Header/>"
                +"    <SOAP-ENV:Body>"
                +"        <SOAP-ENV:Fault>"
                +"            <faultcode>SOAP-ENV:Client</faultcode>"
                +"            <faultstring xml:lang=\"en\">%s</faultstring>"
                +"        </SOAP-ENV:Fault>"
                +"    </SOAP-ENV:Body>"
                +"</SOAP-ENV:Envelope>",
                StringEscapeUtils.escapeXml(message)
                );

        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("text/xml");
        response.getWriter().write(errorXml);
        response.getWriter().flush();
    }
    @Override
    public int getOrder() {
        return 1;
    }

    /**
     * This class is needed as org.springframework.ws.transport.http.HttpServletConnection will throw an
     * exception if it is used outside Spring framework files. However, extending it and using the same
     * implementation seems to be fine.
     *
     */
    static class MyWebServiceConnection extends HttpServletConnection {
        protected MyWebServiceConnection(HttpServletRequest httpServletRequest,
                HttpServletResponse httpServletResponse) {
            super(httpServletRequest, httpServletResponse);
        }
    }    
}

这也需要正确配置。这是 spring 上下文中需要的东西:

<!-- 'messageReceiverHandlerAdapter' is a magic name spring-ws
     org.springframework.ws.transport.http.MessageDispatcherServlet
     will bind to -->
<bean id="messageReceiverHandlerAdapter"
    class="fi.eis.applications.spring.soap.server.transport.http.MyWebServiceMessageReceiverHandlerAdapter">
</bean>
于 2013-09-26T09:21:25.320 回答
2

我能想出的解决方案是覆盖 MessageDispatcherServlet 中的 doService 方法并捕获异常,然后呈现自定义响应。这对你来说可能不是最好的解决方案,但它对我有用,希望对你有帮助!

public class CustomMessageDispatcherServlet extends MessageDispatcherServlet {

protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        super.doService(request, response);
    } catch (Exception e) {
        String error = e.getMessage();
        String errorXml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                                "<SOAP-ENV:Header/>" +
                                    "<SOAP-ENV:Body>" +
                                        "<SOAP-ENV:Fault>" +
                                            "<faultcode>SOAP-ENV:Client</faultcode>" +
                                            "<faultstring xml:lang=\"en\"></faultstring>" + error +
                                        "</SOAP-ENV:Fault>" +
                                    "</SOAP-ENV:Body>" +
                                "</SOAP-ENV:Envelope>";
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("text/xml");
        response.getWriter().write(errorXml);
        response.getWriter().flush();
    }
}

}

您可能只想捕获要处理的异常。

将 org.springframework.ws.transport.http.MessageDispatcherServlet 替换为 web.xml 文件中的 CustomMessageDispatcherServlet。

<servlet>
    <servlet-name>web-services</servlet-name>
    <servlet-class>CustomMessageDispatcherServlet</servlet-class>
</servlet>
于 2012-01-20T03:02:50.370 回答
1

我记得在使用 spring-security 时遇到了这种问题。我还遇到了在某些条件下未调用异常解析器的问题。

那么问题是有一个过滤器链来处理每个请求。调用异常解析器的代码是这个链中的一个过滤器,但它接近链的末端。因此,如果在异常解析器调用过滤器之前过滤器中的某处发生异常,我的解析器将永远不会被调用。

我猜你在这里遇到了类似的事情,信封解析错误发生在异常解析器调用过滤器之前。如果是这种情况,您将不得不求助于一些其他方式来处理这些异常,例如 vanilla servlet 过滤器。

于 2010-08-20T12:00:18.310 回答
0

在最新的 Spring WS 版本中,您可以使用自定义 Web 服务消息侦听器

public class CustomWebServiceMessageListener extends WebServiceMessageListener {

private static final Logger LOG = LoggerFactory.getLogger(CustomWebServiceMessageListener.class);

@Override
public void onMessage(Message message, Session session) throws JMSException {
    try {
        this.handleMessage(message, session);
    } catch (JmsTransportException jmsTransportException) {
        LOG.error(jmsTransportException.getMessage(), jmsTransportException);
    } catch (Exception e) {
        JMSException jmsException = new JMSException(e.getMessage());
        jmsException.setLinkedException(e);
        LOG.error(e.getMessage(), e);
    }
  }
}

并像这样注入它:

  <bean id="messageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="concurrentConsumers" value="#{properties.concurrentListeners}"/>

    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="destination" ref="queue"/>
    <property name="messageListener" ref="messageListener"/>
    <property name="sessionTransacted" value="true"/>

</bean>

<bean id="messageListener" class="com.yourproject.transport.CustomWebServiceMessageListener">
    <property name="messageFactory" ref="saajMessageFactory"/>
    <property name="messageReceiver" ref="messageDispatcher"/>
</bean>
于 2016-02-22T17:35:05.813 回答
0

由于 doService 不再针对无效 XML 引发错误,并且只是将状态设置为 400,因此我不得不进一步探索 Chen 的答案并实现以下内容。

public class CustomWebServiceMessageReceiverHandlerAdapter extends WebServiceMessageReceiverHandlerAdapter {

  @Override
  protected void handleInvalidXmlException(HttpServletRequest httpServletRequest,
                                           HttpServletResponse httpServletResponse,
                                           Object handler,
                                           InvalidXmlException ex) throws IOException {
    String error = ex.getMessage();
    String errorXml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
        "<SOAP-ENV:Header/>" +
        "<SOAP-ENV:Body>" +
        "<SOAP-ENV:Fault>" +
        "<faultcode>SOAP-ENV:Client</faultcode>" +
        "<faultstring xml:lang=\"en\"></faultstring>" + error +
        "</SOAP-ENV:Fault>" +
        "</SOAP-ENV:Body>" +
        "</SOAP-ENV:Envelope>";
    httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    httpServletResponse.setContentType("text/xml");
    httpServletResponse.getWriter().write(errorXml);
    httpServletResponse.getWriter().flush();
  }
}

在 bean 配置上通过设置使用自定义更新messageDispatcherServlet如下。messageReceiverHandlerAdapterBeanNameWebServiceMessageReceiverHandlerAdapter

  @Bean
  public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
    MessageDispatcherServlet servlet = new MessageDispatcherServlet();
    servlet.setApplicationContext(applicationContext);
    servlet.setMessageReceiverHandlerAdapterBeanName("customMessageReceiverHandlerAdapter");
    return new ServletRegistrationBean(servlet, "/ws/*");
  }

  @Bean
  public CustomWebServiceMessageReceiverHandlerAdapter customMessageReceiverHandlerAdapter() {
    CustomWebServiceMessageReceiverHandlerAdapter customWebServiceMessageReceiverHandlerAdapter =
        new CustomWebServiceMessageReceiverHandlerAdapter();
    customWebServiceMessageReceiverHandlerAdapter.setMessageFactory(new DomPoxMessageFactory());
    return customWebServiceMessageReceiverHandlerAdapter;
  }
于 2020-07-28T07:37:52.800 回答
-1

您必须在 spring bean 中“连接”(或“注入”)异常处理程序。我不确定您的哪个 Spring bean 实际上需要异常处理程序。

就个人而言,我使用default-autowire="byName",这会导致我的 exceptionHandler 自动连接到我的 Controller 类中。您的方法实际上使用手动接线。因此,您需要找出哪个 bean 应该实际使用异常处理程序。您是否尝试过(就在我的头上):

<bean class="org.springframework.ws.server.endpoint.adapter.MarshallingMethodEndpointAdapter">
    <constructor-arg ref="marshaller"/>
    <property name="exceptionHandler" ref="exceptionHandler" />
</bean>

或者你可以添加 Spring 的自动装配机制,让它自动装配 bean。:)

于 2010-08-18T15:07:06.543 回答