【问题标题】:Adding implict soap header to axis1.4 client java将隐式soap头添加到axis 1.4客户端java
【发布时间】:2020-07-18 06:07:39
【问题描述】:

我正在尝试使用axis1.4 客户端和java7 调用Web 服务,我可以使用soap ui 添加Auth 标头,但是当我通过代码尝试它时,我得到来自服务器的UnAthurized 401 响应。 主要问题是 wsdl 文件中未定义安全标头。所以我公开了soap项目并找出了一些标题,例如:

<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);
       
      

但错误仍然存​​在。 任何帮助都将不胜感激。

【问题讨论】:

  • 请去掉真实的用户名和密码,使用假的

标签: java web-services axis soap-client


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-04-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2011-08-09
    • 2011-05-02
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    相关资源
    最近更新 更多