zoukankan      html  css  js  c++  java
  • 处理soapUI特殊返回报文 【原】

    String message ="<?xml version="1.0" encoding="UTF-8"?>"
          
          + "<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">"
          + "<soap:Body>"
          +  "   <SetBxInfoTest xmlns="http://tempuri.org/">  "
          +  "        <jkxlh>C33D61EF17</jkxlh>  "
          +  "         <WriteXml> <![CDATA[<?xml version="1.0" encoding="UTF-8"?>"
          +  "       <Data> "
          +  "        <value> "
          +  "             <Hphm/>  "
          +  "            <Cjh>QWSDEFRTGVFEDSWER</Cjh>  "
          +  "          <Bdh>63008080120150000001</Bdh>  "
          +  "            <Pdh>23008135920150000001</Pdh>  "
          +  "           <Jqxbf>1100.00</Jqxbf>  "
          +  "           <Qbrq>2015-05-21</Qbrq>  "
          +  "           <Zbrq>2016-05-20</Zbrq>  "
          +  "            <Bbxr>张</Bbxr>  "
          +  "          <Bbxrsfz>441225198006022516</Bbxrsfz>  "
          +  "           <Jqxzt>1</Jqxzt>  "
          +  "            <Scrq>2015-05-20 15:32:35</Scrq>  "
          +  "           <Ccsqk>4</Ccsqk>  "
          +  "           <Ccsje/>  "
          +  "           <Ccspzhm/>  "
          +  "            <Ccssbh/>  "
          +  "           <Ccsnsrq/>  "
          +  "            <Ccsnsqsrq/>  "
          +  "           <Ccsnszzrq/>  "
          +  "            <BdImg/> "
          +  "        </value> "
          +  "      </Data>]]> </WriteXml> "
          +  "      </SetBxInfoTest> "
          +  "  </soap:Body> "
          +  "</soap:Envelope>";
            HttpClient httpclient = HttpClients.createDefault();
            HttpPost httppost = new HttpPost("http://10.15.22.120:8866/5700000002/ZHJDCBXSJAddCxSj/V1");//请求地址
            StringEntity content =new StringEntity(message, Charset.forName("UTF-8"));// 第二个参数,设置后才会对,内容进行编码
            content.setContentType("application/soap+xml; charset=UTF-8");//设置UTF-8编码
            content.setContentEncoding("UTF-8");
            httppost.setEntity(content);
            
            HttpResponse responses = null;
            Document doc = null;
            String queryResReceiveXml = null;
            String sentity = null;
            try {
                responses = httpclient.execute(httppost);//执行发送
                HttpEntity resEntity = responses.getEntity();
                if (resEntity != null) {
                    sentity = EntityUtils.toString(resEntity, "UTF-8");//接受返回报文数据
                    System.out.println("返回2报文:"+sentity);
                    doc = XmlTool.getDocument(sentity, "UTF-8");//转换格式化
                    Element eRoot = doc.getRootElement();
                    Element body = eRoot.getChild("Body", eRoot.getNamespace());
                    Element resp = (Element) body.getChildren().get(0);
                    Element returnele = (Element) resp.getChildren().get(0);
                    if(returnele != null){
                        queryResReceiveXml = returnele.getText().toString();
                    }
                }
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                System.out.println("返回报文:
    " + queryResReceiveXml);
            }
  • 相关阅读:
    设计模式-抽象工厂模式
    设计模式-工厂方法模式
    设计模式-单例
    java集合-补充HashMapJDK1.8
    java多线程-线程池
    java-阻塞队列
    java多线程-信号量
    java多线程-读写锁
    java多线程-锁
    Ubuntu下编译Poco库
  • 原文地址:https://www.cnblogs.com/hmhhz/p/9663037.html
Copyright © 2011-2022 走看看