我在SOAP项目中配置了Ws-Security用户名和密码验证。现在,当我在SOAP UI中运行请求时,出现异常:
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">No WS-Security header found</faultstring>
我在SoapClientConfig.java中拥有
public class SoapClientConfig {
@SuppressWarnings("deprecation")
@Bean
public Wss4jSecurityInterceptor securityInterceptor(){
@SuppressWarnings("deprecation")
Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
wss4jSecurityInterceptor.setSecurementActions("Timestamp UsernameToken");
wss4jSecurityInterceptor.setSecurementUsername("admin");
wss4jSecurityInterceptor.setSecurementPassword("secret");
return wss4jSecurityInterceptor;
}
@Bean
public Jaxb2Marshaller getMarshaller(){
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("org.onewallet.webservices.disburse");
return marshaller;
}
@Bean
public SoapConnector createLoanClient(){
SoapConnector soapConnector = new SoapConnector();
soapConnector.setMarshaller(getMarshaller());
soapConnector.setUnmarshaller(getMarshaller());
soapConnector.setDefaultUri("http://localhost:8080/soapws/disburse");
ClientInterceptor[] interceptors = new ClientInterceptor[] {securityInterceptor()};
soapConnector.setInterceptors(interceptors);
return soapConnector;
} }
RunClient.java
public class RunClient {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SoapClientConfig.class);
System.out.println(context.getBeanDefinitionCount());
SoapConnector soapConnector = context.getBean(SoapConnector.class);
CreateLoanRequest request = new CreateLoanRequest();
request.setLoanStatus(100);
CreateLoanResponse resp = soapConnector.createLoan(request);
System.out.println("response: " + resp);
} }
LoanEndpoint.java
@Endpoint
public class LoanEndpoint {
private static final String NAMESPACE_URI = "http://www.onewallet.org/webservices/disburse";
@Autowired
private ILoanService loanService;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "createLoanRequest")
@ResponsePayload
public CreateLoanResponse createLoan(@RequestPayload CreateLoanRequest request) {
CreateLoanResponse response = new CreateLoanResponse();
ServiceStatus serviceStatus = new ServiceStatus();
Loan loan = new Loan();
loan.setLoanStatus(request.getLoanStatus());
loan.setExternalId("B9076");
return response; }
更改后,我在SoapUI中更新了WSDL定义,但是我的请求仍然没有显示我添加的Wss4jSecurityInterceptor标头。我还应该在SOAPUI中配置其他内容吗?或者我在SOAP服务中缺少其他配置