SOAP服务正在肥皂UI中工作,但不通过Java中的代码工作



SOAP服务通过SOAP UI中的"身份验证"选项卡下的参数用户名和密码工作正常,但不从Java代码工作。

请找到以下代码:

ServicesLocator sl = new ServicesLocator();
ServicesSoapProxy proxy = new ServicesSoapProxy();
ServicesSoap serviceSoap = sl.getServicesSoap();
//Service s = new Service();
//Port port = s.getPort(); // if tried using service object s but s.getPort not coming in my code
Port port = (Port) sl.getPort(proxy.getEndpoint(),ServicesSoap.class);
BindingProvider prov = (BindingProvider)port;
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
//then calling SOAP Service 
serviceSoap.callExternalSOAPSERVICE();

错误如下:

faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode: 
 faultString: (401)Unauthorized
faultActor: 
 faultNode: 
 faultDetail: 
      {}:return code:  401

请建议。

设置http标头,授权基本" BASE64CODED用户名/密码"。

类似下面的东西。

String authString = "username" + ":" + "password";
String authStringEnc = new BASE64Encoder().encode(authString.getBytes());
//Get the HTTP Header and set it like below.
objectXXX.header("Authorization", "Basic " + authStringEnc);"
//Call your service, now

相关内容

  • 没有找到相关文章

最新更新