SAAJ:如何为SoapHeaderElement创建子元素

时间:2016-01-21 05:39:16

标签: java axis2 axis soap-client saaj


我试图将一些数据发布到远程机器,但它返回一个错误

<soapenv:Fault>
   <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
   <faultstring>no SOAPAction header!</faultstring>

我的意思是我发送标题元素的方式存在问题:

// Java code snip
SOAPHeader header = envelope.getHeader();
header.setPrefix("soapenv");
QName headerElementName = new QName("http://soft.com/webservices/", "AuthHeader");
SOAPHeaderElement authHeader = header.addHeaderElement(headerElementName);

QName headerChild = new QName("Username");
SOAPElement userName =  authHeader.addChildElement(headerChild);
userName.addTextNode("smart");

headerChild = new QName("Password");
SOAPElement passwd = authHeader.addChildElement(headerChild);
passwd.addTextNode("smart");

从响应中可以看出,远程机器上的soap工具包是轴,发送的最终请求及其响应如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ocs="http://ocs.soft.com">
<soapenv:Header>
<AuthHeader xmlns="http://soft.com/webservices/">
<Username>smart</Username>
<Password>smart</Password>
</AuthHeader>
</soapenv:Header>
<soapenv:Body><ocs:doService><ocs:in0 xmlns:ocs="http://ocs.soft.com"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<zsmart>
   <Data>
    <header>
      <ACTION_ID>ModifyBalReturnAllBal</ACTION_ID>
      <REQUEST_ID>005200907310022</REQUEST_ID>
    </header>
    <body>
      <MSISDN>254775127966</MSISDN>
      <AccountCode></AccountCode>
      <BalID></BalID>
      <AddBalance>10000</AddBalance>
      <AddDays>0</AddDays>
      <TransactionSN>00520090731002195</TransactionSN>
    </body>
  </Data>
</zsmart>
]]></ocs:in0></ocs:doService></soapenv:Body></soapenv:Envelope>



HTTP/1.1 500 Internal Server Error
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Wed, 20 Jan 2016 16:56:52 GMT
Server: Apache-Coyote/1.1
Connection: close

<?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:Body>
  <soapenv:Fault>
   <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
   <faultstring>no SOAPAction header!</faultstring>
   <detail>
    <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">ocstest</ns2:hostname>
   </detail>
  </soapenv:Fault>
 </soapenv:Body>
</soapenv:Envelope>

我已经完成了肥皂的文件数百万次,并且我确定这是有效的肥皂要求 我想知道我的标题子元素部分是否定义良好。
如果是这样,轴上的认证问题是什么?

1 个答案:

答案 0 :(得分:1)

在这种情况下,&#34;标题&#34;不是指SOAP标头,而是HTTP标头。使用SAAJ,SELECT products.giftID, products.gift_name, products.price, products.short_description, product_image.picture FROM products LEFT JOIN product_image ON product_image.giftID = products.giftID AND products.vendorID = 1 标头设置如下:

SOAPAction

MimeHeaders headers = message.getMimeHeaders(); headers.addHeader("SOAPAction", "http://www.example.org/someaction"); message个对象。 SOAP操作在服务的WSDL中指定。