编程语言
首页 > 编程语言> > java-Http基本身份验证不适用于Spring WS和WebServiceTemplate凭据

java-Http基本身份验证不适用于Spring WS和WebServiceTemplate凭据

作者:互联网

我尝试使用Spring(-WS)将HTTP基本身份验证凭据添加到我的SOAP请求中.该请求本身有效,但是没有凭据提交. HTTP标头应如下所示:

[...]
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic mybase64encodedtopsecretcredentials=

但是最后一行没有丢失.在MyConfig.java中,我配置Bean(无XML):

@Bean
public WebServiceTemplate webServiceTemplate() {
    WebServiceTemplate template = new WebServiceTemplate();
    try {
        template.setMarshaller(marshaller());  //Jaxb2Marshaller
        template.setUnmarshaller(marshaller());

        // proxy for tcpmon inspection
        template.setDefaultUri("http://127.0.0.1:29080/target/webservice.php");
        String username = environment.getProperty("config.username");
        String password = environment.getProperty("config.password");
        Credentials credentials = new UsernamePasswordCredentials(username, password);
        HttpComponentsMessageSender sender = new HttpComponentsMessageSender();
        sender.setCredentials(credentials);
        sender.afterPropertiesSet();
        template.setMessageSender(sender);
    } catch (Exception e) {
        // @todo: handle me
    }
    return template;
}

如果您知道缺少授权行的原因,请告诉我. :)提前非常感谢

解决方法:

我有类似的问题,这篇文章对我有帮助:https://looksok.wordpress.com/2014/09/06/spring-4-soap-request-with-http-basic-authentication/

标签:spring-ws,web-services,spring,java,soap
来源: https://codeday.me/bug/20191029/1959268.html