WebLogic 上WebServices 总是提示 401 Unauthorized 异常的一种情况!

异常信息:

AxisFault
 faultCode: {http://xml.apache.org/axis/}HTTP
 faultSubcode: 
 faultString: (401)Unauthorized
 faultActor: 
 faultNode: 
 faultDetail: 
{}:return code:  401
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Draft//EN">
<HTML>
<HEAD>
<TITLE>Error 401--Unauthorized</TITLE>
</HEAD>
<BODY bgcolor="white">
<FONT FACE=Helvetica><BR CLEAR=all>
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 401--Unauthorized</H2>
</FONT></TD></TR>
</TABLE>
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100% BGCOLOR=white><FONT FACE="Courier New"><FONT FACE="Helvetica" SIZE="3"><H3>From RFC 2068 <i>Hypertext Transfer Protocol -- HTTP/1.1</i>:</H3>
</FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.4.2 401 Unauthorized</H4>
</FONT><P><FONT FACE="Courier New">The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.46) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains the same challenge as the prior response, and the user agent has already attempted authentication at least once, then the user SHOULD be presented the entity that was given in the response, since that entity MAY include relevant diagnostic information. HTTP access authentication is explained in section 11.</FONT></P>
</FONT></TD></TR>
</TABLE>


</BODY>
</HTML>


{http://xml.apache.org/axis/}HttpErrorCode:401


(401)Unauthorized
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2765)
at org.apache.axis.client.Call.invoke(Call.java:2748)
at org.apache.axis.client.Call.invoke(Call.java:2424)
at org.apache.axis.client.Call.invoke(Call.java:2347)
at org.apache.axis.client.Call.invoke(Call.java:1804)
at cn.test.WSClient.callLocalhost(WSClient.java:43)
at cn.test.WSClient.main(WSClient.java:18)


操作步骤:
1、检查WebLogic控制台标记,搜索 Security ,检查当前WLS的Realm名字 例如:myrealm;
<20XX-12-5 下午03时14分25秒 CST> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.>
2、以上异常提示表示WebServices请求身份认证没有通过,不允许访问服务器资源,此时调用方式必须设置访问账号、以及密码,服务器将拒绝请求;
String endpoint = "http://localhost:7001/MyServicesWeb/services/SayHello";
Service service = new Service();

Call call = (Call) service.createCall();

//设置Security Realm方式一
//            //远程调用用户名设置(HTTP统一认证账号)
//            call.setUsername("weblogic");//wstest/hb_hsxf
//            //远程调用密码设置,黄石公众诉求(HTTP统一认证密码)
//            call.setPassword("passw0rd");
//设置Security Realm方式二
call.setProperty(org.apache.axis.client.Call.USERNAME_PROPERTY, "weblogic"); //账号
call.setProperty(org.apache.axis.client.Call.PASSWORD_PROPERTY,"passw0rd1");//密码

call.setTargetEndpointAddress(new java.net.URL(endpoint));
//设置远程调用方法路径及方法名称
call.setOperationName(new QName("urn:SayHello", "getHello"));
//传入xml文档字符串,返回数据校验错误字符串
//String d = (String) call.invoke(new Object[] {Document.asXML()});
String d = (String) call.invoke(new Object[]{"本地调用"});

System.out.println("Debug-Info: WSClient.callLocalhost Response $d>> "+d);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值