我有一个用Spring Web Services编写的SOAP Web服务,我想对其进行集成测试。
我想使用reference documentation指向spring-ws-test
。因此,测试代码类似于参考中的示例,类似这样:
@Autowired
private ApplicationContext applicationContext;
private MockWebServiceClient mockClient;
@Before
public void createClient() {
mockClient = MockWebServiceClient.createClient(applicationContext);
}
@Test
public void customerEndpoint() throws Exception {
Source requestEnvelope = new ResourceSource(new ClassPathResource("request.xml"));
Source responsePayload = new ResourceSource(new ClassPathResource("response.xml"));
mockClient.sendRequest(withSoapEnvelope(requestPayload)).
andExpect(payload(responsePayload));
}
但是,我正在测试的端点正在使用基本身份验证,并且它希望读取Authorization
标头中的值。它没有为该任务使用spring-security
,但是它具有自定义逻辑,该逻辑通过从TransportContextHolder
获取HttpServletResponse
来获取HTTP标头。因此,该请求触发了端点,但是无法检索基本身份验证base64
令牌。
问题是,在这种情况下如何传递HTTP标头?有可能吗?如果不是,首选的替代方法是什么?
我已阅读javadoc
,但找不到传递标题的方法。另外,我发现了这个question,它很相似,但是对我没有多大帮助。