在Spring Boot SOAP应用程序中映射多个URL

时间:2018-11-18 09:14:57

标签: web-services spring-boot soap

假设我有2个URL和2个Endpoint Service。 我要路线如果  URL 1称为->路由服务1,  URL 2称为->路由服务2

在Rest Service中这太容易了,但是我不知道如何在Spring Boot SOAP App中处理它。

我的配置类:

public class WebServiceConfig extends WsConfigurerAdapter {
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/getAll/","/getValueByKey/");
    }

    @Bean(name = "getAll")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema reqRespSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("PrototypePortAll");
        wsdl11Definition.setLocationUri("/getAll/");
        wsdl11Definition.setTargetNamespace("acc");
        wsdl11Definition.setSchema(reqRespSchema);
        return wsdl11Definition;
    }

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


    @Bean(name = "getValueByKey")
    public DefaultWsdl11Definition defaultWsdl11Definition2(XsdSchema reqRespSchema2) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("PrototypePort");
        wsdl11Definition.setLocationUri("/getValueByKey/");
        wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
        wsdl11Definition.setSchema(reqRespSchema2);
        return wsdl11Definition;
    }

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

我的端点类:

@Endpoint
public class PrototypeEndpoint {
    private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service";

    @Autowired
    private Services service;

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "PrototypeRequest")
    @ResponsePayload
    public PrototypeResponse getValueByKey(@RequestPayload PrototypeRequest prototypeRequest) {
        PrototypeResponse response = new PrototypeResponse();

        HashMap<String, String> map = service.map;

        response.setValue(map.get(prototypeRequest.getName()));

        return response;

    }



    @PayloadRoot(namespace = "acc", localPart = "PrototypeRequestAll")
    @ResponsePayload
    public PrototypeResponseAll getAllValue(@RequestPayload PrototypeRequestAll prototypeRequestAll) {
        PrototypeResponseAll response = new PrototypeResponseAll();

        List<String> resultList=new ArrayList<>();

          service.map.entrySet().forEach(index->resultList.add(index.getValue()));
        response.setValue(resultList);
        return response;
    }
    }

注意:每个端点都有两个.xsd文件。

我需要帮助。 谢谢。

0 个答案:

没有答案