Java接收Cordys中webservice接口的返回数据并解析xml获取相应节点数据

在做项目的过程中,需要用Java调用Cordys的webservice接口的返回数据,众所周知,webservice返回的数据是xml形式的,那么我们怎样获取相关节点下的数据呢?

处理之前返回的数据格式如下:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:TestBfoToPmsResponse xmlns:ns2="http://webservice.software.com/">
         <return>
         <![CDATA[<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
         <SOAP:Header xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
         <header xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/General/1.0/">
         <msg-id>005056B8-1720-11E7-EE6C-E0DE65F01FA7</msg-id>
         <license>License has expired since 823 day(s)<cense>
         </header>
         <bpm xmlns="http://schemas.cordys.com/bpm/instance/1.0">
         <instance_id>005056B8-1720-11E7-EE6C-E18135A09FA7</instance_id></bpm>
         </SOAP:Header><SOAP:Body><validateInterfaceResponse xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.schneider.com/bpm/validateInterface">
         <CValue xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.schneider.com/bpm/validateInterface">S</CValue>
         </validateInterfaceResponse></SOAP:Body>
         </SOAP:Envelope>]]>
         </return>
      </ns2:TestBfoToPmsResponse>
   </soap:Body>
</soap:Envelope>

那么我们现在想要获取CValue节点下的数据,怎样获取呢?
下面我们进行一下处理。

