• 随机获取国际国内航班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;
        }
  • 相关阅读:
    【转】嵌入式程序员应该知道的16个问题
    GetMemory()函数
    Some good questions
    [转]永远做一个有计划的人
    内存分配管理
    c语言面试题(感觉比较好的题目)
    const char*, char const*, char*const的区别
    《论语》《中庸》《大学》经典语录
    洗脑
    python基础之函数参数,名称空间,以及函数嵌套
  • 原文地址:https://www.cnblogs.com/zzzhuxf/p/3569592.html
Copyright © 2020-2023  润新知