11

嗨,我为使用 SOAP 服务创建代码,

对于身份验证标头,我使用 Wss4jSecurityInterceptor 设置标头信息。

我收到如下失败响应

 Exception in thread "main" org.springframework.ws.soap.client.SoapFaultClientException: Required element {http://www.w3.org/2005/08/addressing}Action is missing

我的配置代码如下

@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;
    }
}

谁能建议我缺少什么?

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

4

2 回答 2

6

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

ActionCallback callback = new ActionCallback(
                    new URI("action uri"));

在这里,您应该提供实际的操作 uri 位置,而不是“操作 uri”。然后做

getWebServiceTemplate().marshalSendAndReceive(request, callback)
于 2017-03-28T11:45:22.297 回答
0

很久以前就开始使用动态值填充 SOAP Header,为此您需要使用回调对象构建 xml 节点... WebServiceMessageCallback

http://docs.spring.io/spring-ws/site/reference/html/client.html#d5e1848

在我的场景中,我需要使用 QName (Java) Node by Node 来构建节点。

于 2017-03-29T07:12:30.287 回答