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

标签 java spring web-services soap spring-ws

我尝试使用 Spring(-WS) 将 HTTP Basic Auth 凭据添加到我的 SOAP 请求中。请求本身有效,但未提交任何凭据。 HTTP header 应如下所示:

[...]
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;
}

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

最佳答案

关于java - Http 基本身份验证不适用于 Spring WS 和 WebServiceTemplate 凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24779373/

相关文章:

c# - 从 Android 到 .NET Webservices 的图片上传问题

java - 无法在java中重新绘制

java - Java中字符串重复追加的大O

java - 带有 Youtube 数据 API 的 Apache Nifi

java - 将 JSON 数据从 JQUERY 传递到 java Controller 时出现异常

java - 在 junit 测试中禁用 RedisHttpSessionConfiguration

java - module-info.java 'opens' 语句是否可以包含包和所有子包?

java - Spring Jms 每秒发出警告消息

c# - 实现通过 SSL 使用 Web 服务的 C# 客户端?

java - Web服务器中加载的类的注释是com.sun.proxy.$Proxy52?