首页 > 解决方案 > 向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);
       
      

但错误仍在继续。任何帮助都将不胜感激。

标签: javaweb-servicesaxissoap-client

解决方案


只需导入 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....");

推荐阅读