Web Service 03

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.soap.Node;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.w3c.dom.NodeList;

public class ReceiverSoapMessage
{
private static Logger logger = Logger.getLogger(ReceiverSoapMessage.class);

private static SOAPBody body = null;

// private static SOAPHeader header = null;

private static SOAPEnvelope envelope = null;

private static SOAPElement endPointUrlResult = null;

private static SOAPElement requestHeader = null;

// private static SOAPElement ResultBody = null;

/**
* 定义接收SOAP Response Message Header
* @param respMsg 返回报文
* @return returnBool
*/
public static boolean buildSoapResponseMessage(SOAPMessage respMsg)
{
boolean returnBool = false;
try
{
logger.debug("build Soap Response Message begin.");
if (respMsg != null)
{
// 从返回报文中得到SOAP消息头
envelope = respMsg.getSOAPPart().getEnvelope();
// 从返回报文中得消息体
// header = envelope.getHeader();

body = envelope.getBody();
// 从消息体中得到父节点
endPointUrlResult = (SOAPElement) body
.getChildElements(
envelope
.createName("EndPointUrlResultMsg",
"esb",
"http://ngbss.huawei.com/esb/endpointurl/webservice"))
.next();
// 得到第一个子节点RequestHeader

requestHeader = (SOAPElement) endPointUrlResult
.getChildElements().next();

// 得到第二个子节点RequestBody
// ResultBody = (SOAPElement) EndPointUrlResult.getLastChild();
}
logger.debug("build Soap Response Message sucess.");
returnBool = true;
return returnBool;
}
catch (Exception e)
{
logger
.error("build Soap Response Message failed and The Message was:"
+ e.getMessage());
return returnBool;
}

}

/**
* 接收全查询的SOAP Response Message
* @return listUrlInfo
*/
public static List<EndPointUrlEntity> getqueryAllResponeMessage()
{
List<EndPointUrlEntity> listUrlInfo = new ArrayList<EndPointUrlEntity>();
String urlInfo = null;
try
{
// 得到String,并将其转成XML形式的String;
NodeList resultHeaderList = requestHeader.getChildNodes();
if (resultHeaderList.getLength() > 0)
{
for (int i = 0; i < resultHeaderList.getLength(); i++)
{
Node node = (Node) resultHeaderList.item(i);
if (node.getNodeName().contains("RetDesc"))
{
urlInfo = node.getTextContent();
}
}

listUrlInfo = readXMLMessage(urlInfo);
}
return listUrlInfo;

}
catch (Exception e)
{
listUrlInfo = null;
logger
.error("query All Respone Message failed and the Message was:"
+ e.getMessage());
return listUrlInfo;
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值