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>