计算机二级

3773考试网计算机等级考试计算机二级正文

用Java来输出soap报文

来源:fjzsksw.com 2010-4-1 14:49:17

 

 

  dbf.setNamespaceAware(true);

  Document doc = dbf.newDocumentBuilder().parse(inSource);

  root = (Node) doc.getDocumentElement();

  }

  Transformer transformer = TransformerFactory.newInstance()

  .newTransformer();

  transformer.setOutputProperty(OutputKeys.INDENT, "yes");

  transformer.transform(new DOMSource(root), new StreamResult(

  System.out));

  }

  }

  public Source informResponse(SOAPPart part) throws Exception {

  SOAPEnvelope soapEnvelope = part.getEnvelope();

  SOAPBody soapBody = soapEnvelope.getBody();

  SOAPElement informRes = soapBody.addChildElement("InformResponse",

  "cwmp");

  SOAPElement max = SOAPFactory.newInstance().createElement(

  "MaxEnvelopes", "", "");

  max.setTextContent("1");

  informRes.addChildElement(max);

  return part.getContent();

  }

  public Source getParameterValues(SOAPPart part, List list) throws Exception {

  SOAPEnvelope soapEnvelope = part.getEnvelope();

  SOAPBody soapBody = soapEnvelope.getBody();

  SOAPElement informRes = soapBody.addChildElement("GetParameterValues",

  "cwmp");

  SOAPFactory soapFactory = SOAPFactory.newInstance();

  SOAPElement names = soapFactory.createElement("ParameterNames", "", "");

  names.addAttribute(new QName("SOAP-ENC:arrayType"), "xsd:string["

  + list.size() + "]");

  SOAPElement nameElement = null;

  for (int i = 0; i < list.size(); i++) {

  nameElement = soapFactory.createElement("string", "", "");

  nameElement.setTextContent((String) list.get(i));

  names.addChildElement(nameElement);

  }

  informRes.addChildElement(names);

  return part.getContent();

  }

  public static void main(String[] args) throws Exception {

  SoapUtil util = new SoapUtil();

  SOAPPart part = util.initSoapPart();

  Source inform = util.getParameterValues(part, util.getTestnames());

  util.soap2String(inform);

  }

 

上一页  [1] [2] [3] [4] 下一页

触屏版 电脑版
3773考试网 琼ICP备12003406号-1