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