简体   繁体   English

向MockWebServiceClient添加基本的HTTP身份验证

[英]Add basic http authentication to MockWebServiceClient

I have som old test that are calling some web services. 我有一个旧测试,正在调用某些Web服务。 There was no security on the webservice before. 以前,Web服务上没有安全性。 Now basic http authentication has been added to it and test are therefore failing. 现在已向其添加了基本的HTTP身份验证,因此测试失败。 Test are using org.springframework.ws.test.server.MockWebServiceClient 测试使用的是org.springframework.ws.test.server.MockWebServiceClient

example of test: 测试示例:

@Autowired
MockWebServiceClient mockClient

def "import valid entity"() {

    setup:
    def request = loadEntitesToRequest(validEntityFile)
    Source requestPayload = createStringSourceFromObject(request)

    when: 'Endpoint is requested to import valid entity'
    mockClient.sendRequest(withPayload(requestPayload)).andExpect(new ResponseMatcher() {
        void match(WebServiceMessage req, WebServiceMessage resp) {
            EntityImportResponse response = marshaller.unmarshal(resp.payloadSource)
            assert response.errorMessage.isEmpty()
            assert response.isSuccess()
        }
    })

    then: 'Entity is successfully imported'
    noExceptionThrown()
}

Is there any way to add basic http auth to this client? 有什么方法可以向此客户端添加基本的HTTP身份验证? I know how to add it to WebServiceTemplate but for this i have not found any way. 我知道如何将其添加到WebServiceTemplate,但是为此我没有找到任何方法。

好吧,这个问题实际上是一个不好的问题,MockWebserviceClient根本不处理http,您需要在此客户端之外的http请求中设置所需的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM