zoukankan      html  css  js  c++  java
  • 随机获取国际国内航班3字码城市对的方法

    思路:通过访问开放航班城市查询webservice获取城市对3字码

        /**
         * 利用免费航班城市webservice获取随机城市对
         */
        public List<String> randomCity(){
            String endpoint = "http://webservice.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl";
            String nameSpace = "http://WebXml.com.cn/";
    
            String operationName = "getDomesticCity";
    
            Service service = new Service();
            Call call;
            String FOCElementBody = null;
            List<String> citys = new ArrayList<String>();
            try {
                call = (Call) service.createCall();
                call.setUseSOAPAction(true);
                call.setSOAPActionURI(nameSpace + operationName);
                call.setTargetEndpointAddress(endpoint);
    
                call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA);
                call.setOperationName(operationName);
                Object res = (Object) call.invoke(new Object[] {});
                Schema schema = (Schema) res;
                MessageElement[] msgele = schema.get_any();
                FOCElementBody = msgele[1].getChildren().toString().replace("[", "").replace("]", "");
                
                StringReader stringReader = new StringReader(FOCElementBody);
                InputSource inputSource = new InputSource(stringReader);
                DocumentBuilderFactory docBuilderFac = DocumentBuilderFactory
                        .newInstance();
                DocumentBuilder docBuilder = docBuilderFac.newDocumentBuilder();
                Document document = docBuilder.parse(inputSource);
                Node node = document.getDocumentElement();
                NodeList temp = node.getChildNodes();
                
                for(int i=0;i<temp.getLength();i++){
                    NodeList tmp = temp.item(i).getChildNodes();
                    citys.add(tmp.item(2).getTextContent());
                }
                
            } catch (ServiceException e) {
                e.printStackTrace();
            } catch (RemoteException e) {
                e.printStackTrace();
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            
            String citytemp1 = citys.get(rand.nextInt(citys.size()));
            String citytemp2 = null;
            do{
                citytemp2 = citys.get(rand.nextInt(citys.size()));
            }while(citytemp1==citytemp2);
            
            citys.clear();
            citys.add(citytemp1);
            citys.add(citytemp2);
            return citys;
        }
  • 相关阅读:
    重定向syste.out.print
    文件与文件夹的拷贝
    List和Set转Long数组
    Struts2验证错误信息的两个经典方法-addFieldError&addActionError
    OA项目---笔记
    三种给<s:a>,<a>标签传值的方式
    [整理]免费电子书网站
    [整理]Visual Studio 的Application Insights
    [转载]CSS Tools: Reset CSS
    [转载]AngularJS之Factory vs Service vs Provider
  • 原文地址:https://www.cnblogs.com/zzzhuxf/p/3569592.html
Copyright © 2011-2022 走看看