我有一个使用Axis 1.4创建的旧Web服务,我需要使用它。要使其工作,必须在请求标头上添加以下标记
授权:基本{codifiedUsername}
使用soapui我没有任何问题,但是当我尝试将授权令牌添加到轴服务调用时,服务响应有错误,就像我没有将codifiedUsername设置为soapui上的请求头一样
我正在使用以下代码尝试将标记Authorization:Basic {codifiedUsername}添加到标题
String targetNamespace = "http://www.mysrevice/services/MyService";
String serviceName = "MyService";
String portName = "MyService";
String wsdlURL = "http://xxx.xx.xx.x:8080/idws2/services/MyService?wsdl";
QName qnameService = new QName(targetNamespace, serviceName);
QName qnamePort = new QName(targetNamespace, portName);
ServiceFactory factory = (ServiceFactory) ServiceFactory.newInstance();
Service service = (Service)factory.createService(new URL(wsdlURL),qnameService);
QName qnameOperation = new QName(targetNamespace, "validate");
Call call = (Call)service.createCall(qnamePort, qnameOperation);
String user="235654321";
byte[] bUser=usuario.getBytes();
String encoded=Base64.encode(bUser);
System.out.println("encoded user: "+encoded);
org.apache.axis.message.SOAPHeaderElement header = new org.apache.axis.message.SOAPHeaderElement("http://myservice.com","MyServiceHeade r");
SOAPElement node = header.addChildElement("Authorization:");
node.addTextNode("Basic "+encoded);
call.addHeader(header);
Object[] params = {"6677","6778","001","trrtr"};
call.addHeader(header);
String response = (String)call.invoke(params);
我还创建了webservice存根,以查看存根是否有任何方法来传递带有授权信息的头,但我不太了解轴。这是我必须调用相同方法的代码
MyService myService = new MyServiceLocator();
MyServiceSoapBindingStub stub;
stub = new MyServiceSoapBindingStub(new URL(myService.getMyServiceAddress()),myService);
String result=stub.validate("6677","6778","001","trrtr");
所以我需要知道如何使用java Axis 1.4
在服务调用或服务存根上正确设置授权令牌由于
答案 0 :(得分:0)
为Axis 1.4设置Auth标头元素应该看起来像这样:
SOAPHeaderElement auth = new SOAPHeaderElement(url,"Authentication");
SOAPHeaderElement user = new SOAPHeaderElement(url,"User", "string");
SOAPHeaderElement pass = new SOAPHeaderElement(url,"Password", "string");
auth.addChild(user);
auth.addChild(pass);
// add to Call object ...
这应该有效...然后只需添加到调用对象,就像使用现有的SOAPHeaderElement
一样。