cyydjt 2013-07-09
一、解析示例:
public Senddividendstrategy senddividendstrategy(OMElement in) { Senddividendstrategy svs = null; try { svs = EbsServiceImp.checkDataByOMElement(in); } catch (Exception e) { e.printStackTrace(); } return svs; } public static Senddividendstrategy checkDataByOMElement(OMElement element) throws AxisFault, Exception { Senddividendstrategy s = null; if (element != null) { Calendar cal = Calendar.getInstance(); SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd"); String mDateTime = formater.format(cal.getTime()); List<Senddividendstrategy> sList = new ArrayList<Senddividendstrategy>(); Senddividendstrategy svs = null; Iterator iteClient = element.getChildElements(); while (iteClient.hasNext()) { OMNode omNodeClient = (OMNode) iteClient.next(); if (omNodeClient.getType() == 1) { OMElement omeClient = (OMElement) omNodeClient; if (omeClient.getLocalName().toLowerCase().equals("sparams")) { Iterator iteTParam = omeClient.getChildElements(); while (iteTParam.hasNext()) { OMNode omNodeTParam = (OMNode) iteTParam.next(); if (omNodeTParam.getType() == 1) { OMElement omeTParam = (OMElement) omNodeTParam; if (omeTParam.getLocalName().toLowerCase().equals("sparam")) { svs = (Senddividendstrategy) BeanUtil.processObject(omeTParam, Senddividendstrategy.class, null, true, new DefaultObjectSupplier()); sList.add(svs); } } } } } } s = senddividendstrategyCal(sList); } return s; }
二、封装示例:
1、 /** * 测试 * @param statistic * @param userId * @return */ public static String sendDataDfzwByOMElement() { targetEPR = new EndpointReference("http://192.168.10.227/ebsService/services/ebsService?wsdl"); // 创建request SOAP包 OMFactory fac = OMAbstractFactory.getOMFactory(); // OMNamespace指定此SOAP文档名称空间 OMNamespace om = fac.createOMNamespace("http://service.eee.shun.com", "client"); // 创建元素,并指定其在om指代的名称空间中,元素名必须跟services.xml重大operation的name相同 OMElement method = fac.createOMElement("senddividendstrategy", om); OMElement root; OMElement svsListOmElement; List<Senddividendstrategy> svsList = new ArrayList<Senddividendstrategy>(); try { Senddividendstrategy s = new Senddividendstrategy(); for (int i = 0; i < 10 ; i++) { s.setDividend_date("1"); s.setCompany_code("2"); s.setEquity_note_number("3"); s.setDividend_line_number(Long.valueOf(4)); s.setAssign_type_code("5"); s.setAssign_source("6"); s.setSegment3("7"); s.setAmount(Long.valueOf(8)); s.setCash_amount(Long.valueOf(9)); s.setCash_proportion(Long.valueOf(10)); s.setCash_person_proportion(Long.valueOf(11)); s.setCapital_source("12"); s.setCapital_amount(Long.valueOf(13)); s.setCapital_proportion(Long.valueOf(14)); s.setCapital_person_proportion(Long.valueOf(15)); s.setEquity_category("16"); s.setEquity_properties("17"); s.setReduce_tax_amount(Long.valueOf(18)); s.setStart_date("19"); s.setManager_type("20"); s.setProcess_startus("21"); s.setData_status("22"); s.setX_msg_data("23"); s.setX_return_status("24"); svsList.add(s); } root = fac.createOMElement("root", null); svsListOmElement = BeanUtil.getOMElement(new QName("sparams"), svsList.toArray(), new QName("sparam"), false, null); root.addChild(svsListOmElement); method.addChild(root); Options options = new Options(); options.setTo(targetEPR); ServiceClient sender = new ServiceClient(); sender.setOptions(options); // 发出request SOAP // 同时将得到的远端由senddividendstrategy方法返回的信息保存到result // 通过services.xml能准确找到senddividendstrategy方法所在的文件 sender.sendReceive(method); String filePath = "E:\\ebs.xml"; writeToFile(filePath, method); } catch (Exception e) { e.printStackTrace(); } return null; } 2、 //创建response SOAP包 OMFactory fac = OMAbstractFactory.getOMFactory(); //OMNamespace指定此SOAP文档名称空间 OMNamespace omNs = fac.createOMNamespace("http://service.eee.shun.com", "service"); //创建元素SafetyTrouble返回给客服端的元素,并指定其在omNs指代的名称空间中 OMElement resp = fac.createOMElement("line-service", omNs); OMElement root = fac.createOMElement("root", null); ReturnOutParameter rop = new ReturnOutParameter(); List<ReturnOutParameter> ropList = new ArrayList<ReturnOutParameter>(); OMElement ropListOmElement; rop.setX_return_status(x_return_status); rop.setX_msg_data(x_msg_data); ropList.add(rop); //添加消息信息 ropListOmElement = BeanUtil.getOMElement(new QName("rparams"), ropList.toArray(), new QName("rparam"), false, null); root.addChild(ropListOmElement); resp.addChild(root); return resp;