如何将服务?wsdl转发到Spring WS中的service.wsdl

时间:2017-03-27 12:03:38

标签: web-services wsdl spring-ws

第一个抱歉我可怕的英语。我有以下Spring WS配置:

@Configuration
class WSConfig {

    ...

    @Bean
    Wsdl11Definition wsdlSchema() {

        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("service.wsdl"));

        return wsdl11Definition;
    }
}

所以我可以使用URL * / service.wsdl 获取WSDL文件。

是否可以添加网址转发 * / service?wsdl - > * / service.wsdl 某些WS客户端使用URL * / service?wsdl。

1 个答案:

答案 0 :(得分:0)

可能的解决方案是扩展MessageDispatcherServlet

class CustomMessageDispatcherServlet extends MessageDispatcherServlet {

private static final String WSDL_SUFFIX_NAME = ".wsdl";

private Map<String, WsdlDefinition> wsdlDefinitions;

CustomMessageDispatcherServlet(ApplicationContext applicationContext) {

    super();
    setApplicationContext(applicationContext);
    setTransformWsdlLocations(true);
    setTransformSchemaLocations(false);
}

@Override
protected void initStrategies(ApplicationContext context) {

    super.initStrategies(context);
    initWsdlDefinitions(context);
}

private void initWsdlDefinitions(ApplicationContext context) {

    wsdlDefinitions = BeanFactoryUtils
            .beansOfTypeIncludingAncestors(
                    context, WsdlDefinition.class, true, false);
}

// here with dealing with "wsdl" parameter in HTTP GET request
@Override
protected WsdlDefinition getWsdlDefinition(HttpServletRequest request) {

    if (HttpTransportConstants.METHOD_GET.equals(request.getMethod()) &&
            (request.getRequestURI().endsWith(WSDL_SUFFIX_NAME) || request.getParameter("wsdl") != null)) {

        String fileName = WebUtils.extractFilenameFromUrlPath(request.getRequestURI());
        return wsdlDefinitions.get(fileName);

    } else {
        return null;
    }
}

}