public static String TestBfoToCordys(){
        String cordys_webservice_url = "http://www.silencewen.me/cordys/com.eibus.web.soap.Gateway.wcp?organization=o=silence,cn=cordys,cn=defaultInst,o=nxw"
        String soap =
                "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                "  <SOAP:Body>" +
                "    <validateInterface xmlns=\"http://www.schneider.com/bpm/validateInterface\">" +
                " <validateInterfaceResponse>"+
                "</validateInterfaceResponse>"+
                "    </validateInterface>" +
                "  </SOAP:Body>" +
                "</SOAP:Envelope>";
        Map<String, String> resultMap = HttpKit.postSoap3(cordys_webservice_url, soap);
        String resp = resultMap.get("ResultXML");//返回XML
        String resultStatus = resultMap.get("ResultStatus");//返回状态
        if(!"200".equals(resultStatus)){
            Log.soaplog.debug("Cordys webservice 接口连接失败");
            return "ERROR";
        }
        SAXReader reader = new SAXReader();
        Document document = null;
        try {
            document = DocumentHelper.parseText(resp);
            Node EspaNode = document.selectSingleNode(".//*[local-name()='CValue']");//返回xml中CValue节点的数据
            String note = EspaNode.getText();//获取节点数据
            return note;
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;    
    }

这样我们就拿到了我们所需要的CValue节点下的值。

下边是工具类,可以获取cordys的一些证书什么的。

package com.software.utils;

import java.io.IOException;
import java.net.SocketTimeoutException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;

import javax.net.ssl.SSLContext;

import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.config.SocketConfig;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Created by Silence.
 */
public class HttpKit {
    private static Logger logger = LoggerFactory.getLogger(HttpKit.class);
    /**
     * 发送soap到http/https
     * 
     * @param url
     * @param xml
     * @return HttpResponse
     */
    public static SSLContext sslContext;
    public static SSLConnectionSocketFactory sslsf;
    public static PoolingHttpClientConnectionManager cm;
    public static PoolingHttpClientConnectionManager cmhttps;
//  static {
//      try {
//          sslContext = new SSLContextBuilder().loadTrustMaterial(null,
//                  new TrustStrategy() {
//                      public boolean isTrusted(X509Certificate[] chain,
//                              String authType) throws CertificateException {
//                          return true;
//                      }
//                  }).build();
//          sslsf = new SSLConnectionSocketFactory(sslContext);
//          Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
//                  .<ConnectionSocketFactory> create()
//                  .register("https", sslsf).build();
//          cm = new PoolingHttpClientConnectionManager();
//          cm.setMaxTotal(200);
//          cm.setDefaultMaxPerRoute(20);
//          cmhttps = new PoolingHttpClientConnectionManager(
//                  socketFactoryRegistry);
//          cmhttps.setMaxTotal(200);
//          cmhttps.setDefaultMaxPerRoute(20);
//          
//          // Naylor
//          // int socketTimeout = 30000;
//          // SocketConfig socketConfig = SocketConfig.custom()
//          // .setSoTimeout(socketTimeout).build();
//          // cmhttps.setDefaultSocketConfig(socketConfig);
//      } catch (KeyStoreException e) {
//          e.printStackTrace();
//      } catch (NoSuchAlgorithmException e) {
//          e.printStackTrace();
//      } catch (KeyManagementException e) {
//          e.printStackTrace();
//      }
//  }


    public static void init(){
        try {
            sslContext = new SSLContextBuilder().loadTrustMaterial(null,
                    new TrustStrategy() {
                        public boolean isTrusted(X509Certificate[] chain,
                                String authType) throws CertificateException {
                            return true;
                        }
                    }).build();
            sslsf = new SSLConnectionSocketFactory(sslContext);
            Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
                    .<ConnectionSocketFactory> create()
                    .register("https", sslsf).build();
            cm = new PoolingHttpClientConnectionManager();
            cm.setMaxTotal(200);
            cm.setDefaultMaxPerRoute(20);
            cmhttps = new PoolingHttpClientConnectionManager(
                    socketFactoryRegistry);
            cmhttps.setMaxTotal(200);
            cmhttps.setDefaultMaxPerRoute(20);
            // Naylor
            // int socketTimeout = 30000;
            // SocketConfig socketConfig = SocketConfig.custom()
            // .setSoTimeout(socketTimeout).build();
            // cmhttps.setDefaultSocketConfig(socketConfig);
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }
    }



    public static CloseableHttpClient createSSLClientDefault() {
        try {
            SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(
                    null, new TrustStrategy() {
                        // 信任所有
                        public boolean isTrusted(X509Certificate[] chain,
                                String authType) throws CertificateException {
                            return true;
                        }
                    }).build();
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
                    sslContext);
            return HttpClients.custom().setSSLSocketFactory(sslsf).build();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        }
        return HttpClients.createDefault();
    }

    // public static HttpResponse postSoap(String url,String xml){
    // Log.soaplog.debug("url=" + url);
    // Log.soaplog.debug("xml=" + xml);
    // try{
    // CloseableHttpClient httpClient;
    // if("https".equals(url.substring(0, 5))){
    // httpClient=createSSLInsecureClient();
    // }else{
    // httpClient=HttpClients.custom().setConnectionManager(cm).build();
    // }
    // HttpPost httppost=new HttpPost(url);
    // HttpEntity re = new StringEntity(xml,"UTF-8");
    // httppost.setHeader("Content-Type","application/soap+xml; charset=utf-8");
    // httppost.setEntity(re);
    // HttpResponse response = httpClient.execute(httppost);
    // // httppost.abort();
    //
    // return response;
    // }catch(Exception e){
    // e.printStackTrace();
    // }
    // return null;
    // }

    // By Naylor httpPost: 重载
    // 每次调用完需要将连接关闭掉;
    public static Map<String, String> postSoap2(String url, String xml) {
        //初始化:
        init();

        Map<String, String> resultMap = new HashMap<String, String>();
        // 返回字符串
        String rs = null;
        // 返回状态
        String resultStatusCode = "";
        // 创建httppost
        HttpPost httpPost = null;
        // 创建参数队列
        CloseableHttpResponse response = null;

        CloseableHttpClient httpClient = null;
        try {
            if ("https".equals(url.substring(0, 5))) {
                httpClient = createSSLInsecureClient2();
                // httpClient = createSSLClientDefault();
            } else {
                httpClient = HttpClients.custom().setConnectionManager(cm).build();
                // httpClient = HttpClients.createDefault();
            }
            httpPost = new HttpPost(url );
            HttpEntity re = new StringEntity(xml, "UTF-8");
            httpPost.setHeader("Content-Type",
                    "application/soap+xml; charset=utf-8");
            httpPost.setEntity(re);
            response = httpClient.execute(httpPost);
            resultStatusCode = String.valueOf(response.getStatusLine()
                    .getStatusCode());

            HttpEntity entity = response.getEntity();
            if (entity != null) {
                rs = EntityUtils.toString(entity, "UTF-8");
            }
        } catch (Exception e) {
            Log.soaplog.debug("error", e);
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源
            try {
                response.close();
                httpPost.abort();
                httpClient.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        resultMap.put("ResultStatus", resultStatusCode);
        resultMap.put("ResultXML", rs);
        return resultMap;
    }

    public static Map<String, String> postSoap3(String url, String xml) {
        Map<String, String> resultMap = new HashMap<String, String>();
        // 返回字符串
        String rs = null;
        // 返回状态
        String resultStatusCode = "";
        // 创建httppost
        HttpPost httpPost = null;
        // 创建参数队列
        CloseableHttpClient httpClient = null;
        try {
            String msg = "";
            if(Log.msetlog.isDebugEnabled()){
                if(xml.indexOf("<TaskId>") > 0){//审批时调用
                    msg = "; 审批时相关TaskId :" + xml.substring(xml.indexOf("<TaskId>")+8, xml.indexOf("</TaskId>"));
                }else if(xml.indexOf("<def:EspaId>") > 0){
                    msg = "; SEQID:" + xml.substring(xml.indexOf("<def:EspaId>")+12, xml.indexOf("</def:EspaId>"));
                }else if(xml.indexOf("<espaId>") > 0){
                    msg = "; SEQID:" + xml.substring(xml.indexOf("<espaId>")+8, xml.indexOf("</espaId>"));
                }else if(xml.indexOf("<wsse:Username>") > 0){
                    msg = "; UserName:" + xml.substring(xml.indexOf("<wsse:Username>")+15, xml.indexOf("</wsse:Username>"));
                }
            }
            if ("https".equals(url.substring(0, 5))) {
                // 使用连接池
                // httpClient=createSSLInsecureClient();
                // 不使用连接池
                Log.msetlog.debug("创建https对应httpClient开始时间:"+DateKit.getNowTime()+msg);
                httpClient = createSSLClientDefault();
                Log.msetlog.debug("创建https对应httpClient结束时间:"+DateKit.getNowTime()+msg);
            } else {
                // httpClient=HttpClients.custom().setConnectionManager(cm).build();
                Log.msetlog.debug("创建httpClient开始时间:"+DateKit.getNowTime()+msg);
                httpClient = HttpClients.createDefault();
                Log.msetlog.debug("创建httpClient结束时间:"+DateKit.getNowTime()+msg);
            }
            Log.msetlog.debug("创建httpPost开始时间:"+DateKit.getNowTime()+msg);
            httpPost = new HttpPost(url);
            Log.msetlog.debug("创建httpPost结束时间:"+DateKit.getNowTime()+msg);
            Log.msetlog.debug("设置httpPost属性开始时间:"+DateKit.getNowTime()+msg);
            HttpEntity re = new StringEntity(xml, "UTF-8");
            httpPost.setHeader("Content-Type",
                    "application/soap+xml; charset=utf-8");
            httpPost.setEntity(re);
            Log.msetlog.debug("设置httpPost属性结束时间:"+DateKit.getNowTime()+msg);
            Log.msetlog.debug("最终执行调用接口开始时间:"+DateKit.getNowTime()+msg);
            CloseableHttpResponse response = httpClient.execute(httpPost);
            Log.msetlog.debug("最终执行调用接口结束时间:"+DateKit.getNowTime()+msg);
            if (response != null) {
                resultStatusCode = String.valueOf(response.getStatusLine()
                        .getStatusCode());
            }
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    rs = EntityUtils.toString(entity, "UTF-8");
                }
            } finally {
                response.close();
                httpPost.abort();
            }
        } catch (Exception e) {
            Log.soaplog.debug("error", e);
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源
            try {
                httpClient.close();
            } catch (Exception e) {
                Log.soaplog.debug("error", e);
                e.printStackTrace();
            }
        }
        resultMap.put("ResultStatus", resultStatusCode);
        resultMap.put("ResultXML", rs);
        return resultMap;
    }


    //重载添加超时设置
    public static Map<String, String> postSoap3(String url, String xml, int timeOut) {
        Map<String, String> resultMap = new HashMap<String, String>();
        // 返回字符串
        String rs = null;
        // 返回状态
        String resultStatusCode = "";
        // 创建httppost
        HttpPost httpPost = null;
        // 创建参数队列
        CloseableHttpClient httpClient = null;

        //返回异常信息:
        String ex = null;
        try {
            String msg = "";
            if(Log.msetlog.isDebugEnabled()){
                if(xml.indexOf("<TaskId>") > 0){//审批时调用
                    msg = "; 审批时相关TaskId :" + xml.substring(xml.indexOf("<TaskId>")+8, xml.indexOf("</TaskId>"));
                }else if(xml.indexOf("<def:EspaId>") > 0){
                    msg = "; SEQID:" + xml.substring(xml.indexOf("<def:EspaId>")+12, xml.indexOf("</def:EspaId>"));
                }else if(xml.indexOf("<espaId>") > 0){
                    msg = "; SEQID:" + xml.substring(xml.indexOf("<espaId>")+8, xml.indexOf("</espaId>"));
                }else if(xml.indexOf("<wsse:Username>") > 0){
                    msg = "; UserName:" + xml.substring(xml.indexOf("<wsse:Username>")+15, xml.indexOf("</wsse:Username>"));
                }
            }
            if ("https".equals(url.substring(0, 5))) {
                // 使用连接池
                // httpClient=createSSLInsecureClient();
                // 不使用连接池
                Log.msetlog.debug("创建https对应httpClient开始时间:"+DateKit.getNowTime()+msg);
                httpClient = createSSLClientDefault();
                Log.msetlog.debug("创建https对应httpClient结束时间:"+DateKit.getNowTime()+msg);
            } else {
                // httpClient=HttpClients.custom().setConnectionManager(cm).build();
                Log.msetlog.debug("创建httpClient开始时间:"+DateKit.getNowTime()+msg);
                httpClient = HttpClients.createDefault();
                Log.msetlog.debug("创建httpClient结束时间:"+DateKit.getNowTime()+msg);
            }

            Log.msetlog.debug("创建httpPost开始时间:"+DateKit.getNowTime()+msg);
            httpPost = new HttpPost(url);
            Log.msetlog.debug("创建httpPost结束时间:"+DateKit.getNowTime()+msg);
            Log.msetlog.debug("设置httpPost属性开始时间:"+DateKit.getNowTime()+msg);
            HttpEntity re = new StringEntity(xml, "UTF-8");
            httpPost.setHeader("Content-Type", "application/soap+xml; charset=utf-8");
            httpPost.setEntity(re);

            //添加超时:
            RequestConfig requestConfig = RequestConfig.custom()
                    .setSocketTimeout(timeOut).setConnectTimeout(timeOut).build();//设置请求和传输超时时间
            httpPost.setConfig(requestConfig);

            Log.msetlog.debug("设置httpPost属性结束时间:"+DateKit.getNowTime()+msg);
            Log.msetlog.debug("最终执行调用接口开始时间:"+DateKit.getNowTime()+msg);
            CloseableHttpResponse response = httpClient.execute(httpPost);
            Log.msetlog.debug("最终执行调用接口结束时间:"+DateKit.getNowTime()+msg);
            if (response != null) {
                resultStatusCode = String.valueOf(response.getStatusLine()
                        .getStatusCode());
                if ("504".equals(resultStatusCode))
                {
                    // 504是超时
                    ex = "TimeoutException";
                }
            }
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    rs = EntityUtils.toString(entity, "UTF-8");
                }
            } finally {
                response.close();
                httpPost.abort();
            }
        }catch(ConnectTimeoutException e1){
            e1.printStackTrace();
            ex = "TimeoutException";
        }catch (SocketTimeoutException e2) {
            e2.printStackTrace();
            ex = "TimeoutException";
        }catch (Exception e) {
            Log.soaplog.debug("error", e);
            e.printStackTrace();
            ex = "Exception";
        } finally {
            // 关闭连接,释放资源
            try {
                httpClient.close();
            } catch (Exception e) {
                Log.soaplog.debug("error", e);
                e.printStackTrace();
                ex = "Exception";
            }
        }
        resultMap.put("ResultStatus", resultStatusCode);
        resultMap.put("ResultXML", rs);
        resultMap.put("ex", ex);
        return resultMap;
    }



    /**
     * 发送soap到http/https
     * 
     * @param url
     * @param xml
     * @return String
     */
    public static String postSoapForStr(HttpEntity resEntity) {
        if (resEntity != null) {
            try {
                return EntityUtils.toString(resEntity, "UTF-8");
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return null;
    }

    /**
     * 创建SSL连接忽略证书
     * 
     * @return
     */
    public static CloseableHttpClient createSSLInsecureClient() {
        try {
            return HttpClients.custom().setConnectionManager(cmhttps)
                    .setSSLSocketFactory(sslsf)
                    .setConnectionManagerShared(true).build();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return HttpClients.createDefault();
    }

    public static CloseableHttpClient createSSLInsecureClient2() {
        try {
            return HttpClients.custom().setConnectionManager(cmhttps)
                    .setSSLSocketFactory(sslsf)
                    .build();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return HttpClients.createDefault();
    }

    public static void main(String[] args) {
        // // long begin = System.currentTimeMillis();
        // // String url = "https://10.177.1.195/services/ESPAService";
        // // for(int i=0;i<10;i++){
        // // System.out.println(postSoap3(url,""));
        // // }
        // // System.out.println(System.currentTimeMillis()-begin);
        //
        // for (int i = 0; i < 250; i++) {
        // System.out.println(createSSLInsecureClient2());
        // System.out.println(cmhttps.getTotalStats());
        // // try {
        // // Thread.sleep(1000);
        // // } catch (InterruptedException e) {
        // // e.printStackTrace();
        // // }
        // }
        //
        // createSSLInsecureClient();
        // System.out.println(cmhttps);
        // System.out.println(cmhttps.getMaxTotal());
        // System.out.println(cmhttps.getTotalStats());


        long begin = System.currentTimeMillis();
        String url = "http://localhost:8080/bpm/webservice/ESPABillService";
        String oppId = "Nnnn";
        String xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://webservice.software.com/\">    <soapenv:Header/>    <soapenv:Body>       <web:createESPABillPrebiding>          <ESPABillPrebidingRequest>         <accountName>石油xxxx</accountName>         <accountNum>83</accountNum>         <awardedDate>2015-12-31</awardedDate>         <biddate>2015-12-18</biddate>         <CWT>N</CWT>         <channelType>N</channelType>         <country>中国</country>         <countryCode>0</countryCode>         <countyLevelCity>昌平区</countyLevelCity>         <countyLevelCityCode>12</countyLevelCityCode>         <productLines>           <family1code>MVS</family1code>           <family1Id>659</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>MVS</l2Id>           <lineItemId>3712</lineItemId>           <productLine>PTACB</productLine>           <productLineId>650</productLineId>         </productLines>         <productLines>           <family1code>NSX</family1code>           <family1Id>674</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>NSX</l2Id>           <lineItemId>3713</lineItemId>           <productLine>PTCCB</productLine>           <productLineId>662</productLineId>         </productLines>         <productLines>           <family1code>A9 Enclosure</family1code>           <family1Id>826</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>A9 Enclosure</l2Id>           <lineItemId>3714</lineItemId>           <productLine>PTFDS</productLine>           <productLineId>825</productLineId>         </productLines>         <productLines>           <family1code>Easypact TVS</family1code>           <family1Id>697</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>Easypact TVS</l2Id>           <lineItemId>3715</lineItemId>           <productLine>PTCTR</productLine>           <productLineId>696</productLineId>         </productLines>         <productLines>           <family1code>PCP Others</family1code>           <family1Id>707</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>PCP Others</l2Id>           <lineItemId>3716</lineItemId>           <productLine>PTCTR</productLine>           <productLineId>696</productLineId>         </productLines>         <valueChainPlayers>           <VCPAccoutnName>合肥京东方光电科技有限公司</VCPAccoutnName>           <VCPAccountNum>57-001A000000v4sQmIAI</VCPAccountNum>           <VCPAccoutnRole>System Integrator</VCPAccoutnRole>         </valueChainPlayers>         <valueChainPlayers>           <VCPAccoutnName>河南省新科电控设备有限公司</VCPAccoutnName>           <VCPAccountNum>133-001A000000v50gSIAQ</VCPAccountNum>           <VCPAccoutnRole>Panel Builders</VCPAccoutnRole>         </valueChainPlayers>         <forecastAamt>50000000.0000</forecastAamt>         <offerPackageId>20</offerPackageId>         <offerPackageName>NS LV Transaction</offerPackageName>         <oppId>"
                + oppId
                + "</oppId>         <opportunityName>NS-2015-NS_EU-SESA159144-CASE17-LINNA-自增-NS LV Transaction</opportunityName>         <pipeStage>05</pipeStage>         <prefectureLevelCity>北京市</prefectureLevelCity>         <prefectureLevelCityCode>1</prefectureLevelCityCode>         <province>北京</province>         <provinceCode>5323</provinceCode>         <projectName>CASE17-LINNA</projectName>         <secSegLv1>住宅</secSegLv1>         <secSegLv1Code>A0000</secSegLv1Code>         <secSegLv2>别墅/联排</secSegLv2>         <secSegLv2Code>A0100</secSegLv2Code>         <sesaID>SESA159144</sesaID>         <stage>Pre-bidding</stage>       </ESPABillPrebidingRequest>       </web:createESPABillPrebiding>    </soapenv:Body> </soapenv:Envelope>";
        for(int i=79;i<80;i++){
            xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://webservice.software.com/\">    <soapenv:Header/>    <soapenv:Body>       <web:createESPABillPrebiding>          <ESPABillPrebidingRequest>         <accountName>石油xxxx</accountName>         <accountNum>83</accountNum>         <awardedDate>2015-12-31</awardedDate>         <biddate>2015-12-18</biddate>         <CWT>N</CWT>         <channelType>N</channelType>         <country>中国</country>         <countryCode>0</countryCode>         <countyLevelCity>昌平区</countyLevelCity>         <countyLevelCityCode>12</countyLevelCityCode>         <productLines>           <family1code>MVS</family1code>           <family1Id>659</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>MVS</l2Id>           <lineItemId>3712</lineItemId>           <productLine>PTACB</productLine>           <productLineId>650</productLineId>         </productLines>         <productLines>           <family1code>NSX</family1code>           <family1Id>674</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>NSX</l2Id>           <lineItemId>3713</lineItemId>           <productLine>PTCCB</productLine>           <productLineId>662</productLineId>         </productLines>         <productLines>           <family1code>A9 Enclosure</family1code>           <family1Id>826</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>A9 Enclosure</l2Id>           <lineItemId>3714</lineItemId>           <productLine>PTFDS</productLine>           <productLineId>825</productLineId>         </productLines>         <productLines>           <family1code>Easypact TVS</family1code>           <family1Id>697</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>Easypact TVS</l2Id>           <lineItemId>3715</lineItemId>           <productLine>PTCTR</productLine>           <productLineId>696</productLineId>         </productLines>         <productLines>           <family1code>PCP Others</family1code>           <family1Id>707</family1Id>           <forecastAmt>10000000.0000</forecastAmt>           <forecastQuantity>1111111</forecastQuantity>           <l2Id>PCP Others</l2Id>           <lineItemId>3716</lineItemId>           <productLine>PTCTR</productLine>           <productLineId>696</productLineId>         </productLines>         <valueChainPlayers>           <VCPAccoutnName>合肥京东方光电科技有限公司</VCPAccoutnName>           <VCPAccountNum>57-001A000000v4sQmIAI</VCPAccountNum>           <VCPAccoutnRole>System Integrator</VCPAccoutnRole>         </valueChainPlayers>         <valueChainPlayers>           <VCPAccoutnName>河南省新科电控设备有限公司</VCPAccoutnName>           <VCPAccountNum>133-001A000000v50gSIAQ</VCPAccountNum>           <VCPAccoutnRole>Panel Builders</VCPAccoutnRole>         </valueChainPlayers>         <forecastAamt>50000000.0000</forecastAamt>         <offerPackageId>20</offerPackageId>         <offerPackageName>NS LV Transaction</offerPackageName>         <oppId>"
                    + oppId+i
                    + "</oppId>         <opportunityName>NS-2015-NS_EU-SESA159144-CASE17-LINNA-自增-NS LV Transaction</opportunityName>         <pipeStage>05</pipeStage>         <prefectureLevelCity>北京市</prefectureLevelCity>         <prefectureLevelCityCode>1</prefectureLevelCityCode>         <province>北京</province>         <provinceCode>5323</provinceCode>         <projectName>CASE17-LINNA</projectName>         <secSegLv1>住宅</secSegLv1>         <secSegLv1Code>A0000</secSegLv1Code>         <secSegLv2>别墅/联排</secSegLv2>         <secSegLv2Code>A0100</secSegLv2Code>         <sesaID>SESA159144</sesaID>         <stage>Pre-bidding</stage>       </ESPABillPrebidingRequest>       </web:createESPABillPrebiding>    </soapenv:Body> </soapenv:Envelope>";
            System.out.println(postSoap3(url,xml,1));
        }

//        for(int i=0;i<250;i++){
//          System.out.println(createSSLInsecureClient());
//            System.out.println(postSoap3(url,""));
//        }
        System.out.println(System.currentTimeMillis()-begin);



    }

    /**
     * 字符串转Document
     * 
     * @param xml
     * @return
     */
    public static Document convertDocFromStr(String xml) {
        try {
            return DocumentHelper.parseText(xml);
        } catch (DocumentException e) {
            return null;
        }
    }

    /**
     * 获取xml某个节点的值
     * 
     * @param xml
     * @param node
     * @return
     */
    public static String getNodeByXml(String xml, String node) {
        Document doc = convertDocFromStr(xml);
        if (doc == null) {
            return null;
        } else {
            Node typeNode = doc.selectSingleNode(".//*[local-name()='" + node
                    + "']");
            if (typeNode == null) {
                return null;
            } else {
                return typeNode.getStringValue();
            }
        }
    }
}
posted @ 2017-07-31 10:00  nxw_tsp  阅读(585)  评论(0编辑  收藏  举报