Как настроить Axis Security Header для следующего XML с помощью заглушки - PullRequest
0 голосов
/ 07 января 2019
I am trying to automate the xml web services using Apache Axis Java API and I have generated the stubs. But my Below XML has header part which i need to customize manually using stub. 
So I have used SOAPHeaderElement from stub class and designed the code. But I am getting extra namespace like xmlns:wsse="" in each node and soapenv: in header node.
So, please modify my code to get the exact format(Expected) as given below 

Ниже приведена часть заголовка XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <wsse:Header mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:Security>
            <wsse:UsernameToken>
               <wsse:Username>InternalServiceUser</wsse:Username>
               <wsse:Password>123456</wsse:Password>
            </wsse:UsernameToken>
         </wsse:Security>
      </wsse:Header>
   </soapenv:Header>

Ниже приведен код:

        SOAPHeaderElement wsseHeader = new SOAPHeaderElement(new  PrefixedQName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Header", "wsse")); 
        String nullString = null;
        MessageElement Security = new MessageElement(nullString, "wsse:Security");
        MessageElement usernameToken = new MessageElement(nullString, "wsse:UsernameToken");
        MessageElement username = new MessageElement(nullString, "wsse:Username");
        MessageElement password = new MessageElement(nullString, "wsse:Password");
        username.setObjectValue("InternalServiceUser");
        usernameToken.addChild(username);
        password.setObjectValue("123456");
        usernameToken.addChild(password);
        Security.addChild(usernameToken);
        wsseHeader.addChild(Security);
        wsseHeader.setActor(null);
        wsseHeader.setMustUnderstand(true);

        _call.addHeader(wsseHeader);

Ожидаемый запрос Заголовок XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <wsse:Header mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:Security mustUnderstand="1">
            <wsse:UsernameToken>
               <wsse:Username>InternalServiceUser</wsse:Username>
               <wsse:Password>123456</wsse:Password>
            </wsse:UsernameToken>
         </wsse:Security>
      </wsse:Header>
   </soapenv:Header>

Фактическая часть XML-заголовка запроса, которая создается после выполнения:

не удалось удалить soapenv: в теге заголовка и xmlns: wsse = "" в тегах безопасности, имени пользователя и пароля с помощью кода

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Header soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Security xmlns:wsse=""><wsse:UsernameToken xmlns:wsse="">
<wsse:Username xmlns:wsse="">InternalServiceUser</wsse:Username>
<wsse:Password xmlns:wsse="">123456</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</wsse:Header>
</soapenv:Header>
...