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;
        }
  • 相关阅读:
    前端React 条件渲染
    hbuilder小白干货之快捷键大全
    前端React 元素渲染
    mybatis学习笔记五(映射)
    mybatis学习笔记四(配置文件)
    mybatis学习笔记二(sqlsession与开发dao)
    mybatis学习笔记三(动态sql)
    mybatis学习笔记一(mybatis概述)
    必备idea 插件plugins 提高编码效率
    shell提升篇
  • 原文地址:https://www.cnblogs.com/zzzhuxf/p/3569592.html
Copyright © 2011-2022 走看看