• 主页
  • 无法在Spring boot中使用Spring-WS来使用SOAP WS,但可从SOAPUI工作

无法在Spring boot中使用Spring-WS来使用SOAP WS,但可从SOAPUI工作

我正在使用Spring Boot来使用从WSDL生成的SOAP WS。我添加了spring-ws-security,这样我就可以将user/password作为安全头进行传递,如配置中所示:

@Configuration
public class ClientConfig {

    public static final String SIEBEL_ENDPOINT = "http://...";

    @Bean
    public CustomerClient customerClient() {
        CustomerClient client = new CustomerClient();
        client.setDefaultUri(SIEBEL_ENDPOINT);
        client.setWebServiceTemplate(webServiceTemplate(marshaller()));
        return client;
    }

    @Bean
    public WebServiceTemplate webServiceTemplate(Jaxb2Marshaller marshaller) {
        WebServiceTemplate template = new WebServiceTemplate(marshaller, marshaller);
        template.setDefaultUri(SIEBEL_ENDPOINT);
        ClientInterceptor[] interceptors = new ClientInterceptor[] {new LogHttpHeaderClientInterceptor(), wsSecurityInterceptor()};
        template.setInterceptors(interceptors);
        return template;
    }

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("com.test.dms.gen");
        return marshaller;
    }

    @Bean
    public Wss4jSecurityInterceptor wsSecurityInterceptor() {
        Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
        wss4jSecurityInterceptor.setSecurementActions(WSHandlerConstants.USERNAME_TOKEN);
        wss4jSecurityInterceptor.setSecurementPasswordType(WSConstants.PW_TEXT);
        wss4jSecurityInterceptor.setSecurementUsername("rf_USER");
        wss4jSecurityInterceptor.setSecurementPassword("rf_USER");
        return wss4jSecurityInterceptor;
    }

}

和服务调用:

public class CustomerClient extends WebServiceGatewaySupport {
 
    public CustomerInfoOutput getCustomerInfo(String vin) {
        ObjectFactory request = new ObjectFactory();
        final CustomerInfoInput custInfoInput = request.createCustomerInfoInput();
        custInfoInput.setVINNumber(vin);


        return (CustomerInfoOutput) getWebServiceTemplate().marshalSendAndReceive(ClientConfig.SIEBEL_ENDPOINT, custInfoInput);
    }
}

一切都生成得很好,并记录了以下输出:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                   xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                   SOAP-ENV:mustUnderstand="1">
        <wsse:UsernameToken wsu:Id="UsernameToken-e8f183db-44db-4c0b-90d9-ca57e89225fd">
            <wsse:Username>rf_USER</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">rf_USER</wsse:Password>
        </wsse:UsernameToken>
    </wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
    <ns3:CustomerInfo_Input xmlns:ns2="http://siebel.com/testdashboard"
                            xmlns:ns3="http://test.com/rf/customerinfo" xmlns:ns4="http://test.com/rf"
                            xmlns:ns5="http://www.siebel.com/xml/IBM%20test%20Dashboard">
        <ns3:VINNumber>123456789</ns3:VINNumber>
    </ns3:CustomerInfo_Input>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

当我使用SOAP发送这个请求时,它工作得很好。但是当使用WSDL中生成的对象发送它时,我会遇到这样的错误:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <faultcode>SOAP-ENV:Server</faultcode>
            <faultstring>There is no active Web Service with operation named
                'http://test.com/rf/customerinfo:CustomerInfo_Input'.(SBL-EAI-04313)
            </faultstring>
            <detail>
                <siebelf:siebdetail xmlns:siebelf="http://www.siebel.com/ws/fault">
                    <siebelf:logfilename>EAIObjMgr_enu_0023_24117286.log</siebelf:logfilename>
                    <siebelf:errorstack>
                        <siebelf:error>
                            <siebelf:errorcode>SBL-EAI-04313</siebelf:errorcode>
                            <siebelf:errorsymbol>IDS_EAI_WS_OP_NOT_FOUND</siebelf:errorsymbol>
                            <siebelf:errormsg>There is no active Web Service with operation named
                                'http://test.com/rf/customerinfo:CustomerInfo_Input'.(SBL-EAI-04313)
                            </siebelf:errormsg>
                        </siebelf:error>
                    </siebelf:errorstack>
                </siebelf:siebdetail>
            </detail>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

有什么想法吗?

PS:请不要关注URI,因为我对它们进行了更改,但是生成的请求在SOAPUI中工作得很好。

转载请注明出处:http://www.jxbyjx.net/article/20230513/1478228.html