Publishing Static WSDL and related XSD schemas using Spring WS

后端 未结 3 1892
栀梦
栀梦 2021-01-18 08:49

I have one module where I have my XSD schemas, where one schema can reference an other using relative path within schema location:



        
相关标签:
3条回答
  • 2021-01-18 09:13

    Spring web service has a way to do it elegantly actually. All you need to do is to define a SimpleXsdSchema bean with the right id (which will be used as the xsd name without .xsd) in the bean definition xml file, something like below

    <bean id="my" 
            class="org.springframework.xml.xsd.SimpleXsdSchema">
            <property 
                name="xsd" 
                value="/mypackage/my.xsd">
            </property>
    </bean>
    

    More information (including an example) can be found at the following link: Static WSDL with imported XML Schema in Spring Web Service

    0 讨论(0)
  • 2021-01-18 09:25

    Below is the Java config for exposing the schema. This worked for me. Please note that the schema name should match the Bean name and method name. This is very key for this to work. So I kept the XSD name and Bean name as "CustomerDetailsSchema" and make sure the constructor for getCustomerDetails also matches the name.

    @Bean(name = "customerDetails")
    public DefaultWsdl11Definition getCustomerDetails(XsdSchema CustomerDetailsSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("...");
        wsdl11Definition.setServiceName("...");
        wsdl11Definition.setLocationUri("/webservice");
        wsdl11Definition.setTargetNamespace("...");
        wsdl11Definition.setSchema(CustomerDetailsSchema);
        return wsdl11Definition;
    }
    
    @Bean(name = "CustomerDetailsSchema")
    public XsdSchema CustomerDetailsSchema() {
        return new SimpleXsdSchema(new ClassPathResource("schemas/CustomerDetailsSchema.xsd"));
    }
    
    0 讨论(0)
  • 2021-01-18 09:31

    Here is my solution for static WSDL and XSDs

    @Bean(name = "OpportunityAttachmentService")
    public Wsdl11Definition getOpportunityAttachmentServiceDefinition() {
        SimpleWsdl11Definition wsdl11Definition =
                new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(
                new ClassPathResource(
                        "wsdl/getOpportunityAttachment/BeP_getOpportunityAttachment_cuContract.wsdl"));
        return wsdl11Definition;
    }
    
    @Bean(name = "getOpportunityAttachment_Request_CRM")
    public XsdSchema getOpportunityAttachmentServiceRequestXsd() {
        return new SimpleXsdSchema(
                new ClassPathResource("wsdl/getOpportunityAttachment/getOpportunityAttachment_Request_CRM.xsd"));
    }
    
    @Bean(name = "getOpportunityAttachment_Response_CRM")
    public XsdSchema getOpportunityAttachmentServiceResponseXsd() {
        return new SimpleXsdSchema(
                new ClassPathResource("wsdl/getOpportunityAttachment/getOpportunityAttachment_Response_CRM.xsd"));
    }
    
    0 讨论(0)
提交回复
热议问题