使用Wss4jSecurityInterceptor和Java的SOAP WS-Addressing属性

Piy*_*iya 10 java soap web-services ws-addressing soap-client

嗨,我创建消费SOAP服务的代码,

对于Authentication Header,我使用Wss4jSecurityInterceptor来设置Header信息.

我收到如下的失败回应

 Exception in thread "main" org.springframework.ws.soap.client.SoapFaultClientException: Required element {http://www.w3.org/2005/08/addressing}Action is missing
Run Code Online (Sandbox Code Playgroud)

我的配置代码如下

@Configuration
public class SoapClientConfig {

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("com.xyz.client");
        marshaller.setCheckForXmlRootElement(false);
        return marshaller;
    }

    @Bean
    public MyClient myClient(Jaxb2Marshaller marshaller) throws Exception {
        MyClient client = new MyClient();
        client.setDefaultUri("https://localhost:8080/ws/service");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);

        ClientInterceptor[] interceptors = new ClientInterceptor[] {securityInterceptor()};

        client.setInterceptors(interceptors);
        return client;
    }

    @Bean
    public Wss4jSecurityInterceptor securityInterceptor() {
        Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
        wss4jSecurityInterceptor.setSecurementActions("UsernameToken");
        wss4jSecurityInterceptor.setSecurementMustUnderstand(true);
        wss4jSecurityInterceptor.setSecurementPasswordType("PasswordText");
        wss4jSecurityInterceptor.setSecurementUsername("XXXXXXXXXXX");
        wss4jSecurityInterceptor.setSecurementPassword("XXXXXXXX");
        return wss4jSecurityInterceptor;
    }
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我缺少的东西?

如果我从SOAPUI尝试它的工作正常.如果我从SOAPUI设置WS-Addressing = false也给我同样的错误,那么使用上面的代码设置WS-Addressing属性的问题.我怎么能够?

小智 5

您是否使用WebServiceTemplate发送请求?如果是,您可以执行以下操作:

ActionCallback callback = new ActionCallback(
                    new URI("action uri"));
Run Code Online (Sandbox Code Playgroud)

在这里你应该提供实际的uri行动位置而不是"行动uri".然后做

getWebServiceTemplate().marshalSendAndReceive(request, callback)
Run Code Online (Sandbox Code Playgroud)