Http 基本身份验证不适用于 Spring WS 和 WebServiceTemplate 凭据 [英] Http Basic Authentication not working with Spring WS and WebServiceTemplate credentials

查看:31
本文介绍了Http 基本身份验证不适用于 Spring WS 和 WebServiceTemplate 凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to add HTTP Basic Auth credentials to my SOAP-Request using Spring(-WS). The Request itself works, but no credentials are submitted. The HTTP header should look like:

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

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

But the last row is not missing. In MyConfig.java, I configure the Bean (no 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;
}

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

If you know the reason why the Authorization line is missing, please let me know. :) Thank you a lot in advance

推荐答案

我遇到了类似的问题,这篇文章帮助了我:https://looksok.wordpress.com/2014/09/06/spring-4-soap-request-with-http-basic-身份验证/

I had similar problem and this article helped me: https://looksok.wordpress.com/2014/09/06/spring-4-soap-request-with-http-basic-authentication/

这篇关于Http 基本身份验证不适用于 Spring WS 和 WebServiceTemplate 凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