java - 向axis1.4客户端java添加隐含soap头
问题描述
我正在尝试使用axis1.4客户端和java7调用Web服务,我可以使用soap ui添加Auth标头但是当我通过代码尝试它时,我得到了来自服务器的UnAthurized 401响应。主要问题是 wsdl 文件中未定义安全标头。所以我 expoerted 肥皂项目并找出一些标题,如:
<con:credentials>
<con:username>sarmayeh_gsb</con:username>
<con:password>Sarmayeh@gsb123</con:password>
<con:domain>estelamwebservice.nocservices.org/iws/Estelam</con:domain>
<con:selectedAuthProfile>Basic</con:selectedAuthProfile>
<con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes>
<con:authType>Global HTTP Settings</con:authType>
</con:credentials>
我怎样才能在我的代码中添加它?
我试过类似的东西
EstelamLocator wsLocator = new EstelamLocator();
logger.info("creating locateor...");
EstelamPort ws = wsLocator.getEstelamPort(new URL("http://10.0.233.254/sabteahval/proxy/SabteAhvalPS?wsdl"));
//add SOAP header for authentication
SOAPHeaderElement authentication = new SOAPHeaderElement("http://est","Authentication");
SOAPHeaderElement user = new SOAPHeaderElement("http://est","User", service_user);
SOAPHeaderElement password = new SOAPHeaderElement("http://est","Password", service_pass);
authentication.addChild(user);
authentication.addChild(password);
Estelam3TRequest re= new Estelam3TRequest();
re.setBirthDate("13750427");
re.setBirthDate("0019317859");
logger.info("creat authentication...");
((org.apache.axis.client.Stub)ws).setHeader(authentication);
ws.getEstelam3T("Bksr","Bk@Sr-0513","36571","915DE0DEAD1",re);
但错误仍在继续。任何帮助都将不胜感激。
解决方案
只需导入 org.apache.axis.client.Stub 和 javax.xml.rpc 然后设置用户名和密码。
EstelamLocator wsLocator = new EstelamLocator();
logger.info("creating locateor...");
EstelamPort ws = wsLocator.getEstelamPort(new URL("http://****/sabteahval/proxy/SabteAhvalPS?wsdl"));
logger.info("creating EstelamPort...");
Estelam3TRequest re= new Estelam3TRequest();
re.setBirthDate("13750427");
re.setNin("0019317859");
( (Stub) ws)._setProperty(Call.USERNAME_PROPERTY,service_user);
( (Stub) ws)._setProperty(Call.PASSWORD_PROPERTY,service_pass);
logger.info("_setProperty on ws....");
ws.getEstelam3T("Bksr","Bk@Sr-0513","36571","915DE0DEAD1",re);
logger.info("return object....");
推荐阅读
- node.js - 重定向页面时如何将jwt存储在cookie中并将其传递给身份验证功能?
- amazon-web-services - MeterUsage 和 BatchMeterUsage AWS Marketplace Metering Service API 有什么区别?
- python - 由于框架,我找不到 Element
- android - 如何每个会话仅显示一次弹出窗口?
- mysql - 无法添加外键约束 - 无法解析接近错误的表名
- sql - 从没有列名的表中选择
- ionic-framework - 如何发送一个 ngModel 新字符串但将已经存在的另一个字符串发送到数据库?
- java - Recyclerview 中的 Admob 横幅广告
- javascript - 如果我使用扩展语法,如何完全返回包含嵌套对象数组的数组?
- oracle - oracle session_id 在 *_scheduler_job_run_details 中代表什么