嗨,我创建了使用SOAP服务的代码,
对于身份验证 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
我的配置代码如下
@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属性。我怎样才能?
最佳答案
您是否使用WebServiceTemplate发送请求?如果是,则可以执行以下操作:
ActionCallback callback = new ActionCallback(
new URI("action uri"));
在这里,您应该提供操作的实际uri位置,而不是“action uri”。然后做
getWebServiceTemplate().marshalSendAndReceive(request, callback)