java – SOAP客户端基本身份验证:HTTP响应’401:未授权’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – SOAP客户端基本身份验证:HTTP响应’401:未授权’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2669字,纯文字阅读大概需要4分钟。
内容图文
![java – SOAP客户端基本身份验证:HTTP响应’401:未授权’](/upload/InfoBanner/zyjiaocheng/723/17390dcecaf547c7ad64d3a3f848b285.jpg)
我正在尝试创建一个必须调用使用http基本身份验证的服务器的SOAP客户端.
我收到以下错误:
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
...
Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '401: Unauthorized' when communicating with http://localhost:8080/SpringMVCTest/services/ContractService?wsdl=ContractService.wsdl
我的app-config.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<security:http auto-config="true">
<security:intercept-url pattern="/services/*"/>
<security:http-basic/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="wsuser1" password="pw123" authorities="wsuser" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<bean id="client" class="hu.bz.ikti.insurance.service.insurer.ContractService"
factory-bean="clientFactory" factory-method="create"/>
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="hu.bz.ikti.insurance.service.insurer.ContractService"/>
<property name="address" value="http://localhost:8080/SpringMVCTest/services/ContractService?wsdl=ContractService.wsdl"/>
</bean>
</beans>
http基本身份验证在服务器web.xml中配置:
<security-constraint>
<web-resource-collection>
<url-pattern>/services/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>wsuser</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<security-role>
<role-name>webservice</role-name>
</security-role>
在tomcat-users.xml中添加了用户:
<user username="wsuser1" password="pw123" roles="wsuser"/>
我可以在浏览器中打开wsdl给出用户名/密码.
什么可能导致这401:客户端未经授权的错误?
解决方法:
根据这里的CXF文档:
https://cxf.apache.org/docs/jax-ws-configuration.html(请参阅配置Spring Client(选项2))
设置用户名和密码的正确方法是使用clientFactory bean配置中的用户名和密码属性.
所以在clientFactory bean中添加这些:
<property name="username" value="yourUsername"/>
<property name="password" value="yourPassword"/>
内容总结
以上是互联网集市为您收集整理的java – SOAP客户端基本身份验证:HTTP响应’401:未授权’全部内容,希望文章能够帮你解决java – SOAP客户端基本身份验证:HTTP响应’401:未授权’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。