在Spring WebService中从WSDL而不是XSD公开Web服务

时间:2017-04-26 11:57:58

标签: java spring-ws

在我们的项目中,我们使用的是Spring WebService。配置文件如下所示:

@EnableWs
@Configuration
public class WebServiceConfiguration extends WsConfigurerAdapter {
    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors) {
        PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
        validatingInterceptor.setValidateRequest(true);
        validatingInterceptor.setValidateResponse(true);
        validatingInterceptor.setXsdSchema(customerSchema());
        interceptors.add(validatingInterceptor);
    }

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

    @Bean(name = "someInterface")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema priceListSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("SomePortType");
        wsdl11Definition.setLocationUri("/abc/ws/someInterface");
        wsdl11Definition.setTargetNamespace("someNamespace");
        wsdl11Definition.setSchema(priceListSchema);
        return wsdl11Definition;
    }

    @Bean
    public XsdSchema customerSchema() {
        return new SimpleXsdSchema(new ClassPathResource("SomeXsd.xsd"));
    }
}

wsdl的XSD文件是我们保存在类路径中的SomeXsd.xsd。但我想知道我是否有暴露的wsdl文件,而不是以这种方式生成wsdl。我们如何公开已经存在的wsdl?

1 个答案:

答案 0 :(得分:1)

您是否尝试删除以下

s.registerPreTrackCallback(function() {
    console.log('Pre-Track');
});

s.registerPostTrackCallback(function() {
    console.log('Post-Track');
});

并添加此

   @Bean(name = "someInterface")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema priceListSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("SomePortType");
        wsdl11Definition.setLocationUri("/abc/ws/someInterface");
        wsdl11Definition.setTargetNamespace("someNamespace");
        wsdl11Definition.setSchema(priceListSchema);
        return wsdl11Definition;
    }

您仍需要验证器的xsd。您可能还需要更多配置