0
您好我想为spring soap客户端添加头文件,我有一个如下所示的ClientAppConfig类;如何在Spring soap客户端上添加自定义头文件
@Configuration
public class ClientAppConfig {
@Bean
public Wss4jSecurityInterceptor wss4jSecurityInterceptor() {
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
interceptor.setSecurementActions("Timestamp");
interceptor.setSecurementUsername("user");
interceptor.setSecurementPassword("*******");
return interceptor;
}
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com");
return marshaller;
}
@Bean
public SomeClient someClient(Jaxb2Marshaller marshaller) {
SomeClient client = new SomeClient();
client.setDefaultUri("http://test");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
实施例客户端:
@Component
public class SomeClient extends WebServiceGatewaySupport {
public SomeResponse someMethod(ArrayOfLong arrayOfLong) {
SomeRequest request = new SomeRequest();
request.setsomeId(arrayOfLong);
SomeResponse response = (SomeResponse) getWebServiceTemplate()
.marshalSendAndReceive(request, new SoapActionCallback(
"http://soapaction"));
return response;
}
}
我有这样WSDL请求;
<soapenv:Envelope xmlns:soapenv="http://envelope" xmlns:v1="http://Service">
<soapenv:Header xmlns:as="http://Schema">
<wsse:Security xmlns:wsse="http://wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>user</wsse:Username>
<wsse:Password>********</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<as:consumerContext xsi:type="as:IntWebAppContextType" xmlns:as="http://Schema" xmlns:xsi="http://XMLSchema-instance">
<consumerCode>someCode</consumerCode>
</as:consumerContext>
</soapenv:Header>
<soapenv:Body>
<v1:someReceived xmlns:ns3="http://Service" xmlns:ns2="http://Schema">
<v1:parameters>
<!--Optional:-->
<v1:someId>
<!--Zero or more repetitions:-->
<v1:long>111111111</v1:long>
</v1:someId>
</v1:parameters>
</v1:someReceived>
</soapenv:Body>
</soapenv:Envelope>
我已经加入的用户名和密码,但我要补充as:consumerContext
部分,我需要得到consumerCode用于获取响应其他明智的即时得到错误。我怎样才能得到consumerCode弹簧WS
我已经使用org.jvnet.jaxb2.maven2生成了maven插件 – mstykt
它和'wsimport'做了同样的事情,您会找到'ConsumerContext.java',填充它并将其设置为'Header'的一部分。 – Arpit
只有HeaderType类,是的,它具有:consumerContext元素如何包含respoonse或全局设置 – mstykt